当前位置: 首页>>代码示例>>Python>>正文


Python Timestamp.from_rfc3339方法代码示例

本文整理汇总了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())
开发者ID:JavierRoger,项目名称:beam,代码行数:13,代码来源:timestamp_test.py

示例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
开发者ID:apsaltis,项目名称:incubator-beam,代码行数:20,代码来源:transform_evaluator.py

示例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
开发者ID:charlesccychen,项目名称:incubator-beam,代码行数:19,代码来源:transform_evaluator.py

示例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')
开发者ID:JavierRoger,项目名称:beam,代码行数:7,代码来源:timestamp_test.py


注:本文中的apache_beam.utils.timestamp.Timestamp.from_rfc3339方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。