Skip to main content

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()

  • Added microseconds to format_duration() thanks to Javier Ruere

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%

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

whenIO-1.5.2.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file whenIO-1.5.2.tar.gz.

File metadata

  • Download URL: whenIO-1.5.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for whenIO-1.5.2.tar.gz
Algorithm Hash digest
SHA256 df02aa62793e278af99c45cbeff6158409b4aea978b6f9cb33f5112a5942e8a0
MD5 d4bd1247b5ece32c97d053e030c2c190
BLAKE2b-256 e9ea1167f413904d36811a9d9132b5ad40c1998d0bc00c5c9c2cec3c88619ce7

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