Skip to content

now('US/Pacific') failing during DST transition #417

@tomage

Description

@tomage

I've been evaluating a few libraries to use for my company, and as I have a testing "rig" that can run our unit-test suite under arbitrary datetimes of the year, I've especially been digging into daylight savings transitions.

There was a couple of oddities I did discover. One was #415, but the other one is this: Calling pendulum.now('US/Pacific') yielded different results than pendulum.now('UTC').in_tz('US/Pacific'), latter yielding correct results.

So, running this at 2019-11-03 08:30:00+00:00 (set by system time, or using libfreezetime or freezegun):

>>> now_utc_pt = pendulum.now('UTC').in_tz('US/Pacific')
>>> print(now_utc_pt.isoformat(), now_utc_pt.fold)
2019-11-03T01:30:00-07:00 0
>>> print(now_utc_pt.is_dst(), -now_utc_pt.utcoffset())
True 7:00:00
>>> now_pt = pendulum.now('US/Pacific')
>>> print(now_pt.isoformat(), now_pt.fold)
Conversely, let's ask directly for US/Pacific "now"
2019-11-03T01:30:00-08:00 1
>>> print(now_pt.is_dst(), -now_pt.utcoffset())
False 8:00:00

As with the other issue, I took the liberty to create a PR for a potential fix: #416.

Here's a small pyfiddle to showcase the behavior: https://pyfiddle.io/fiddle/f0ef4724-3af3-4e24-8a7c-254a17db9dec/?i=true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions