Giter Site home page Giter Site logo

timespan's Introduction

timespan

name:timespan
description:Check if timestamp falls within specific boundaries
Copyright: © 2012 Justine Alexandra Roberts Tunney
license:MIT

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, datetime.now()):
    print "we're open for business!"
else:
    print "sorry, we're closed :("

For more examples, see the documentation or source code.

Installation

From folder:

sudo python setup.py install

From cheeseshop:

sudo pip install timespan

From git:

sudo pip install git+git://github.com/jart/timespan.git

timespan's People

Contributors

livni avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.