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!

Methods for formatting and parsing friendly timestamps

Project Description

Here are some methods for formatting and parsing friendly timestamps.

Installation

easy_install -U whenIO

Usage

>>> import whenIO
>>> import datetime
>>> w = whenIO.WhenIO(timezone='US/Eastern')

>>> w.format(datetime.datetime.now(), fromUTC=False)
'Today 2:30pm'
>>> w.format(datetime.datetime.utcnow())
'Today 2:30pm'
>>> w.format(datetime.datetime.utcnow(), forceDate=True)
'Today 3/10/2013 2:30pm'
>>> date1 = datetime.datetime(2000, 1, 1, 0, 0)
>>> date2 = datetime.datetime(2000, 1, 1, 1, 0)
>>> w.format([date1, date2], fromUTC=False)
'1/1/2000 12am 1am'

>>> w.parse('10am', toUTC=False)[0]
[datetime.datetime(2013, 3, 10, 10, 0)]
>>> w.parse('today 10am', toUTC=False)[0]
[datetime.datetime(2013, 3, 10, 10, 0)]
>>> w.parse('tom 8pm', toUTC=False)[0]
[datetime.datetime(2013, 3, 11, 20, 0)]
>>> w.parse('mon 10am 12pm', toUTC=False)[0]
[datetime.datetime(2013, 3, 11, 10, 0),
 datetime.datetime(2013, 3, 11, 12, 0)]

>>> rdelta = whenIO.parse_duration('111 weeks')
>>> whenIO.format_duration(rdelta)
'2 years 3 months 3 weeks'
>>> whenIO.format_duration(rdelta, precision=2, style='abbreviations')
'2 yrs 4 mos'

1.5

  • Added unit abbreviations and letters to parse_duration(), format_duration()
  • Added control over rounding behavior to format_duration()

1.4

  • Added forceDate to format(), format_date()
  • Replaced withStartDate to omitStartDate

1.3

  • Changed constructor to use timezones from pytz and tzlocal
  • Added weeks to format_duration()
  • Added withLeadingZero to format(), format_date(), format_time()
  • Added withStartDate to format()
  • Removed parse_offset(), format_offset()

1.2

  • Removed python-dateutil==1.5 requirement
  • Restored test coverage to 100%

1.1

  • Added format_duration() for formatting relativedelta objects
  • Added parse_duration() for parsing text into relativedelta objects

1.0

  • Expanded test coverage to 100%
Release History

Release History

This version
History Node

1.5.1

History Node

1.5

History Node

1.4

History Node

1.3

History Node

1.2

History Node

1.1

History Node

1.0

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
whenIO-1.5.1.tar.gz (6.5 kB) Copy SHA256 Checksum SHA256 Source Nov 28, 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