本文整理汇总了Python中ciso8601.parse_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python ciso8601.parse_datetime方法的具体用法?Python ciso8601.parse_datetime怎么用?Python ciso8601.parse_datetime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ciso8601
的用法示例。
在下文中一共展示了ciso8601.parse_datetime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_tz_offsets_too_large
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_invalid_tz_offsets_too_large(self):
# The Python interpreter crashes if you give the datetime constructor a TZ offset with an absolute value >= 1440
# TODO: Determine whether these are valid ISO 8601 values and therefore whether ciso8601 should support them.
self.assertRaisesRegex(
ValueError,
# Error message differs whether or not we are using pytz or datetime.timezone
r"^offset must be a timedelta strictly between" if sys.version_info.major >= 3 else r"\('absolute offset is too large', -5940\)",
ciso8601.parse_datetime,
'2018-01-01T00:00:00.00-99',
)
self.assertRaisesRegex(
ValueError,
r"tzminute must be in 0..59",
ciso8601.parse_datetime,
'2018-01-01T00:00:00.00-23:60',
)
示例2: test_mixed_basic_and_extended_formats
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_mixed_basic_and_extended_formats(self):
"""
Both dates and times have "basic" and "extended" formats.
But when you combine them into a datetime, the date and time components
must have the same format.
"""
self.assertRaisesRegex(
ValueError,
r"Cannot combine \"extended\" date format with \"basic\" time format",
ciso8601.parse_datetime,
'2014-01-02T010203',
),
self.assertRaisesRegex(
ValueError,
r"Cannot combine \"basic\" date format with \"extended\" time format",
ciso8601.parse_datetime,
'20140102T01:02:03',
)
示例3: test_valid_rfc3339_timestamps
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_valid_rfc3339_timestamps(self):
"""
Validate that valid RFC 3339 datetimes are parseable by parse_rfc3339
and produce the same result as parse_datetime.
"""
for string in [
'2018-01-02T03:04:05Z',
'2018-01-02t03:04:05z',
'2018-01-02 03:04:05z',
'2018-01-02T03:04:05+00:00',
'2018-01-02T03:04:05-00:00',
'2018-01-02T03:04:05.12345Z',
'2018-01-02T03:04:05+01:23',
'2018-01-02T03:04:05-12:34',
'2018-01-02T03:04:05-12:34',
]:
self.assertEqual(ciso8601.parse_datetime(string),
ciso8601.parse_rfc3339(string))
示例4: _should_process_row
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def _should_process_row(self, row, date_column, is_full_month, is_finalized=None):
"""Determine if we want to process this row.
Args:
row (dict): The line item entry from the AWS report file
date_column (str): The name of date column to check
is_full_month (boolean): If this is the first time we've processed this bill
Kwargs:
is_finalized (boolean): If this is a finalized bill
Returns:
(bool): Whether this row should be processed
"""
if is_finalized or is_full_month:
return True
row_date = ciso8601.parse_datetime(row[date_column]).date()
if row_date < self.data_cutoff_date:
return False
return True
示例5: convert_date
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def convert_date(self, date_string):
"""Converts date from string format to date object, for use by DateField."""
if date_string:
try:
# TODO: for now, return as a string.
# When actually supporting DateField, then switch back to date.
# ciso8601.parse_datetime(ts).astimezone(pytz.utc).date().isoformat()
return self.date_field_for_converting.deserialize_from_string(date_string).isoformat()
except ValueError:
self.incr_counter(self.counter_category_name, 'Cannot convert to date', 1)
# Don't bother to make sure we return a good value
# within the interval, so we can find the output for
# debugging. Should not be necessary, as this is only
# used for the column value, not the partitioning.
return u"BAD: {}".format(date_string)
# return self.lower_bound_date_string
else:
self.incr_counter(self.counter_category_name, 'Missing date', 1)
return date_string
示例6: test_problem_check
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_problem_check(self):
template = self.event_templates['problem_check']
event = self.create_event_log_line(template=template)
expected_key = (self.DEFAULT_DATE, self.task.PROJECT_NAME)
expected_dict = {
'input_file': '',
'source': self.task.PROJECT_NAME,
'event_type': 'problem_check',
'emitter_type': 'server',
'timestamp': ciso8601.parse_datetime('2013-12-17T15:38:32.805444+00:00'),
'received_at': ciso8601.parse_datetime('2013-12-17T15:38:32.805444+00:00'),
'date': datetime.date(*[int(x) for x in self.DEFAULT_DATE.split('-')]),
'username': 'test_user',
'course_id': self.encoded_course_id,
'org_id': self.encoded_org_id,
'user_id': '10',
'raw_event': self.get_raw_event(event),
}
expected_value = JsonEventRecord(**expected_dict).to_separated_values()
self.assert_single_map_output(event, expected_key, expected_value)
示例7: test_android_screen
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_android_screen(self):
template = self.event_templates['android_screen']
event = self.create_event_log_line(template=template)
expected_key = (self.DEFAULT_DATE, self.DEFAULT_PROJECT)
expected_dict = {
'input_file': '',
'source': self.DEFAULT_PROJECT,
'event_type': 'screen',
'emitter_type': 'server',
'timestamp': ciso8601.parse_datetime('2013-12-17T15:38:32.700000+00:00'),
'received_at': ciso8601.parse_datetime('2013-12-17T15:38:32.796000+00:00'),
'date': datetime.date(*[int(x) for x in self.DEFAULT_DATE.split('-')]),
'agent_type': 'tablet',
'agent_device_name': 'Samsung SM-N920A',
'agent_os': 'Android',
'agent_browser': 'Android',
'agent_touch_capable': True,
'anonymous_id': self.DEFAULT_ANONYMOUS_ID,
'category': 'screen',
'label': 'Launch\\0',
'raw_event': self.get_raw_event(event),
}
expected_value = JsonEventRecord(**expected_dict).to_separated_values()
self.assert_single_map_output(event, expected_key, expected_value)
示例8: test_auto_generated_valid_formats
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_auto_generated_valid_formats(self):
for (timestamp, expected_datetime) in generate_valid_timestamp_and_datetime():
try:
self.assertEqual(ciso8601.parse_datetime(timestamp), expected_datetime)
except Exception:
print("Had problems parsing: {timestamp}".format(timestamp=timestamp))
raise
示例9: test_excessive_subsecond_precision
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_excessive_subsecond_precision(self):
self.assertEqual(
ciso8601.parse_datetime('20140203T103527.234567891234'),
datetime.datetime(2014, 2, 3, 10, 35, 27, 234567)
)
示例10: test_leap_year
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_leap_year(self):
# There is nothing unusual about leap years in ISO 8601.
# We just want to make sure that they work in general.
for leap_year in (1600, 2000, 2016):
self.assertEqual(
ciso8601.parse_datetime('{}-02-29'.format(leap_year)),
datetime.datetime(leap_year, 2, 29, 0, 0, 0, 0)
)
示例11: test_special_midnight
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_special_midnight(self):
self.assertEqual(
ciso8601.parse_datetime('2014-02-03T24:00:00'),
datetime.datetime(2014, 2, 4, 0, 0, 0)
)
示例12: test_parse_auto_generated_invalid_formats
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_parse_auto_generated_invalid_formats(self):
for timestamp in generate_invalid_timestamp():
try:
with self.assertRaises(ValueError, msg="Timestamp '{0}' was supposed to be invalid, but parsing it didn't raise ValueError.".format(timestamp)):
ciso8601.parse_datetime(timestamp)
except Exception as exc:
print("Timestamp '{0}' was supposed to raise ValueError, but raised {1} instead".format(timestamp, type(exc).__name__))
raise
示例13: test_invalid_calendar_separator
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_invalid_calendar_separator(self):
self.assertRaisesRegex(
ValueError,
r"Invalid character while parsing month",
ciso8601.parse_datetime,
'2018=01=01',
)
self.assertRaisesRegex(
ValueError,
r"Invalid character while parsing date separator \('-'\) \('=', Index: 7\)",
ciso8601.parse_datetime,
'2018-01=01',
)
self.assertRaisesRegex(
ValueError,
r"Invalid character while parsing date separator \('-'\) \('0', Index: 7\)",
ciso8601.parse_datetime,
'2018-0101',
)
self.assertRaisesRegex(
ValueError,
r"Invalid character while parsing day \('-', Index: 6\)",
ciso8601.parse_datetime,
'201801-01',
)
示例14: test_invalid_day_for_month
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_invalid_day_for_month(self):
for non_leap_year in (1700, 1800, 1900, 2014):
self.assertRaisesRegex(
ValueError,
r"day is out of range for month",
ciso8601.parse_datetime,
'{}-02-29'.format(non_leap_year)
)
self.assertRaisesRegex(
ValueError,
r"day is out of range for month",
ciso8601.parse_datetime,
'2014-01-32',
)
self.assertRaisesRegex(
ValueError,
r"day is out of range for month",
ciso8601.parse_datetime,
'2014-06-31',
)
self.assertRaisesRegex(
ValueError,
r"day is out of range for month",
ciso8601.parse_datetime,
'2014-06-00',
)
示例15: test_invalid_yyyymm_format
# 需要导入模块: import ciso8601 [as 别名]
# 或者: from ciso8601 import parse_datetime [as 别名]
def test_invalid_yyyymm_format(self):
self.assertRaisesRegex(
ValueError,
r"Unexpected end of string while parsing day. Expected 2 more characters",
ciso8601.parse_datetime,
'201406',
)