Skip to main content

Multi-calendar datetime, date, and time range iterators.

Project description


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


  • 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.



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):
for units in [‘y’, ‘m’, ‘w’, ‘d’, ‘h’, ‘min’, ‘s’, ‘ms’, ‘us’]:
for it in dtrange(start, stop, step=1, units=units):
for it in dtrange(start, stop, n=10):
for it in dtrange(start, step, n=10):
for units in [‘y’, ‘m’, ‘w’, ‘d’, ‘h’, ‘min’, ‘s’, ‘ms’, ‘us’]:
for it in dtrange(start, step=1, units=units, n=10):

from dtrange import dtfraction

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


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

from dtrange import dfraction

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


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

from dtrange import tfraction

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


make test


From PyPi.

pip install dtrange

From tarball.

python install


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.

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

dtrange-1.2.2.tar.gz (6.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page