Skip to main content

Type-safe Python package for timezone data with 400+ timezones, country associations, GMT offsets, and time conversion utilities.

Project description

countrystatecity-timezones

PyPI version Python versions

Official Python package for timezone data — 400+ IANA timezones with country associations, GMT offsets, and time conversion utilities. Part of the countrystatecity ecosystem.

Installation

pip install countrystatecity-timezones

Quick Start

from countrystatecity_timezones import (
    get_all_timezones,
    get_timezones_by_country,
    get_timezone_by_zone_name,
    get_timezones_by_offset,
    search_timezones,
    convert_time,
)
from datetime import datetime

# Get all timezones
timezones = get_all_timezones()
# [Timezone(zoneName="Africa/Abidjan", gmtOffset=0, ...), ...]

# Get timezones for a country
us_timezones = get_timezones_by_country("US")
# [Timezone(zoneName="America/Adak", countryCode="US", ...), ...]

# Lookup by IANA zone name
tz = get_timezone_by_zone_name("America/New_York")
# Timezone(zoneName="America/New_York", gmtOffset=-18000, gmtOffsetName="UTC-05:00", ...)

# Filter by GMT offset (seconds)
utc_minus_5 = get_timezones_by_offset(-18000)

# Search by name or abbreviation
results = search_timezones("Eastern")

# Convert time between timezones
dt = datetime(2024, 1, 1, 12, 0, 0)
converted = convert_time(dt, "America/New_York", "Asia/Kolkata")
# datetime(2024, 1, 1, 22, 30, tzinfo=ZoneInfo("Asia/Kolkata"))

Data Model

class Timezone(BaseModel):
    zoneName: str        # IANA timezone name (e.g., "America/New_York")
    gmtOffset: int       # GMT offset in seconds (e.g., -18000)
    gmtOffsetName: str   # Human-readable offset (e.g., "UTC-05:00")
    abbreviation: str    # Timezone abbreviation (e.g., "EST")
    tzName: str          # Full timezone name (e.g., "Eastern Standard Time")
    countryCode: str     # ISO2 country code (e.g., "US")
    countryName: str     # Country name (e.g., "United States")

API Reference

Function Description
get_all_timezones() Get all timezone entries
get_timezones_by_country(code) Get timezones for an ISO2 country code
get_timezone_by_zone_name(name) Lookup by IANA zone name
get_timezones_by_offset(seconds) Filter by GMT offset in seconds
search_timezones(query) Search by zone name, full name, or abbreviation
convert_time(dt, from_tz, to_tz) Convert datetime between IANA timezones

License

ODbL-1.0 — see LICENSE.

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

countrystatecity_timezones-1.0.3.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

countrystatecity_timezones-1.0.3-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file countrystatecity_timezones-1.0.3.tar.gz.

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.3.tar.gz
Algorithm Hash digest
SHA256 e192ab3349a2c95a2e32cf9254bcadb70493b3ef2a9d262e2abbbed8d2f35c5a
MD5 9df2f6351e8e493b34396aa1f86484b5
BLAKE2b-256 30db250c5d25eb499b5d26ac9fc348d595a00ab9720c4e22ef76eafd688afbf6

See more details on using hashes here.

File details

Details for the file countrystatecity_timezones-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for countrystatecity_timezones-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f3fdce506e31b8c40524745605c248dd126fe3f734a3e12e18cdc380ee3f67fe
MD5 7ab2d8b20c69dc7f0a018f8dc2abf776
BLAKE2b-256 269f26c2bab78ab9e343f4425cbc727cf2cb00f292404cda50c22befbbce22a9

See more details on using hashes here.

Supported by

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