本文整理汇总了Python中apache_beam.utils.timestamp.Timestamp.from_rfc3339方法的典型用法代码示例。如果您正苦于以下问题:Python Timestamp.from_rfc3339方法的具体用法?Python Timestamp.from_rfc3339怎么用?Python Timestamp.from_rfc3339使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apache_beam.utils.timestamp.Timestamp
的用法示例。
在下文中一共展示了Timestamp.from_rfc3339方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_rfc3339
# 需要导入模块: from apache_beam.utils.timestamp import Timestamp [as 别名]
# 或者: from apache_beam.utils.timestamp.Timestamp import from_rfc3339 [as 别名]
def test_from_rfc3339(self):
test_cases = [
(10000000, '1970-04-26T17:46:40Z'),
(10000000.000001, '1970-04-26T17:46:40.000001Z'),
(1458343379.123456, '2016-03-18T23:22:59.123456Z'),
]
for seconds_float, rfc3339_str in test_cases:
self.assertEqual(Timestamp(seconds_float),
Timestamp.from_rfc3339(rfc3339_str))
self.assertEqual(rfc3339_str,
Timestamp.from_rfc3339(rfc3339_str).to_rfc3339())
示例2: _get_element
# 需要导入模块: from apache_beam.utils.timestamp import Timestamp [as 别名]
# 或者: from apache_beam.utils.timestamp.Timestamp import from_rfc3339 [as 别名]
def _get_element(message):
parsed_message = PubsubMessage._from_message(message)
if timestamp_attribute:
try:
rfc3339_or_milli = parsed_message.attributes[timestamp_attribute]
except KeyError as e:
raise KeyError('Timestamp attribute not found: %s' % e)
try:
timestamp = Timestamp.from_rfc3339(rfc3339_or_milli)
except ValueError:
try:
timestamp = Timestamp(micros=int(rfc3339_or_milli) * 1000)
except ValueError as e:
raise ValueError('Bad timestamp value: %s' % e)
else:
timestamp = Timestamp.from_rfc3339(message.service_timestamp)
return timestamp, parsed_message
示例3: _get_element
# 需要导入模块: from apache_beam.utils.timestamp import Timestamp [as 别名]
# 或者: from apache_beam.utils.timestamp.Timestamp import from_rfc3339 [as 别名]
def _get_element(message):
parsed_message = PubsubMessage._from_message(message)
if (timestamp_attribute and
timestamp_attribute in parsed_message.attributes):
rfc3339_or_milli = parsed_message.attributes[timestamp_attribute]
try:
timestamp = Timestamp.from_rfc3339(rfc3339_or_milli)
except ValueError:
try:
timestamp = Timestamp(micros=int(rfc3339_or_milli) * 1000)
except ValueError as e:
raise ValueError('Bad timestamp value: %s' % e)
else:
timestamp = Timestamp(message.publish_time.seconds,
message.publish_time.nanos // 1000)
return timestamp, parsed_message
示例4: test_from_rfc3339_failure
# 需要导入模块: from apache_beam.utils.timestamp import Timestamp [as 别名]
# 或者: from apache_beam.utils.timestamp.Timestamp import from_rfc3339 [as 别名]
def test_from_rfc3339_failure(self):
with self.assertRaisesRegexp(ValueError, 'parse'):
Timestamp.from_rfc3339('not rfc3339')
with self.assertRaisesRegexp(ValueError, 'parse'):
Timestamp.from_rfc3339('2016-03-18T23:22:59.123456Z unparseable')