Skip to main content
Help us improve Python packaging – donate today!

Check if timestamp falls within specific boundaries

Project Description

What Is This?

Timespans allow you to check if a timestamp falls within a specified list of boundaries. For example, you might want to program your phone system to only accept calls Mon-Fri from 9 a.m. to 5 p.m. except on holidays like Christmas.

Timespans are specified in the form of times|daysofweek|days|months. If your timespan starts with !, it’ll only match if the timestamps falls outside the given range.

Basic example:

import timespan
from datetime import datetime

business_hours = [
    '9:00-17:00|mon-fri|*|*',  # is between 9 a.m. to 5 p.m. on Mon to Fri
    '!*|*|1|jan',              # not new years
    '!*|*|25|dec',             # not christmas
    '!*|thu|22-28|nov',        # not thanksgiving

if timespan.match(business_hours,
    print "we're open for business!"
    print "sorry, we're closed :("

For more examples, see the documentation or source code.


From folder:

sudo python install

From cheeseshop:

sudo pip install timespan

From git:

sudo pip install git+git://

Release history Release notifications

This version
History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
timespan-0.1.tar.gz (4.3 kB) Copy SHA256 hash SHA256 Source None Mar 30, 2012

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page