Skip to main content

command-line tool to convert a date and time to several time zones at once

Project description

tzconv: convert a date and time to several time zones at once

This Python package provides a small command-line utility to convert a YYYY-MM-DD HH:MM formatted date and time to several other time zones.

Installation

tzconv is available through PyPI:

$ python3 -m pip install tzconv

Alternatively, you can install it directly from the Codeberg Git repository:

$ git clone https://codeberg.org/gnyeki/tzconv
$ python3 -m pip install --user ./tzconv

Usage

Basic usage

tzconv uses the time zone information available through your operating system, so time zones have to be specified accordingly:

$ tzconv \
    -f America/New_York \
    -t America/Los_Angeles \
    -t America/Halifax \
    -t Asia/Karachi \
    -t Asia/Calcutta \
    "2023-04-25 10:00"
EDT: 2023-04-25 10:00 (America/New_York)
PDT: 2023-04-25 07:00 (America/Los_Angeles)
ADT: 2023-04-25 11:00 (America/Halifax)
PKT: 2023-04-25 19:00 (Asia/Karachi)
IST: 2023-04-25 19:30 (Asia/Calcutta)
$

Daylight savings

Daylight savings can complicate conversions. However, thanks to the Python standard library, tzconv is aware of changes to daylight savings, and it infers the correct offsets. For example, in March 2023, New York switched to daylight savings two weeks earlier than Budapest. Notice the switch from EST/CET to EDT/CET, and finally to EDT/CEST:

$ tzconv -f America/New_York -t Europe/Budapest "2023-03-07 10:00"
EST: 2023-03-07 10:00 (America/New_York)
CET: 2023-03-07 16:00 (Europe/Budapest)
$ tzconv -f America/New_York -t Europe/Budapest "2023-03-14 10:00"
EDT: 2023-03-14 10:00 (America/New_York)
CET: 2023-03-14 15:00 (Europe/Budapest)
$ tzconv -f America/New_York -t Europe/Budapest "2023-03-28 10:00"
EDT: 2023-03-28 10:00 (America/New_York)
CEST: 2023-03-28 16:00 (Europe/Budapest)
$

Custom shell commands for common conversions

If you have a project that spans several time zones, it is convenient to define a command for it in your .bashrc, .zshrc, or equivalent dot file, depending on what shell you use. For example, if you are using zsh, you can add the following to ~/.zshrc:

project_tz() {
    tzconv \
        --from-tz America/New_York \
        --to-tz America/Los_Angeles \
        --to-tz America/Halifax \
        --to-tz Asia/Karachi \
        --to-tz Asia/Calcutta \
        "$*"
}

Now you can reload ~/.zshrc and use project_tz as a shell command:

$ . ~/.zshrc
$ project_tz 2023-04-25 10:00
EDT: 2023-04-25 10:00 (America/New_York)
PDT: 2023-04-25 07:00 (America/Los_Angeles)
ADT: 2023-04-25 11:00 (America/Halifax)
PKT: 2023-04-25 19:00 (Asia/Karachi)
IST: 2023-04-25 19:30 (Asia/Calcutta)
$

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

tzconv-1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

tzconv-1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file tzconv-1.0.tar.gz.

File metadata

  • Download URL: tzconv-1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for tzconv-1.0.tar.gz
Algorithm Hash digest
SHA256 744d8747fa65b2b62a0ff7da2e341ca5ee2f63ca0ccf7aa4f20f67a5330685dd
MD5 f00012efa3dbc5604520bc1705f64033
BLAKE2b-256 cd5189497514403b78d6d2e342871fcb8d5f9882090c54517ecd4c9d4687c116

See more details on using hashes here.

File details

Details for the file tzconv-1.0-py3-none-any.whl.

File metadata

  • Download URL: tzconv-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for tzconv-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 887313c61df743df3e489a02ebe098969d0627fc0f076d7229fc00dc3d7f7775
MD5 6035ae5636395794a57aa598e614a46f
BLAKE2b-256 32186d658f721d5ce5c739392e3e4e121ac6de64c5d16ce83337ee8deda79ea6

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