Skip to main content

Overview

dtrange has multi-calendar datetime, date and time range iterators.

Features

  • Half-open or closed bounds.

  • Non-uniform step date units, such as leap years and months.

  • Alternative calendars: 360, all-leap, no-leap, gregorian, julian

  • Ordinals (total days) for all calendar dates.

  • Fraction arithmetic.

  • [lower, upper) bounds search.

  • Python 2 & 3.

Examples

Datetime

from datetime import datetime, timedelta from dtrange import dtrange

start = datetime(2000, 1, 1) stop = datetime(2020, 2, 1) step = timedelta(1)

for it in dtrange(start, stop, step, endpoint=True):

print(it)

for units in [‘y’, ‘m’, ‘w’, ‘d’, ‘h’, ‘min’, ‘s’, ‘ms’, ‘us’]:
for it in dtrange(start, stop, step=1, units=units):

print(units,it)

for it in dtrange(start, stop, n=10):

print(it)

for it in dtrange(start, step, n=10):

print(it)

for units in [‘y’, ‘m’, ‘w’, ‘d’, ‘h’, ‘min’, ‘s’, ‘ms’, ‘us’]:
for it in dtrange(start, step=1, units=units, n=10):

print(units,it)

from dtrange import dtfraction

print(dtfraction(datetime(2000,1,1), datetime(2001,1,1), datetime(2002,1,1)))

Date

from datetime import date, timedelta from dtrange import drange

start = date(2000, 1, 1) stop = date(2005, 2, 1) step = timedelta(days=1)

for calendar in [‘360’, ‘gregorian’, ‘julian’, ‘leap’, ‘noleap’]:
for it in drange(start, stop, step, calendar=calendar):

print(calendar,it)

from dtrange import dfraction

print(dfraction(date(2000,1,1), date(2001,1,1), date(2002,1,1)))

Time

from datetime import time, timedelta from dtrange import trange

start = time(0, 0, 0) stop = time(0, 1, 0) step = timedelta(seconds=1)

for it in trange(start, stop, step):

print(it)

from dtrange import tfraction

print(tfraction(time(1,1,1), time(2,1,1), time(3,1,1)))

Testing

make test

Installation

From PyPi.

pip install dtrange

From tarball.

python setup.py install

License

dtrange Copyright (C) 2016 Remik Ziemlinski

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the conditions of the GPLv3 license.

Metadata

Release files for dtrange 1.2.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 dtrange 1.2.2
File Size Uploaded Provenance Actions
dtrange-1.2.2.tar.gz 6.4 kB Without provenance Details for dtrange-1.2.2.tar.gz

Release files / dtrange-1.2.2.tar.gz

Download URL dtrange-1.2.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
66bd0b7d341d67672b495c9d9969f7066fae7999215a70de35408f10c8a4cd9a
BLAKE2b-256 checksum
How to use checksums
4345265aaa2b40bb17c4835f8210ba7c0a2e058dda3f443181cd3c14aeae077a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for dtrange 1.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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