Skip to main content

Backport of the standard library zoneinfo module

Project description

backports.zoneinfo: Backport of the standard library module zoneinfo

This package was originally the reference implementation for PEP 615, which proposes support for the IANA time zone database in the standard library, and now serves as a backport to Python 3.8.

This exposes the backports.zoneinfo module, which is a backport of the zoneinfo module. The backport's documentation can be found on readthedocs.

The module uses the system time zone data if available, and falls back to the tzdata package (available on PyPI) if installed.

Installation and depending on this library

This module is called backports.zoneinfo on PyPI. To install it in your local environment, use:

pip install backports.zoneinfo

Or (particularly on Windows), you can also use the tzdata extra (which basically just declares a dependency on tzdata, so this doesn't actually save you any typing 😅):

pip install backports.zoneinfo[tzdata]

If you want to use this in your application, it is best to use PEP 508 environment markers to declare a dependency conditional on the Python version:

backports.zoneinfo;python_version<"3.9"

Support for backports.zoneinfo in Python 3.9+ is currently minimal, since it is expected that you would use the standard library zoneinfo module instead.

Use

The backports.zoneinfo module should be a drop-in replacement for the Python 3.9 standard library module zoneinfo. If you do not support anything earlier than Python 3.9, you do not need this library; if you are supporting Python 3.8+, you may want to use this idiom to "fall back" to backports.zoneinfo:

try:
    import zoneinfo
except ImportError:
    from backports import zoneinfo

To get access to time zones with this module, construct a ZoneInfo object and attach it to your datetime:

>>> from backports.zoneinfo import ZoneInfo
>>> from datetime import datetime, timedelta, timezone
>>> dt = datetime(1992, 3, 1, tzinfo=ZoneInfo("Europe/Minsk"))
>>> print(dt)
1992-03-01 00:00:00+02:00
>>> print(dt.utcoffset())
2:00:00
>>> print(dt.tzname())
EET

Arithmetic works as expected without the need for a "normalization" step:

>>> dt += timedelta(days=90)
>>> print(dt)
1992-05-30 00:00:00+03:00
>>> dt.utcoffset()
datetime.timedelta(seconds=10800)
>>> dt.tzname()
'EEST'

Ambiguous and imaginary times are handled using the fold attribute added in PEP 495:

>>> dt = datetime(2020, 11, 1, 1, tzinfo=ZoneInfo("America/Chicago"))
>>> print(dt)
2020-11-01 01:00:00-05:00
>>> print(dt.replace(fold=1))
2020-11-01 01:00:00-06:00

>>> UTC = timezone.utc
>>> print(dt.astimezone(UTC))
2020-11-01 06:00:00+00:00
>>> print(dt.replace(fold=1).astimezone(UTC))
2020-11-01 07:00:00+00:00

Contributing

Currently we are not accepting contributions to this repository because we have not put the CLA in place and we would like to avoid complicating the process of adoption into the standard library. Contributions to CPython will eventually be backported to this repository — see the Python developer's guide for more information on how to contribute to CPython.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backports.zoneinfo-0.1.0b0.tar.gz (71.8 kB view details)

Uploaded Source

Built Distributions

backports.zoneinfo-0.1.0b0-cp38-cp38-win_amd64.whl (38.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

backports.zoneinfo-0.1.0b0-cp38-cp38-win32.whl (36.4 kB view details)

Uploaded CPython 3.8 Windows x86

backports.zoneinfo-0.1.0b0-cp38-cp38-macosx_10_14_x86_64.whl (35.6 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

File details

Details for the file backports.zoneinfo-0.1.0b0.tar.gz.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b0.tar.gz
  • Upload date:
  • Size: 71.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 3f9f771b601a31e86233851acc2989bd14b3b57791f1d985b369f73cb0e15608
MD5 80b3ada104f66b8517e1cd711ab8282d
BLAKE2b-256 bb8db5e3e2da72f7fa687643766d52cfebdab3402bc165a25247f97a9bfba04b

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c84af3bf7d9fd84704979d4f0ef7aacc34f0d5409ec26345dd2240bd7096e3d6
MD5 0565f887dcb00806f647154713bf837c
BLAKE2b-256 cee4ab0ecce13eb55e7f735ef83cfc5cebcf8905d85b493a2b89fea1bc523462

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b0-cp38-cp38-win32.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 36.4 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 7b2e3c71605683b8334428690db85cdd03ba35843bd762735c0188ffc231f250
MD5 6bfd5a76c42451c2b33c75f33a9b0072
BLAKE2b-256 4f765dabc00b964790b325013a2dc1e4e9aab8c5d28ea052bb27649497a7ff44

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for backports.zoneinfo-0.1.0b0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9da738644c350232cb2f43dc16f4e2dadc6d814dc4aafbffe376147ad4a4a536
MD5 cd52643445488aecd2c246c46573a7e5
BLAKE2b-256 fb6a7069603f9a99ccc6a734391433f650db17748231a7e2c130344ba48483fb

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b0-cp38-cp38-manylinux1_i686.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b0-cp38-cp38-manylinux1_i686.whl
  • Upload date:
  • Size: 71.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b0-cp38-cp38-manylinux1_i686.whl
Algorithm Hash digest
SHA256 38291a5c1a20601ad934d7e9de032a52ae0d8b93031224e5fbc2da28884178a6
MD5 09d84f50fb5a07d5a5ff098dc9c98cb5
BLAKE2b-256 ac02a845408168bc800845c0bf47ac7f269f443c85dfd47f2cf70af8c0d2a731

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b0-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 87890d65150fd7a5bde63e3d5ec2a8e1cd0b943825997c562c9a394ef020899d
MD5 3ff62595ca6e02a177ccb1211eccd051
BLAKE2b-256 038940c8ff853e520d2d140b2b5b69264306e01fac655376520b2cd09ac53d07

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page