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


Python Arrow._get_datetime方法代码示例

本文整理汇总了Python中arrow.Arrow._get_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python Arrow._get_datetime方法的具体用法?Python Arrow._get_datetime怎么用?Python Arrow._get_datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arrow.Arrow的用法示例。


在下文中一共展示了Arrow._get_datetime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ArrowTests

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import _get_datetime [as 别名]
class ArrowTests(BaseArrowTests):

    def setUp(self):
        super(ArrowTests, self).setUp()

        self.arrow = Arrow(datetime.utcnow(), tz='UTC')

    def test_str(self):

        expected = '{0}.{1} +00:00 (UTC)'.format(time.strftime(
            '%x %X', self.arrow.datetime.timetuple()), self.arrow.datetime.microsecond)

        self.assertEqual(self.arrow.__str__(), expected)

    def test_repr(self):

        expected = 'Arrow({0}.{1} +00:00 (UTC))'.format(time.strftime(
            '%x %X', self.arrow.datetime.timetuple()), self.arrow.datetime.microsecond)

        self.assertEqual(self.arrow.__repr__(), expected)

    def test_tz(self):

        self.arrow._timezone = self.utc

        self.assertEqual(self.arrow.tz, self.utc)

    def test_to(self):

        self.arrow._datetime = datetime.utcnow().replace(tzinfo=self.utc.tzinfo)
        self.arrow._timezone = self.utc

        result = self.arrow.to('local')

        self.assert_dt_equal(result.datetime, self.arrow._datetime.astimezone(self.local.tzinfo))

    def test_utc_utc(self):

        self.arrow._datetime = datetime.now().replace(tzinfo=self.local.tzinfo)
        self.arrow._timezone = self.local

        result = self.arrow.utc()

        self.assert_dt_equal(result.datetime, self.arrow._datetime.astimezone(self.utc.tzinfo))

    def test_utc_local(self):

        self.arrow._datetime = datetime.utcnow().replace(tzinfo=self.utc.tzinfo)
        self.arrow._timezone = self.utc

        result = self.arrow.utc()

        self.assert_dt_equal(result.datetime, self.arrow._datetime.astimezone(self.utc.tzinfo))

    def test_datetime(self):

        dt = datetime.utcnow().replace(tzinfo=tz.tzutc())

        self.arrow._datetime = dt
        self.arrow._timezone = self.utc

        result = self.arrow.datetime

        self.assertEqual(result, dt)

    def test_timestamp_utc(self):

        dt = datetime.utcnow()

        self.arrow._datetime = dt
        self.arrow._timezone = self.utc

        result = self.arrow.timestamp

        self.assertEqual(result, calendar.timegm(dt.timetuple()))

    def test_timestamp_local(self):

        dt = datetime.now()

        self.arrow._datetime = dt
        self.arrow._timezone = self.local

        result = self.arrow.timestamp

        self.assertEqual(result, time.mktime(dt.timetuple()))

    def test_get_datetime_int(self):

        result = self.arrow._get_datetime(int(time.time()), self.utc)

        self.assert_dt_equal(result, datetime.utcnow())

    def test_get_datetime_float_utc(self):

        result = self.arrow._get_datetime(time.time(), self.utc)

        self.assert_dt_equal(result, datetime.utcnow())

    def test_get_datetime_float_local(self):
#.........这里部分代码省略.........
开发者ID:RedKrieg,项目名称:arrow,代码行数:103,代码来源:arrow_test.py


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