def timestamp_parameter(timestamp, allow_none=True):
if timestamp is None:
if allow_none:
return None
raise ValueError("Timestamp value cannot be None")
if isinstance(timestamp, datetime):
return timestamp.isoformat()
if isinstance(timestamp, basestring):
if not ISO_8601.match(timestamp):
raise ValueError(("Invalid timestamp: %s is not a valid ISO-8601"
" formatted date") % timestamp)
return timestamp
raise ValueError("Cannot accept type %s for timestamp" % type(timestamp))
评论列表
文章目录