### Using ZoneInfo with datetime (Python 3.9+) Source: https://tzdata.python.org/_sources/index.rst.txt Demonstrates how to get the current time in a specific time zone using the zoneinfo module. Requires Python 3.9 or later. ```python from datetime import datetime from zoneinfo import ZoneInfo dt = datetime.now(ZoneInfo("America/New_York")) ``` -------------------------------- ### Update tzdata to a new release Source: https://tzdata.python.org/_sources/maintaining.rst.txt Run the update environment to check for and install the latest IANA time zone database release. This command also allows specifying a target version. ```bash $ tox -e update -- --version=2020a ``` -------------------------------- ### Get Current Time with Time Zone (Python 3.9+) Source: https://tzdata.python.org/index.html Demonstrates how to get the current datetime object with a specific time zone using the zoneinfo module. Requires Python 3.9 or later. ```python from datetime import datetime from zoneinfo import ZoneInfo dt = datetime.now(ZoneInfo("America/New_York")) ``` -------------------------------- ### Create a post release version Source: https://tzdata.python.org/_sources/maintaining.rst.txt Use tox to bump the version to a post release. This is useful for creating a new release after an initial release, especially if issues are found. ```bash tox -e bump -- --post ``` -------------------------------- ### Accessing Zoneinfo Binaries with importlib.resources Source: https://tzdata.python.org/_sources/index.rst.txt Shows how to open zoneinfo binaries directly using importlib.resources. Each folder in tzdata.zoneinfo is treated as a package. ```python from importlib import resources # America/New_York with resources.open_binary("tzdata.zoneinfo.America", "New_York") as f: assert f.read(4) == b"TZif" ``` -------------------------------- ### Dry run for bumping release candidate version Source: https://tzdata.python.org/_sources/maintaining.rst.txt Use the bump release candidate version command with --dry-run to preview changes. This is useful for preparing release candidates. ```bash $ tox -e bump -- --rc --dry-run ``` -------------------------------- ### Dry run for bumping post release version Source: https://tzdata.python.org/_sources/maintaining.rst.txt Use the bump post release version command with --dry-run to preview changes. This is useful for creating patch releases. ```bash $ tox -e bump -- --post --dry-run ``` -------------------------------- ### Dry run for bumping development version Source: https://tzdata.python.org/_sources/maintaining.rst.txt Use the bump development version command with --dry-run to preview changes. This helps in understanding how version components are incremented. ```bash $ tox -e bump -- --dev --dry-run ``` -------------------------------- ### Bump to a release version Source: https://tzdata.python.org/_sources/maintaining.rst.txt Use the bump command with --release to remove all additional version markers and create a simple release version. This is typically done before a final release. ```bash $ tox -e bump -- --release ``` -------------------------------- ### Bump tzdata package version components Source: https://tzdata.python.org/maintaining.html These commands demonstrate how to increment different components of the `tzdata` package version (development, post-release, release candidate) or convert it to a full release using the `tox -e bump` environment. ```bash $ tox -e bump -- --dev --dry-run ... 2020.1rc1.post2.dev0 → 2020.1rc1.post2.dev1 ``` ```bash $ tox -e bump -- --post --dry-run ... 2020.1rc1.post2.dev0 → 2020.1rc1.post3 ``` ```bash $ tox -e bump -- --rc --dry-run ... 2020.1rc1.post2.dev0 → 2020.1rc2 ``` ```bash $ tox -e bump -- --release ... 2020.1rc1.post2.dev0 → 2020.1 ``` -------------------------------- ### Tag release script Source: https://tzdata.python.org/_sources/maintaining.rst.txt Execute the tag_release.sh script to automatically tag the repository with the current version from the VERSION file. This is the first step in the release process. ```bash ./tag_release.sh ``` -------------------------------- ### tzdata package version scheme Source: https://tzdata.python.org/maintaining.html This snippet illustrates the PEP 440-compliant versioning scheme used for the `tzdata` package, including release candidates, post-releases, and development versions. ```text YYYY.minor[rcX][.postY][.devZ] ``` -------------------------------- ### Access Time Zone Binary Data Source: https://tzdata.python.org/index.html Shows how to open and read time zone binary data (TZif format) from the tzdata package using importlib.resources. Each folder in tzdata.zoneinfo is treated as a package. ```python from importlib import resources # America/New_York with resources.open_binary("tzdata.zoneinfo.America", "New_York") as f: assert f.read(4) == b"TZif" ``` -------------------------------- ### Converting IANA Keys to Resource Paths Source: https://tzdata.python.org/_sources/index.rst.txt A utility function to convert IANA time zone keys into the package and resource names used by the tzdata package structure. Handles nested directories in IANA keys. ```python def iana_key_to_resource(key): package_loc, resource = key.rsplit("/", 1) package = "tzdata.zoneinfo." + package_loc.replace("/", ".") return package, resource assert iana_key_to_resource("America/New_York") == \ ("tzdata.zoneinfo.America", "New_York") assert iana_key_to_resource("America/Indiana/Indianapolis") == \ ("tzdata.zoneinfo.America.Indiana", "Indianapolis") ``` -------------------------------- ### Convert IANA Key to Resource Path Source: https://tzdata.python.org/index.html Provides a utility function to convert an IANA time zone key string into the corresponding package and resource names used by the tzdata package. This is useful for accessing time zone data programmatically. ```python def iana_key_to_resource(key): package_loc, resource = key.rsplit("/", 1) package = "tzdata.zoneinfo." + package_loc.replace("/", ".") return package, resource assert iana_key_to_resource("America/New_York") == \ ("tzdata.zoneinfo.America", "New_York") assert iana_key_to_resource("America/Indiana/Indianapolis") == \ ("tzdata.zoneinfo.America.Indiana", "Indianapolis") ``` -------------------------------- ### Update tzdata to a new IANA release Source: https://tzdata.python.org/maintaining.html This command updates the `tzdata` repository to a new IANA time zone database version, setting the base version and initializing it as a release candidate. ```bash $ tox -e update -- --version=2020a ... $ git diff VERSION -2019.3 +2020.1rc0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.