Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong hour in timezone "Africa/Cairo" from 2023 #706

Closed
psyking841 opened this issue May 4, 2023 · 4 comments
Closed

Wrong hour in timezone "Africa/Cairo" from 2023 #706

psyking841 opened this issue May 4, 2023 · 4 comments

Comments

@psyking841
Copy link

psyking841 commented May 4, 2023

  • OS version and name: OSX 13.3.1 (22E261)
  • Pendulum version: 2.1.2

Issue

In 2023, Cairo has started daylight saving in 2023 on 2023-04-27T21:00:00 UTC.
This 2023-04-27T21:00:00 UTC should be local time 2023-04-28T00:00:00 (Cairo time). However, in pendulumn this is still converted to 2023-04-27T23:00:00 (Cairo time)
Please see the replay below:

>>> dt = pendulum.datetime(2023, 4, 27, 21)
>>> dt
DateTime(2023, 4, 27, 21, 0, 0, tzinfo=Timezone('UTC'))
>>> dt.in_timezone('Africa/Cairo')
DateTime(2023, 4, 27, 23, 0, 0, tzinfo=Timezone('Africa/Cairo'))

Basically, pendumlum is not implementing daylight saving for Africa/Cairo time.

This is related to this issue: #700 where Mexico has made the similar decision in 2023.

@NickFabry
Copy link
Collaborator

This is caused by pendulum release 2.1.2 referencing (now) obsolete IANA zoneinfo, specifically 2022.1. As a temporary fix, to force pendulum 2.1.2 to use either the system zoneinfo, or (on Windows), the zoneinfo from the first party module tzdata, put the following into your python import path as (for example) pendulum_212_fix.py, and after you import pendulum, add the line import pendulum_212_fix, and you should be good.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This module has one purpose - to fix the behavior of pendulum release
2.1.2, which uses a hardcoded version of the IANA zoneinfo data, 2022.2.
Importing this module after importing pendulum should cause pendulum to
use either the OS provided zoneinfo data, or if that does not exist, to
use the zoneinfo from the first party module tzdata. Note this introduces
a dependence on tzdata, which must be separetely installed, typically via
pip install tzdata.

In theory, IMMEDIATELY AFTER IMPORTING pendulum, you should simply
import this module and pendulum will then use the local system
zoneinfo, if available, and if not, the zoneinfo from tzdata, when
creating aware datetimes.
"""



import pathlib
import sysconfig
import tzdata

LOCAL_TZPATH = sysconfig.get_config_var('TZPATH')
if LOCAL_TZPATH:
    # This could be a colon separated list of paths; we take the first only
    LOCAL_TZPATH = LOCAL_TZPATH.split(':')[0]
else:
    LOCAL_TZPATH = pathlib.Path(tzdata.__path__) / 'zoneinfo'

import pendulum
import pytzdata
pytzdata.set_directory(LOCAL_TZPATH)



if __name__ == '__main__':
    pass

@psyking841
Copy link
Author

Thanks for the solution! But, I am using the pendulum module built inside Airflow, specifically MWAA in AWS. So, I guess I have to wait for them to make this patch.

@edgarrmondragon
Copy link
Contributor

I think this is indeed a bug, but the example seems incorrect:

When local standard time was about to reach Friday, April 28, 2023, 12:00:00 midnight clocks were turned forward 1 hour to Friday, April 28, 2023, 1:00:00 am local daylight time instead.

So, Cairo (EET) being normally UTC+2, the correct test case would be 2023-4-27T22:00:00Z:

>>> pendulum.__version__
'2.1.2'
>>> pendulum.datetime(2023, 4, 27, 21).in_timezone('Africa/Cairo')
DateTime(2023, 4, 27, 23, 0, 0, tzinfo=Timezone('Africa/Cairo'))
>>> pendulum.datetime(2023, 4, 27, 22).in_timezone('Africa/Cairo')
DateTime(2023, 4, 28, 0, 0, 0, tzinfo=Timezone('Africa/Cairo'))  # Should be 1 A.M.

FWIW this does seem to be fixed in Pendulum 3.0.0b1:

>>> pendulum.__version__
'3.0.0b1'
>>> pendulum.datetime(2023, 4, 27, 21).in_timezone('Africa/Cairo')
DateTime(2023, 4, 27, 23, 0, 0, tzinfo=Timezone('Africa/Cairo'))
>>> pendulum.datetime(2023, 4, 27, 22).in_timezone('Africa/Cairo')
DateTime(2023, 4, 28, 1, 0, 0, tzinfo=Timezone('Africa/Cairo'))

@Secrus
Copy link
Collaborator

Secrus commented Dec 17, 2023

Fixed in Pendulum 3.0

@Secrus Secrus closed this as completed Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants