Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes time format error when compiling under Windows #2228

Merged
merged 7 commits into from
Sep 20, 2024
21 changes: 17 additions & 4 deletions docs/_ext/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .utils import load_yaml

import logging
import sys
from datetime import datetime, time, timedelta

try:
Expand All @@ -17,11 +18,23 @@

log = logging.getLogger(__name__)


def get_24hour_time(dt):
return dt.strftime('%H:%M')


def get_12hour_time(dt):
hour = dt.strftime('%I')
hour = hour.lstrip('0')
return f'{hour}:{dt.strftime("%M %p")}'


TIME_FORMATS = {
'24h': '%H:%M',
'12h': '%-I:%M %p',
'24h': get_24hour_time,
'12h': get_12hour_time,
}


# Some DST timezones aren't "real" timezones.
TIMEZONE_TRANSLATION_PYTZ = {
'CEST': 'CET',
Expand Down Expand Up @@ -134,15 +147,15 @@ def load_conference_context_from_yaml(shortcode, year, year_str, page):
)
if not display_timezones:
# In a single-tz schedule, render just naive time, first schedule item with TZ
schedule_item['time'] = naive_item_start.strftime(TIME_FORMATS[data['time_format']])
schedule_item['time'] = TIME_FORMATS[data['time_format']](naive_item_start)
if not naive_next_item_default_start and not data.get('flaghasfood'):
schedule_item['time'] += ' ' + data['tz']
if display_timezones:
# In multi-timezone, first convert to aware, then format for each timezone.
# Note that we need to combine with conf date to know whether there is DST.
aware_item_start = datetime.combine(conf_date, naive_item_start.time()).replace(tzinfo=conf_timezone)
schedule_item['time'] = '<br>'.join([
aware_item_start.astimezone(tz).strftime(TIME_FORMATS[data['time_format']]) + ' ' + tz_name
TIME_FORMATS[data['time_format']](aware_item_start.astimezone(tz)) + ' ' + tz_name
for tz_name, tz in display_timezones
])
naive_next_item_default_start = naive_item_start + duration
Expand Down