Skip to main content

Calculate and convert times across time zones.

Project description

https://github.com/dakrauth/when/actions/workflows/test.yml/badge.svg

Usage

To access city names, you must install the cities database, downloaded from http://download.geonames.org/export/dump/citiesXXX.zip - depending upon where you specify the --size [500|1000|5000|15000] or --pop POP option(s).

$ when --help
usage: when [-h] [-s SOURCE] [-t TARGET] [-f FORMAT] [--all] [--holidays HOLIDAYS] [-v] [-V] [--pdb] [--db] [--search SEARCH] [--alias ALIAS] [--size SIZE]
            [--pop POP]
            [timestamp ...]

Convert times to and from time zones or cities

positional arguments:
  timestamp             Timestamp to parse, defaults to local time

options:
  -h, --help            show this help message and exit
  -s SOURCE, --source SOURCE
                        Timezone / city to convert the timestamp from, defaulting to local time
  -t TARGET, --target TARGET
                        Timezone / city to convert the timestamp to (globbing patterns allowed, can be comma delimited), defaulting to local time
  -f FORMAT, --format FORMAT
                        Output formatting. Additionaly predefined formats by name are rfc2822, iso, . Default: %Y-%m-%d %H:%M:%S%z (%Z) %jd%Ww %C %O, where %K
                        is timezone long name
  --all                 Show times in all common timezones
  --holidays HOLIDAYS   Show holidays for given country code.
  -v, --verbosity       Verbosity (-v, -vv, etc)
  -V, --version         show program's version number and exit
  --pdb
  --db                  Togge database mode, used with --search, --alias, --size, and --pop
  --search SEARCH       Search database for the given city (used with --db)
  --alias ALIAS         (Used with --db) Create a new alias from the city id
  --size SIZE           (Used with --db) Geonames file size. Can be one of 1000, 500, 15000, 5000.
  --pop POP             (Used with --db) City population minimum.

Examples:
=========

# Show the time in a given source city or time zone

when --source New York City
when --source America/New_York

# Show the specified time at a given source in local time

when --source Paris,FR 21:35

# Show the specified time at a given source in the target locale's time

when --target Bangkok --source Seattle

Example

$ when
2023-02-11 17:43:44+0900 (KST) 042d06w  [🌖 Waning Gibbous]

$ when --source CST
2023-02-11 02:44:22-0600 (Central Standard Time) 042d06w  [🌖 Waning Gibbous]
2023-02-11 12:44:22+0400 (Caucasus Standard Time) 042d06w  [🌖 Waning Gibbous]
2023-02-11 16:44:22+0800 (China Standard Time) 042d06w  [🌖 Waning Gibbous]
2023-02-11 03:44:22-0500 (Cuba Standard Time) 042d06w  [🌖 Waning Gibbous]

$ when --source Paris
2023-02-11 09:45:11+0100 (Europe/Paris) 042d06w  (Villeparisis, FR, Île-de-France) [🌖 Waning Gibbous]
2023-02-11 09:45:11+0100 (Europe/Paris) 042d06w  (Paris, FR, Île-de-France) [🌖 Waning Gibbous]
2023-02-11 09:45:11+0100 (Europe/Paris) 042d06w  (Cormeilles-en-Parisis, FR, Île-de-France) [🌖 Waning Gibbous]
2023-02-11 03:45:11-0500 (America/Port-au-Prince) 042d06w  (Fond Parisien, HT, Ouest) [🌖 Waning Gibbous]
2023-02-11 02:45:11-0600 (America/Chicago) 042d06w  (Paris, US, Texas) [🌖 Waning Gibbous]

$ when --source "San Francisco,US" --target America/New_York Mar 7 1945 7:00pm
1945-03-07 22:00:00-0400 (America/New_York) 066d10w  [🌘 Waning Crescent]
1945-03-07 22:00:00-0400 (America/New_York) 066d10w  [🌘 Waning Crescent]

Develop

Requirements Python 3.7+

$ git clone git@github.com:dakrauth/when.git
$ cd when
$ python -mvenv venv
$ . venv/bin/activate
$ pip install .
$ when --help
$ when --db
$ pip install tox
$ tox

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

when-2.0.0.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

when-2.0.0-py3-none-any.whl (81.0 kB view details)

Uploaded Python 3

File details

Details for the file when-2.0.0.tar.gz.

File metadata

  • Download URL: when-2.0.0.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for when-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f76b8e88cfc093972cf64722feeec5300cccecfc233cffb78b5f1a9a5ba616e5
MD5 4d640a2ffa0446e4315e8f4a6085398e
BLAKE2b-256 15865717b0a6f7ba41ab1bbfc268fb37e5fdffa3e5e81d7a53fbe7215ed17c72

See more details on using hashes here.

File details

Details for the file when-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: when-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 81.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for when-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94f1d92e5b3d7bd8f70cc176df3a110607b541e7e3bb11ad8711beb7b1d842a1
MD5 0a834fe6f3dfbe8ba0850c958cfd2f60
BLAKE2b-256 a30763f9b82dd75d09fe01fe2db0972cda50e431a62eb05925521694344cc281

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