A wrapper around the datetime, pytz and tzlocal packages for Python 3.2+. Full docs on github.
Examples
Just give me a UTC datetime for these dates!
>>> for date in '1/6/2013 BST', '1/6/2013 EST', 'Tue, 18 Jun 2013 12:19:09 -0400': >>> print(best_guess_utc(date)) 2013-05-31 23:00:00+00:00 2013-01-06 05:00:00+00:00 2013-06-18 16:19:09+00:00
What time is it now, in New York?
>>> SimpleDate(tz='America/New_York')
SimpleDate('2013-06-14 13:14:17.295943 EDT', tz='America/New_York')
And what time is that in the UK (the country code is for Great Britain)?
>>> SimpleDate('2013-06-14 13:14:17.295943 EDT').convert(country='GB')
SimpleDate('2013-06-14 18:14:17.295943 BST', tz='Europe/London')
What is the UTC for this email date?
>>> SimpleDate('Fri, 14 Jun 2013 13:13:42 -0400').utc
SimpleDate('Fri, 14 Jun 2013 17:13:42 +0000', tz='UTC')
What’s the date a week from now (I live in Chile)?
>>> SimpleDate() + timedelta(days=7)
SimpleDate('2013-06-21 13:55:20.791519 CLT', tz='America/Santiago')
The day of the week for Xmas this year?
>>> SimpleDate(2013, 12, 24).weekday 1
And as a naive datetime?
>>> SimpleDate(2013, 12, 24).naive.datetime datetime.datetime(2013, 12, 24, 0, 0)
What’s the time in EST for epoch 1234567890?
>>> SimpleDate(1234567890, tz='EST') AmbiguousTimezone: 3 distinct timezones found: <'EST'>; <'Australia/NSW'>; ...
Whoa! What are those crazy Australians doing? Let’s force the USA (only):
>>> SimpleDate(1234567890, tz='EST', country='US')
SimpleDate('2009-02-13 18:31:30.000000 EST')
Alternatively, we could give priority to the USA and take the first solution we find:
>>> SimpleDate(1234567890, tz='EST', country=prefer('US'), unsafe=True)
SimpleDate('2009-02-13 18:31:30.000000 EST')
And what day is that?
>>> SimpleDate(1234567890, tz='EST', country=prefer('US'), unsafe=True).strftime('%A')
'Friday'
Licence
(c) 2013,2015 Andrew Cooke, andrew@acooke.org; released into the public domain for any use, but with absolutely no warranty.
Metadata
Release files for simple-date 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple-date-0.5.0.tar.gz | 27.7 kB | Without provenance | Details for simple-date-0.5.0.tar.gz |
Release files / simple-date-0.5.0.tar.gz
| Download URL | simple-date-0.5.0.tar.gz |
|---|---|
| Size | 27.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27bcd055c3ca7557936be160d6626edd180d424a6a899fccd786c8a7ad4244cf
|
|
BLAKE2b-256 checksum How to use checksums |
c062c31f66ffc0c86c9565a73a0e9673d4c30b01ce8912a4c0e47975bbf99761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for simple-date 0.5.0
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.