本文整理匯總了Python中isodatetime.parsers.TimePointParser.strptime方法的典型用法代碼示例。如果您正苦於以下問題:Python TimePointParser.strptime方法的具體用法?Python TimePointParser.strptime怎麽用?Python TimePointParser.strptime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類isodatetime.parsers.TimePointParser
的用法示例。
在下文中一共展示了TimePointParser.strptime方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RoseDateTimeOperator
# 需要導入模塊: from isodatetime.parsers import TimePointParser [as 別名]
# 或者: from isodatetime.parsers.TimePointParser import strptime [as 別名]
class RoseDateTimeOperator(object):
"""A class to parse and print date string with an offset."""
CURRENT_TIME_DUMP_FORMAT = u"CCYY-MM-DDThh:mm:ss+hh:mm"
CURRENT_TIME_DUMP_FORMAT_Z = u"CCYY-MM-DDThh:mm:ssZ"
NEGATIVE = "-"
# strptime formats and their compatibility with the ISO 8601 parser.
PARSE_FORMATS = [
("%a %b %d %H:%M:%S %Y", True), # ctime
("%a %b %d %H:%M:%S %Z %Y", True), # Unix "date"
("%Y-%m-%dT%H:%M:%S", False), # ISO8601, extended
("%Y%m%dT%H%M%S", False), # ISO8601, basic
("%Y%m%d%H", False) # Cylc (current)
]
REC_OFFSET = re.compile(r"""\A[\+\-]?(?:\d+[wdhms])+\Z""", re.I)
REC_OFFSET_FIND = re.compile(r"""(?P<num>\d+)(?P<unit>[wdhms])""")
STR_NOW = "now"
STR_REF = "ref"
TASK_CYCLE_TIME_ENV = "ROSE_TASK_CYCLE_TIME"
UNITS = {"w": "weeks",
"d": "days",
"h": "hours",
"m": "minutes",
"s": "seconds"}
def __init__(self, parse_format=None, utc_mode=False, calendar_mode=None,
ref_point_str=None):
"""Constructor.
parse_format -- If specified, parse with the specified format.
Otherwise, parse with one of the format strings in
self.PARSE_FORMATS. The format should be a string
compatible to strptime(3).
utc_mode -- If True, parse/print in UTC mode rather than local or
other timezones.
calendar_mode -- Set calendar mode, for isodatetime.data.Calendar.
ref_point_str -- Set the reference time point for operations.
If not specified, operations use current date time.
"""
self.parse_formats = self.PARSE_FORMATS
self.custom_parse_format = parse_format
self.utc_mode = utc_mode
if self.utc_mode:
assumed_time_zone = (0, 0)
else:
assumed_time_zone = None
self.set_calendar_mode(calendar_mode)
self.time_point_dumper = TimePointDumper()
self.time_point_parser = TimePointParser(
assumed_time_zone=assumed_time_zone)
self.duration_parser = DurationParser()
self.ref_point_str = ref_point_str
def date_format(self, print_format, time_point=None):
"""Reformat time_point according to print_format.
time_point -- The time point to format.
Otherwise, use ref date time.
"""
if time_point is None:
time_point = self.date_parse()[0]
if print_format is None:
return str(time_point)
if "%" in print_format:
try:
return time_point.strftime(print_format)
except ValueError:
return self.get_datetime_strftime(time_point, print_format)
return self.time_point_dumper.dump(time_point, print_format)
def date_parse(self, time_point_str=None):
"""Parse time_point_str.
Return (t, format) where t is a isodatetime.data.TimePoint object and
format is the format that matches time_point_str.
time_point_str -- The time point string to parse.
Otherwise, use ref time.
"""
if time_point_str is None or time_point_str == self.STR_REF:
time_point_str = self.ref_point_str
if time_point_str is None or time_point_str == self.STR_NOW:
time_point = get_timepoint_for_now()
#.........這裏部分代碼省略.........