0

I have a 2 datetimes from "America/Santiago" timezone:

  • 2022-09-04 00:00:00
  • 2022-09-04 01:00:00

In "America/Santiago" they usually change the hour on the 4th Sept. This is at 2022-09-04 00h they say it is 2022-09-04 01:00:00. But this year because of elections the change of hour was delayed one week. So there is no change of time on the 4th.

I need to convert the chilean time to UTC. Therefore:

By using an updated version of pytz library, i succeed to convert this to a datetime object in "UTC":

  • 2022-09-04 00:00:00-04:00
  • 2022-09-04 01:00:00-04:00

The old version i was using did not had this into count because did not know about it.

The problem is that i want to generate too and end time so the script i am reviewing from my department is using the following pendulum library:

def my_next_hour(datetime_obj):
    //datetime_obj=2022-09-04 00:00:00-04:00
    new_dt = pendulum.instance(datetime_obj).add(hours=1)
    return new_dt

The output i get is:

  • 2022-09-04T02:00:00-03:00
  • 2022-09-04T02:00:00-03:00

As it can be seen, on the first record i do not know why it changes the -4 to -3. Anyway at the end it does the job. But as a consequence in the second record i do not get the plus hour.

So i am asking to understand how to upload pendulum to possibly update as well the library in the same way pytz did to correct the change of time in a week later that usual.

I do not want if i can avoid it to use another library because the code i am reviewing is using in other parts as well the library, so the idea is to fix the library not every operation.

Thanks

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
  • Hi. It appears that the Pendulum library is behind on maintenance of their time zone data. You should probably raise an issue here: https://github.com/sdispater/pendulum/issues – Matt Johnson-Pint Nov 07 '22 at 21:44
  • what's the relation to pytz? this seems to be solely related to pendulum. – FObersteiner Nov 08 '22 at 17:40
  • the relation is that the dataobject with the -4 offset is being generated with pytz, but when this dataobject with -4 offset is passed to pendulum then it fails because it seems pendulum is outdated – Víctor Rosillo Nov 09 '22 at 11:37
  • 1
    It makes no difference if you use a Python datetime object, set a pytz.timezone, then convert to pendulum datetime and add one hour ***or*** if you use pendulum datetime in the first place. You don't need pytz if you use pendulum. Still, pendulum's tz database is outdated and the result therefore incorrect. pytz is deprecated since Python 3.9. You might want to have a look at [zoneinfo](https://docs.python.org/3/library/zoneinfo.html), the up-to-date way to handle time zones in Python. – FObersteiner Nov 09 '22 at 19:23

0 Answers0