pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

pendulum.instance & dateutil.tz compatibility

Open LemonPepperSeasoning opened this issue 10 months ago • 0 comments

  • [x] I am on the latest Pendulum version.
  • [x] 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)

LemonPepperSeasoning avatar Apr 26 '24 18:04 LemonPepperSeasoning