|
8 | 8 | from .utils import load_yaml
|
9 | 9 |
|
10 | 10 | import logging
|
| 11 | +import sys |
11 | 12 | from datetime import datetime, time, timedelta
|
12 | 13 |
|
13 | 14 | try:
|
|
17 | 18 |
|
18 | 19 | log = logging.getLogger(__name__)
|
19 | 20 |
|
| 21 | + |
| 22 | +def get_24hour_time(dt): |
| 23 | + return dt.strftime('%H:%M') |
| 24 | + |
| 25 | + |
| 26 | +def get_12hour_time(dt): |
| 27 | + hour = dt.strftime('%I') |
| 28 | + hour = hour.lstrip('0') |
| 29 | + return f'{hour}:{dt.strftime("%M %p")}' |
| 30 | + |
| 31 | + |
20 | 32 | TIME_FORMATS = {
|
21 |
| - '24h': '%H:%M', |
22 |
| - '12h': '%-I:%M %p', |
| 33 | + '24h': get_24hour_time, |
| 34 | + '12h': get_12hour_time, |
23 | 35 | }
|
24 | 36 |
|
| 37 | + |
25 | 38 | # Some DST timezones aren't "real" timezones.
|
26 | 39 | TIMEZONE_TRANSLATION_PYTZ = {
|
27 | 40 | 'CEST': 'CET',
|
@@ -134,15 +147,15 @@ def load_conference_context_from_yaml(shortcode, year, year_str, page):
|
134 | 147 | )
|
135 | 148 | if not display_timezones:
|
136 | 149 | # In a single-tz schedule, render just naive time, first schedule item with TZ
|
137 |
| - schedule_item['time'] = naive_item_start.strftime(TIME_FORMATS[data['time_format']]) |
| 150 | + schedule_item['time'] = TIME_FORMATS[data['time_format']](naive_item_start) |
138 | 151 | if not naive_next_item_default_start and not data.get('flaghasfood'):
|
139 | 152 | schedule_item['time'] += ' ' + data['tz']
|
140 | 153 | if display_timezones:
|
141 | 154 | # In multi-timezone, first convert to aware, then format for each timezone.
|
142 | 155 | # Note that we need to combine with conf date to know whether there is DST.
|
143 | 156 | aware_item_start = datetime.combine(conf_date, naive_item_start.time()).replace(tzinfo=conf_timezone)
|
144 | 157 | schedule_item['time'] = '<br>'.join([
|
145 |
| - aware_item_start.astimezone(tz).strftime(TIME_FORMATS[data['time_format']]) + ' ' + tz_name |
| 158 | + TIME_FORMATS[data['time_format']](aware_item_start.astimezone(tz)) + ' ' + tz_name |
146 | 159 | for tz_name, tz in display_timezones
|
147 | 160 | ])
|
148 | 161 | naive_next_item_default_start = naive_item_start + duration
|
|
0 commit comments