Skip to content

pendulum.instance & dateutil.tz compatibility  #820

Open
@LemonPepperSeasoning

Description

@LemonPepperSeasoning
  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: macOS Sonoma Version 14.4.1
  • Pendulum version: 3.0.0

Issue

As title suggests pendulum.instance does not seem to be compatible with dateutil.tz. (Please let me know if this is intentional or outside the support)

Here is what i found.

Generally, pendulum works fine with tz. As seen by the example below, tzinfo gets assigned correctly & it shows the appropriate time.

% python3
>>> import pendulum
>>> from dateutil import tz
>>> from datetime import datetime
>>> datetime.now().astimezone(pendulum.timezone("Etc/GMT+6"))
datetime.datetime(2024, 4, 26, 11, 53, 39, 999441, tzinfo=Timezone('Etc/GMT+6'))
 
>>> datetime.now().astimezone(pendulum.timezone("Etc/GMT+6")).astimezone(tz.gettz("Etc/GMT+6"))
datetime.datetime(2024, 4, 26, 11, 54, 10, 296885, tzinfo=tzfile('/usr/share/zoneinfo/Etc/GMT+6'))

But, with pendulum.instance. Using astimezone() function with tz.timezone as an input produces a bug & results in output Datetime object to not have tzinfo attribute.

>>> pendulum.instance(datetime.now(), tz=pendulum.timezone("Etc/GMT+6"))
DateTime(2024, 4, 27, 2, 56, 5, 7794, tzinfo=Timezone('Etc/GMT+6'))
 
>>> pendulum.instance(datetime.now(), tz=pendulum.timezone("Etc/GMT+6")).astimezone(tz.gettz("Etc/GMT+6"))
DateTime(2024, 4, 27, 8, 56, 17, 906011)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions