Skip to main content

whenIO

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%

Metadata

Release files for whenIO 1.5.2

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

Source distribution (sdist)

Source distribution for whenIO 1.5.2
File Size Uploaded
whenIO-1.5.2.tar.gz 6.6 kB Details

Release files / whenIO-1.5.2.tar.gz

Download URL whenIO-1.5.2.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
df02aa62793e278af99c45cbeff6158409b4aea978b6f9cb33f5112a5942e8a0
BLAKE2b-256 checksum
How to use checksums
e9ea1167f413904d36811a9d9132b5ad40c1998d0bc00c5c9c2cec3c88619ce7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.5.2 This release

1 release file

1.5.1

1 release file

1.5

1 release file

1.4

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

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