Skip to main content

Parse and format timedelta

Project description

timedeltafmt

A tool to parse and format timedelta

Examples

from datetime import timedelta

from timedeltafmt import parse_timedelta, format_timedelta, make_formatter, MICROSECOND, SECOND

print(parse_timedelta('1day 24h'))  # 2 days, 0:00:00
print(parse_timedelta('10s 1m 1s'))  # 0:01:11

print(format_timedelta(timedelta(weeks=1)))  # 7d
print(format_timedelta(timedelta(days=365.25)))  # 1y

JIFFY_FMT = make_formatter({
    MICROSECOND: 'ms',
    SECOND // 50: 'jiffies',
})

print(JIFFY_FMT.format(timedelta(seconds=2)))  # 100jiffies

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

timedeltafmt-0.1.1.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

timedeltafmt-0.1.1-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

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