Skip to content

Commit dcc4269

Browse files
Merge pull request ietf-tools#4612 from painless-security/jennifer/idsubmit-math
refactor: simplify I-D cutoff calculations and make TZ more explicit
2 parents e461f70 + 0346271 commit dcc4269

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

ietf/meeting/models.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,45 +147,38 @@ def end_datetime(self):
147147
return datetime_from_date(self.get_meeting_date(self.days), self.tz())
148148

149149
def get_00_cutoff(self):
150-
start_date = datetime.datetime(
151-
year=self.date.year,
152-
month=self.date.month,
153-
day=self.date.day,
154-
tzinfo=datetime.timezone.utc,
155-
)
150+
"""Get the I-D submission 00 cutoff in UTC"""
156151
importantdate = self.importantdate_set.filter(name_id='idcutoff').first()
157152
if not importantdate:
158153
importantdate = self.importantdate_set.filter(name_id='00cutoff').first()
159154
if importantdate:
160155
cutoff_date = importantdate.date
161156
else:
162-
cutoff_date = start_date + datetime.timedelta(days=ImportantDateName.objects.get(slug='idcutoff').default_offset_days)
163-
cutoff_time = datetime_from_date(cutoff_date) + self.idsubmit_cutoff_time_utc
157+
cutoff_date = self.date + datetime.timedelta(days=ImportantDateName.objects.get(slug='idcutoff').default_offset_days)
158+
cutoff_time = datetime_from_date(cutoff_date, datetime.timezone.utc) + self.idsubmit_cutoff_time_utc
164159
return cutoff_time
165160

166161
def get_01_cutoff(self):
167-
start_date = datetime.datetime(year=self.date.year, month=self.date.month, day=self.date.day, tzinfo=pytz.utc)
162+
"""Get the I-D submission 01 cutoff in UTC"""
168163
importantdate = self.importantdate_set.filter(name_id='idcutoff').first()
169164
if not importantdate:
170165
importantdate = self.importantdate_set.filter(name_id='01cutoff').first()
171166
if importantdate:
172167
cutoff_date = importantdate.date
173168
else:
174-
cutoff_date = start_date + datetime.timedelta(days=ImportantDateName.objects.get(slug='idcutoff').default_offset_days)
175-
cutoff_time = datetime_from_date(cutoff_date) + self.idsubmit_cutoff_time_utc
169+
cutoff_date = self.date + datetime.timedelta(days=ImportantDateName.objects.get(slug='idcutoff').default_offset_days)
170+
cutoff_time = datetime_from_date(cutoff_date, datetime.timezone.utc) + self.idsubmit_cutoff_time_utc
176171
return cutoff_time
177172

178173
def get_reopen_time(self):
179-
start_date = datetime.datetime(year=self.date.year, month=self.date.month, day=self.date.day)
180-
local_tz = pytz.timezone(self.time_zone)
181-
local_date = local_tz.localize(start_date)
174+
"""Get the I-D submission reopening time in meeting-local time"""
182175
cutoff = self.get_00_cutoff()
183-
if cutoff.date() == start_date:
176+
if cutoff.date() == self.date:
184177
# no cutoff, so no local-time re-open
185178
reopen_time = cutoff
186179
else:
187180
# reopen time is in local timezone. May need policy change?? XXX
188-
reopen_time = local_date + self.idsubmit_cutoff_time_utc
181+
reopen_time = datetime_from_date(self.date, self.tz()) + self.idsubmit_cutoff_time_utc
189182
return reopen_time
190183

191184
@classmethod

ietf/utils/timezone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
def _tzinfo(tz: Union[str, datetime.tzinfo, None]):
2323
"""Helper to convert a tz param into a tzinfo
2424
25-
Accepts Defaults to UTC.
25+
Accepts a tzinfo or string containing a timezone name. Defaults to UTC if tz is None.
2626
"""
2727
if tz is None:
2828
return datetime.timezone.utc

0 commit comments

Comments
 (0)