Skip to content

Instantly share code, notes, and snippets.

View berislavlopac's full-sized avatar

Berislav Lopac berislavlopac

View GitHub Profile
@obeattie
obeattie / datetime_range.py
Created October 19, 2009 12:31
A datetime range class for Python, for (obviously) dealing with ranges of datetimes.
"""Provides a `DateTimeRange` class, which is used for managing ranges of datetimes."""
import datetime
class DateTimeRange(object):
"""Represents a range of datetimes, with a start and (optionally) an end.
Basically implements most of the methods on a standard sequence data type to provide
some lovely syntactic sugar. Specifically, you can iterate on this, index it, slice it,
use the in operator, reverse it, and use it in a boolean context to see if there is any
time in between the start and end."""