Skip to content

Date and time is handled well by core python. This module offers a DateSequence and a DateIterator class that creates a sequence of dates or datetimes for you.

Notifications You must be signed in to change notification settings

paulskeie/timehelpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

timehelpers

Date and time is handled well by core python.

This module offers:

  1. A DateSequence class that creates a sequence of dates for you.
  2. A TimeIterator class that is initialized with starttime and timedeltastep and implements a next() method.

DateSequence produces the full sequence of successive days in memory upon initialization. TimeIterator is more lightweight and only keeps track of which is the next datetime to return.

DateSequence

The DateSequence class is initialized with a start and end date string like so:

from timehelpers import DateSequence

ds=DateSequence('20180210','20180331')

The initialization takes an optional keyword argument datestr_format='%Y%m%d' where '%Y%m%d' is the default.

For convenience the class has an iterator so you can do: for d in ds: do something After the initialization the instance has a list of dates stored in the dateseq attribute.

TimeIterator

Usage:

from timehelpers import TimeIterator
from datetime import datetime,timedelta

datetimestart=datetime.strptime("2018010103","%Y%m%d%H")
timedeltastep=timedelta(hours=3)

ti=TimeIterator(datetimestart,timedeltastep)

nextdatetime=ti.next()
# or
nextdatetime=ti()

About

Date and time is handled well by core python. This module offers a DateSequence and a DateIterator class that creates a sequence of dates or datetimes for you.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages