检查时间戳是否在特定范围内
timespan的Python项目详细描述
name: | timespan |
---|---|
description: | Check if timestamp falls within specific boundaries |
Copyright: | © 2012 Justine Alexandra Roberts Tunney |
license: | MIT |
这是什么?
时间跨度允许您检查时间戳是否位于 边界。例如,您可能希望将电话系统编程为 接受周一至周五上午9点至下午5点的电话,圣诞节等节假日除外。
时间跨度以times|daysofweek|days|months的形式指定。如果 您的时间跨度以!开头,只有时间戳落下时才会匹配 超出给定范围。
基本示例:
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 :("
有关更多示例,请参阅文档或源代码。
安装
从文件夹:
sudo python setup.py install
来自芝士店:
sudo pip install timespan
来自Git:
sudo pip install git+git://github.com/jart/timespan.git