pytz Python historical timezone library and database

Overview

pytz

Brings the IANA tz database into Python. This library allows accurate and cross platform timezone calculations.

pytz contains generated code, and this branch generates it. The actual pytz code and documentation can be found in the src/ directory.

Usage Information / Documentation

See the pytz README.

pytz for Enterprise

Available as part of the Tidelift Subscription.

The maintainers of pytz and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Release process

1) Untar upstream tarballs into elsie/src
2) Update VERSION & OLSON_VERSION in src/pytz/__init__.py, and EXPECTED_VERSION in
   src/pytz/tests/test_tzinfo.py
3) make test
4) make dist
Comments
  • Can't run Django - No Time Zone Found Error

    Can't run Django - No Time Zone Found Error

    Can't start my Django if I set the version 2022.2:

    Command: python manage.py produces the following output:

    zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Asia/Hanoi'
    

    If I set requirements version to pytz==2022.1 then it works fine.

    Please advise.

    opened by colinschwegmann 8
  • Update spelling of Ukrainian geographical names

    Update spelling of Ukrainian geographical names

    Resolution by UN Economic and Social Council, 10th UN Conference on the Standardization of Geographical Names (2012).

    Matches spelling adopted by IATA and ICAO.

    opened by savchenko 6
  • API to preload all data files

    API to preload all data files

    In a dynamic deployment environment, sometimes it's needed to "warm" the library by preloading all the data files before the application starts. Would be great if the library had a single entry point for that, to have a shared, stable way of doing so.

    opened by besfahbod 4
  • pytz still using IANA  Time Zone Database 2021c

    pytz still using IANA Time Zone Database 2021c

    the current version Time Zone Database is 2021e, so 2021c seems outdated. This might cause invalid UTC offsets like e.g.

    from datetime import datetime
    import pytz
    
    >>> dt = datetime.fromisoformat('2046-05-31 22:00:00+00:00').astimezone(pytz.timezone("Europe/Paris"))
    >>> print(dt)
    2046-05-31 23:00:00+01:00
    # should be 
    # 2046-06-01 00:00:00+02:00
    
    >>> print(pytz.__version__)
    2021.3
    
    from zoneinfo import ZoneInfo
    >>> dt = datetime.fromisoformat('2046-05-31 22:00:00+00:00').astimezone(ZoneInfo("Europe/Paris"))
    >>> print(dt)
    2046-06-01 00:00:00+02:00
    
    >>> import tzdata
    >>> print(tzdata.IANA_VERSION)
    2021e
    

    Python 3.9.4 on Windows 10

    opened by FObersteiner 3
  • OverflowError with time.mktime using pytz 2021.3

    OverflowError with time.mktime using pytz 2021.3

    We are observing an unexpected OverflowError from time.mktime. So far we're only able to reproduce within Github Actions.

    I'm unsure if the issue is related to pytz. However, I thought it would make sense to open an issue here first to rule it out.

    A minimally reproducible example of the issue is below:

    import datetime
    import time
    import pytz
    x = pytz.timezone('US/Pacific')
    y = datetime.datetime(2017,5,26,15,30,16)
    z = x.localize(y)
    print(time.mktime(z.timetuple()))
    

    The code above appears to work on Python 3.9 using pytz 2021.3 on OSX 11.6.1, Centos 7.9, Ubuntu 18.04 and macos-latest in Github Actions. However, it does not appear to work within ubuntu-latest on Github Actions. In all cases, Python and pytz are being sourced by conda.

    An example log of the failure can be found here. The build configuration has been minimized as to only install Python 3.9 and pytz (latest).

    A passing execution, on macos-latest, can be found here.

    Please let me know if additional information would be helpful. I apologize if this issue is being opened on the wrong project, and if it instead would be better for python-dev. It does appear the issue has been noted with python-dev but closed on the assumption it was related to pytz.

    Thank you for your time, and all your hard work on this foundational project.

    opened by wasade 3
  • UTC is not a BaseTzInfo instance?

    UTC is not a BaseTzInfo instance?

    I am confused by the following behavior:

    >>> import pytz
    >>> pytz.__version__
    '2018.3'
    >>> utc = pytz.timezone('UTC')
    >>> la = pytz.timezone('America/Los_Angeles')
    >>> isinstance(utc, pytz.tzinfo.BaseTzInfo)
    False
    >>> isinstance(la, pytz.tzinfo.BaseTzInfo)
    True
    

    Is this intended, and if so, why?

    Thanks!

    opened by jenstroeger 3
  • Error when update pytz version to 2022.2

    Error when update pytz version to 2022.2

    File "/usr/local/lib/python3.10/site-packages/timezone_field/init.py", line 1, in from timezone_field.fields import TimeZoneField File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 11, in class TimeZoneField(models.Field): File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in TimeZoneField default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] File "/usr/local/lib/python3.10/zoneinfo/_common.py", line 24, in load_tzdata raise ZoneInfoNotFoundError(f"No time zone found with key {key}") zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Asia/Hanoi'

    opened by franklindias 2
  • AttributeError: module 'posixpath' has no attribute 'sep'

    AttributeError: module 'posixpath' has no attribute 'sep'

    Hi, I'm having an AttributeError: module 'posixpath' has no attribute 'sep' because this if statement. I'm using python 3.10.4.

    I'm not using pytz directly, but instead, I'm profiling a web app and that happens when I start the profiler (scalene) with scalene app.py and PyBabel calls pytz. If needed I can paste here the traceback.

    However, after taking a look at the os module, indeed there isn't an os.path.sep attribute. But there is os.sep or os.pathsep. In this case, I think the most appropriate method would be the os.sep because it returns the OS path separator. If this is a real issue with pytz, I'm happy to provide PR to fix it.

    Cheers

    opened by fullonic 2
  • 2021.3: pytest is failing on missimg 'all_timezones' variable

    2021.3: pytest is failing on missimg 'all_timezones' variable

    I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

    • python3 -sBm build -w
    • install .whl file in </install/prefix>
    • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

    Here is pytest output:

    + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytz-2021.3-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytz-2021.3-2.fc35.x86_64/usr/lib/python3.8/site-packages
    + /usr/bin/pytest -ra
    =========================================================================== test session starts ============================================================================
    platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
    rootdir: /home/tkloczko/rpmbuild/BUILD/pytz-release_2021.3/src
    collected 41 items / 1 error / 40 selected
    
    ================================================================================== ERRORS ==================================================================================
    ________________________________________________________________ ERROR collecting pytz/tests/test_tzinfo.py ________________________________________________________________
    pytz/tests/test_tzinfo.py:40: in <module>
        GMT = pytz.timezone('GMT')
    ../../../BUILDROOT/python-pytz-2021.3-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytz/__init__.py:179: in timezone
        zone = _case_insensitive_zone_lookup(_unmunge_zone(zone))
    ../../../BUILDROOT/python-pytz-2021.3-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytz/__init__.py:205: in _case_insensitive_zone_lookup
        _all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in all_timezones)  # noqa
    E   NameError: name 'all_timezones' is not defined
    ========================================================================= short test summary info ==========================================================================
    ERROR pytz/tests/test_tzinfo.py - NameError: name 'all_timezones' is not defined
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ============================================================================= 1 error in 1.64s =============================================================================
    
    opened by kloczek 2
  • Base class for all errors in the library

    Base class for all errors in the library

    Would be great to have a single "base" class for all errors that could be raised by the library.

    Looking at https://github.com/stub42/pytz/blob/master/src/pytz/exceptions.py, there are two base classes at the moment: UnknownTimeZoneError and InvalidTimeError.

    Without a guaranteed single base class, a package upgrade may add new error types, without call-sites being updated about the change.

    opened by besfahbod 2
  • Please confirm typing of _tzinfos kwarg for typeshed

    Please confirm typing of _tzinfos kwarg for typeshed

    👋 Hi! New contributor here. I'm updating the typing stubs for pytz in typeshed (PR#3393), specifically adding FixedOffset's typing. I'm unsure about the kwarg though, _tzinfos.

    Here's the line I've put in typeshed. @stub42 Can you confirm the typing of _tzinfos (and, of course, let me know if the other types are wrong). The typeshed tests run, and it looks right to me... but I don't know pytz well enough. Thanks!

    opened by angelaambroz 2
  • Superset of all_timezones/common_timezones is hardcoded

    Superset of all_timezones/common_timezones is hardcoded

    On Debian-based systems (including Ubuntu) pytz is patched to use the tzdata information from the system. That allows updating tzdata without needing to update pytz every time.

    The superset of all_timezones and common_timezones is hard-coded in the pytz release (in pytz/__init__.py). When tzdata adds a timezone or renames one (e.g. Ubuntu bug #1995864), pytz needs to be updated.

    pytz should evaluate the available timezones on the system to work with future tzdata updates.

    Bug-Ubuntu: https://launchpad.net/bugs/207604

    opened by bdrung 1
  • CET/CEST and Europe/Stockholm issues

    CET/CEST and Europe/Stockholm issues

    For the better part of a day I've been trying to properly calculate the number of hours in a given day using Python and pytz. I have significant experience doing date and time calculations, so this should be a simple task. However, I feel like I am being blocked at every exit.

    Please consider the following code:

    from datetime import datetime, timedelta
    from pytz import timezone
    
    # Set some things up
    format = "%Y-%m-%d %H:%M:%S %Z%z"
    tz_local = timezone('CET') #Europe/Stockholm
    tz_utc = timezone('UTC')
    
    # Set up a date just before the switch from winter to summer time
    original = datetime(2022, 3, 25, 13, 11, 25, tzinfo = tz_local)
    print(original.strftime(format))
    # Create the same date in the world of UTC, where date calculations are easy as pie
    redating = datetime(original.year, original.month, original.day, tzinfo = tz_utc)
    # Add a week to the date
    redating = redating + timedelta(days = 7)
    # Create new date+time, with the original time, in the original timezone
    output = datetime(redating.year, redating.month, redating.day, original.hour, original.minute, original.second, original.microsecond, tzinfo = tz_local)
    print(output.strftime(format))
    # Convert to UTC and back again.... (!?)
    output = output.astimezone(tz_utc).astimezone(tz_local)
    print(output.strftime(format))
    

    The output is:

    2022-03-25 13:11:25 CET+0100
    2022-04-01 13:11:25 CET+0100
    2022-04-01 14:11:25 CEST+0200
    

    I know there have been discussions regarding whether CET should, or should not, have a fixed offset from UTC.

    I am working under the understanding that:

    • CET does NOT have a fixed offset from UTC - it observes summer and winter time.
    • CEST is not an actual timezone, it is still CET - but during the summer.

    Since I am someone who is used to dealing with the complexities at hand, and live in a country that observes CET you should absolutely not listen to me, because who know - I might just be full of it. Instead, you should listen to the large number of verifiable sources, online and offline, that claim the same, giving these statements at least some weight. Also, since pytz does not make a CEST timezone available, it would seem we are in agreement.

    Regardless of correctness, it seems quite schizophrenic that I am getting CET from datetime(), but CEST after converting to UTC and back.

    The output I would expect from this program is:

    2022-03-25 13:11:25 CET+0100
    2022-04-01 13:11:25 CEST+0200
    2022-04-01 13:11:25 CEST+0200
    

    So, in light of the discussions I've seen on the topic of what CET really is, I decided to go ahead and switch tz_local to Europe/Stockholm - a location-based timezone which, according to those discussions, should always observe DST if applicable.

    After this, I get the following output:

    2022-03-25 13:11:25 LMT+0053
    2022-04-01 13:11:25 LMT+0053
    2022-04-01 14:18:25 CEST+0200
    

    This output made me faceplant the keyboard, demand comfort from my wife, and undertake several therapy sessions at the local pub.

    Sweden, including Stockholm, like most European countries, observe CET. I know we are seen as quite backward at times here in Sweden, but I assure you that LMT+0053 is just too weird, even for us.

    It may very well be that I am completely wrong or that I am doing things completely wrong. If this is the case, then I beg your forgiveness for wasting your time and humbly ask to be corrected. If, however, I am correct - it seems there is a bug in datetime() where it does not correctly return dates that fall within CEST as such, as well as a bug in pytz where it returns incorrect tzinfo for Europe/Stockholm.

    I understand that the behavior of datetime() does not fall on pytz to dictate. But perhaps, given pytz popularity in the date- and time-loving python subcommunity, you might have some pull with the in-crowd.

    All the best.

    opened by stg 1
  • Change of timezone name Europe/Kiev to Europe/Kyiv and Europe/Zaporozhye to Europe/Zaporizhzhia

    Change of timezone name Europe/Kiev to Europe/Kyiv and Europe/Zaporozhye to Europe/Zaporizhzhia

    "Europe/Kiev", "Europe/Zaporozhye" are to be changed into "Europe/Kyiv", "Europe/Zaporizhzhia" respectively

    https://phabricator.wikimedia.org/T149523

    opened by vizvasrj 0
  • _FixedOffset Base Class

    _FixedOffset Base Class

    While most timezone classes share a BaseTzInfo class, _FixedOffset does not. Functionally it doesn't really make a difference, but with stricter type checking it can become troublesome. Some interfaces from third-party projects specify BaseTzInfo within type annotations where _FixedOffset should also work.

    Would you be open to a change that just replaces class _FixedOffset(datetime.tzinfo): with class _FixedOffset(BaseTzInfo):?

    opened by AlecRosenbaum 0
  • Please add Europe/Kyiv timezone in ukrainian manner

    Please add Europe/Kyiv timezone in ukrainian manner

    Some browsers have different names of timezones: in Ukrainian manner (Europe/Kyiv) and in russian manner (Europe/Kiev).

    Could you please track both (Europe/Kyiv) and (Europe/Kiev) to fix the changes between different browsers ?

    Thanks you.

    opened by Mihail12 0
  • Mypy compliance / type checking

    Mypy compliance / type checking

    Would there be any interest in a PR to add typing for mypy compliance? The main benefits are better IDE integration and improved static type checking on projects that use pytz

    Effort is pretty minimal, mypy only raises 14-18 errors currently, depending on the python version.

    A stubs repo already does exist: much of that could likely https://github.com/python/typeshed/tree/master/stubs/pytz/pytz

    Type hinting is quite easy in python 3.6+. Not sure how long compatibility for python 2.7/3.5 (seen in pipelines) is intended for but that's doable too, just less elegant https://mypy.readthedocs.io/en/stable/cheat_sheet.html

    opened by tgross35 2
Owner
Stub
Stub
A simple in-process python scheduler library, designed to be integrated seamlessly with the `datetime` standard library.

scheduler A simple in-process python scheduler library, designed to be integrated seamlessly with the datetime standard library. Due to the support of

null 30 Dec 30, 2022
A Python 3 library for parsing human-written times and dates

Chronyk A small Python 3 library containing some handy tools for handling time, especially when it comes to interfacing with those pesky humans. Featu

Felix Wiegand 339 Dec 19, 2022
darts is a Python library for easy manipulation and forecasting of time series.

A python library for easy manipulation and forecasting of time series.

Unit8 5.2k Jan 1, 2023
A Python library for dealing with dates

moment A Python library for dealing with dates/times. Inspired by Moment.js and Kenneth Reitz's Requests library. Ideas were also taken from the Times

Zach Williams 709 Dec 9, 2022
Generate and work with holidays in Python

python-holidays A fast, efficient Python library for generating country, province and state specific sets of holidays on the fly. It aims to make dete

Maurizio Montel 881 Dec 29, 2022
A datetime parser in Python by Ari24-cb24 and NekoFantic

datetimeparser A datetime parser in Python by Ari24-cb24 and NekoFantic V 1.0 Erinnerung für den Parser Auf falsche Eingaben überprüfen Liste an Event

AriDevelopment 13 Dec 30, 2022
Useful extensions to the standard Python datetime features

dateutil - powerful extensions to datetime The dateutil module provides powerful extensions to the standard datetime module, available in Python. Inst

null 2k Dec 29, 2022
Python datetimes made easy

Pendulum Python datetimes made easy. Supports Python 2.7 and 3.4+. >>> import pendulum >>> now_in_paris = pendulum.now('Europe/Paris') >>> now_in_par

Sébastien Eustace 5.3k Jan 6, 2023
PyTime is an easy-use Python module which aims to operate date/time/datetime by string.

PyTime PyTime is an easy-use Python module which aims to operate date/time/datetime by string. PyTime allows you using nonregular datetime string to g

Sinux 148 Dec 9, 2022
Friendly Python Dates

When.py: Friendly Dates and Times Production: Development: User-friendly functions to help perform common date and time actions. Usage To get the syst

Andy Dirnberger 191 Oct 14, 2022
Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 5, 2023
python parser for human readable dates

Python parser for human readable dates Key Features • How To Use • Installation • Common use cases • You may also like... • License Key Features Suppo

Scrapinghub 2.2k Jan 8, 2023
Make Python datetime formatting human readable

Make Python datetime formatting human readable

James Timmins 0 Oct 3, 2021
A simple digital clock made with the help of python

Digital-Clock ⏰ Description ?? ✔️ A simple digital clock made with the help of python. The code is easy to understand and implement. With this reposit

Mohit 0 Dec 10, 2021
E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

null 2.8k Jan 6, 2023
⌚️Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with Internet Time 😉

Internet-Ti.me Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with

Jessica Stokes 17 Nov 2, 2022
i18n and l10n support for Flask based on Babel and pytz

Flask Babel Implements i18n and l10n support for Flask. This is based on the Python babel module as well as pytz both of which are installed automatic

null 397 Dec 15, 2022
A Python module that tries to figure out what your local timezone is

tzlocal This Python module returns a tzinfo object with the local timezone information under Unix and Windows. It requires either Python 3.9+ or the b

Lennart Regebro 159 Dec 16, 2022
This contains timezone mapping information for when preprocessed from the geonames data

when-data This contains timezone mapping information for when preprocessed from the geonames data. It exists in a separate repository so that one does

Armin Ronacher 2 Dec 7, 2021
Whole-day timezone comparison

Timezone Converter Compare a full day of your local timezone with foreign ones $ timezone-converter tijuana --zone $ timezone-converter tijuana new_yo

Iago Alonso 12 Nov 24, 2022