Skip to main content

wtftz

WTF Timezones?!

I can’t convert UTC to PST in my head, and google can’t do it for me either.

Every timezone converter website is full of spam and the worst UX imaginable.

wtftz assumes you’re trying to convert a UTC timestamp

print(wtftz.convert("2012-12-10T18:31:29.214653", "pst"))
# 2012-12-10 10:31:29.214653

unless you’re not

Note the embedded timezone in this iso-formatted string.

print(wtftz.convert("2012-12-10T18:31:29.214653-08:00", "pst"))
# 2012-12-10 18:31:29.214653

wtftz knows a few common abbreviations for timezones

print(wtftz.convert("1355236920", "est"))
# 2012-12-11 01:42:00
# Sorry, Australia! EST is most commonly used for US/Eastern!

wtftz gives back tzinfo-free timestamps because python’s timezones are broken!

print(wtftz.convert(datetime.datetime.now(), from_tz="pst", to_tz="utc"))
# 2012-12-11 06:45:04.075608
print(wtftz.convert(datetime.datetime.now(), from_tz="pst", to_tz="eastern"))
# 2012-12-11 01:45:18.343536

wtftz knows that you don’t know if the current time is PST or PDT

But it does the right thing, using PST or PDT when appropriate

print(wtftz.convert(datetime.datetime.now(), "pst"))
# 2012-12-11 06:48:39.860947
print(wtftz.convert(datetime.datetime.now(), "pdt"))
# 2012-12-11 06:48:39.860947

wtftz knows that you work with systems with nonstandard timestamp formats

print(wtftz.convert('2012/10/7 12:25:46', 'pst'))
# 2012-10-07 19:25:46
print(wtftz.convert('7 October 2012 12:25:46', 'pst'))
# 2012-10-07 19:25:46

wtftz will accept proper timezone names, too

print(wtftz.convert(datetime.datetime.now(), "US/Pacific"))
# 2012-12-10 15:04:03.644934
print(wtftz.convert(datetime.datetime.now(), "America/Chicago"))
# 2012-12-10 17:04:03.650494

But it can’t handle everything

print(wtftz.convert('2012:10:7:12:25:46', 'pst'))
# ...
# ValueError: Cannot parse timestamp 2012:10:7:12:25:46

Use it from the shell!

$ date && ./wtftz "`date`" pst && ./wtftz "`date`" utc
Mon Dec 10 23:43:06 PST 2012
2012-12-10 23:43:06
2012-12-11 07:43:06
$ date +%s && ./wtftz "`date +%s`" utc
1355211747
2012-12-10 23:42:27

Wtftz can also handle free text strings

print(wtftz.convert_free("1355236920 to est"))
# 2012-12-11 01:42:00
print(wtftz.convert_free("2012-12-10T18:31:29.214653-08:00 to est"))
# 2012-12-10 21:31:29.214653
print(wtftz.convert_free("2012-12-10T18:31:29.214653 from pst to est"))
# 2012-12-10 21:31:29.214653
print(wtftz.convert_free("2012-12-10T18:31:29.214653 from utc to est"))
# 2012-12-10 13:31:29.214653

Installation

wtftz is in the cheese shop, so just:

pip install wtftz

Development

Issues and Pull Requests are welcome!

I’m looking to expand the list of common timezone names to include foreign (to me) timezones and make the free-text parser smarter.

Testing

Tests are important. Pull requests will not be accepted without them.

python -m unittest discover

Readme

This README should be updated with examples as new behavior is added. To ensure that the file is formatted correctly, please check it:

pip install docutils
pip install pygments
python setup.py --long-description | rst2html.py > output.html

Ensure that the file parses and looks good.

Metadata

Release files for wtftz 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wtftz 0.2.4
File Size Uploaded Provenance Actions
wtftz-0.2.4.tar.gz 5.8 kB Without provenance Details for wtftz-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wtftz 0.2.4
File Interpreter ABI Platform Actions
wtftz-0.2.4-py2.7.egg Legacy Egg format - - Details for wtftz-0.2.4-py2.7.egg

Total release size: 16.2 kB

Release files / wtftz-0.2.4.tar.gz

Download URL wtftz-0.2.4.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6db466e9251cc05c4bb64dcca1e40f0d8f9c098ab93467b4e90ec5469c824757
BLAKE2b-256 checksum
How to use checksums
5f86147b83b3c3b2481341205fb737db2e51389260f32b893b6359263631d8ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / wtftz-0.2.4-py2.7.egg

Download URL wtftz-0.2.4-py2.7.egg
Size 10.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
25316fea8d73d11b8180d0e6a2707c10a3edbf5f3d5f4e1709b00a346289fd39
BLAKE2b-256 checksum
How to use checksums
9eae758efe7830dcf9c600962106717b61e964cadd902a66e9f6867b60fd017b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for wtftz 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page