freezegun: `freeze_time` could accept a timezone argument
What do you think of having freeze_time accept a timezone argument:
@freeze_time('2015-03-09 09:00:00', timezone='US/Pacific')
That would require adding pytz to the requirements, which should be fine since most Python projects have it.
Thoughts? I might develop it.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 19 (7 by maintainers)
Just FYI: one can already pass
freeze_timea timezone-aware datetime object:(prints
2015-08-18 08:51:50-08:00)@spulec That’s a shame. While it works, it’s a bit clumsy for an extremely common use case. (I, at least, have zero Python projects that can afford to ignore time zones.)
@shreevatsar solution does not work for me.
I might be doing something wrong, but definitely this is not very straightforward.
Regarding my previous comment, it turns out that dateutil’s parser returns an aware datetime IFF the timezone in the string matches the default timezone of the host. In all other cases, dateutil’s parser ignores the given timezone and returns a naive (and unadjusted) datetime.
Definitely fails the principle of least surprise for me, but there you have it.
i can confirm problem mentioned by @spumer @fish-face and @jose-lpa
my workaround:
2015-08-18 15:51:50I got same problem with freezing time in Django tests =/