Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Simple dates (and times, and timezones).

Project Description

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 Andrew Cooke, andrew@acooke.org; released into the public domain for any use, but with absolutely no warranty.

Release History

Release History

History Node

0.5.0

History Node

0.4.8

History Node

0.4.7

History Node

0.4.6

History Node

0.4.5

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.6

History Node

0.3.5

History Node

0.3.4

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

This version
History Node

0.3.0

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.8

History Node

0.0.7

History Node

0.0.6

History Node

0.0.5

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
simple-date-0.3.0.tar.gz (27.4 kB) Copy SHA256 Checksum SHA256 Source Jun 24, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting