Skip to content

Commit

Permalink
Fixes time format error when compiling under Windows (#2228)
Browse files Browse the repository at this point in the history
* Fixes encoding error when building under Windows

* This will keep the formatting the same and allow it to work under Windows.

* This will keep the formatting the same and allow it to work under Windows.

---------

Co-authored-by: Sam <[email protected]>
  • Loading branch information
kdschlosser and plaindocs authored Sep 20, 2024
1 parent a8970f1 commit c037f99
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit c037f99

Please sign in to comment.