Skip to content

Commit

Permalink
Use a defined sourceTime when using parsedatetime
Browse files Browse the repository at this point in the history
When using the parsedatetime functionalities freezegun is not used to
compute the source time. If the tests are run too close to midnight it
might result in the computation of 'tomorrow' being another day then
now() + 24h (because time.localtime() will be the next day) … thus
failing test_default_due2.

Setting sourceTime when calling parsedatime will ensure the same base is
used for all tests.
  • Loading branch information
nicoe committed Aug 24, 2019
1 parent cf1df4a commit 0e05015
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion todoman/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def _parse_datetime_naive(self, dt):
except ValueError:
pass

rv, pd_ctx = self._parsedatetime_calendar.parse(dt)
now = datetime.datetime.now(self.tz)
rv, pd_ctx = self._parsedatetime_calendar.parse(dt, now)
if not pd_ctx.hasDateOrTime:
raise ValueError('Time description not recognized: {}'.format(dt))
return datetime.datetime.fromtimestamp(mktime(rv))
Expand Down

0 comments on commit 0e05015

Please sign in to comment.