本文整理汇总了Python中arrow.Arrow.to方法的典型用法代码示例。如果您正苦于以下问题:Python Arrow.to方法的具体用法?Python Arrow.to怎么用?Python Arrow.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow.Arrow
的用法示例。
在下文中一共展示了Arrow.to方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zone_to_zone
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
def test_zone_to_zone(self):
dt_1 = datetime.utcnow() + timedelta(hours=-2)
dt_2 = datetime.utcnow() + timedelta(hours=2)
arr_1 = Arrow(dt_1, timedelta(hours=-2))
arr_2 = Arrow(dt_2, timedelta(hours=2))
result_1 = arr_1.to(timedelta(hours=2))
result_2 = arr_2.to(timedelta(hours=-2))
self.assert_dt_equal(result_1.datetime, arr_2.datetime)
self.assert_dt_equal(result_2.datetime, arr_1.datetime)
示例2: blacklist_project
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
def blacklist_project(self, project: db.Project, reset_time: arrow.Arrow):
"""
Add specified project to `self.ratelimit_queue`, add backend to
`self.blacklist_dict` and increment `self.ratelimit_counter`.
Args:
project: Project to blacklist
reset_time: Time when the ratelimit will be reset
"""
with self.blacklist_dict_lock:
if project.backend not in self.blacklist_dict:
_log.debug(
"Rate limit threshold reached. Adding {} to blacklist.".format(
project.backend
)
)
self.blacklist_dict[project.backend] = reset_time.to("utc").datetime
with self.ratelimit_queue_lock:
if project.backend not in self.ratelimit_queue:
self.ratelimit_queue[project.backend] = []
self.ratelimit_queue[project.backend].append(project.id)
with self.ratelimit_counter_lock:
self.ratelimit_counter += 1
示例3: test_local_to_utc
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
def test_local_to_utc(self):
arr = Arrow(datetime.now(), tz='local')
result = arr.to('UTC')
self.assert_dt_equal(result.datetime, datetime.utcnow())
self.assert_ts_equal(result.timestamp, time.time())
示例4: test_eq_utc_converstions
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
def test_eq_utc_converstions(self):
arr = Arrow(datetime(11, 1, 1))
utc_1 = arr.utc()
utc_2 = arr.to('UTC')
self.assertEqual(utc_1.datetime, utc_2.datetime)
self.assertEqual(utc_1, utc_2)
示例5: ArrowTests
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
class ArrowTests(BaseArrowTests):
def setUp(self):
super(ArrowTests, self).setUp()
self.arrow = Arrow(datetime.utcnow(), tz=tz.tzutc())
def test_str(self):
expected = '{0} UTC'.format(self.arrow._datetime.isoformat())
self.assertEqual(self.arrow.__str__(), expected)
def test_repr(self):
expected = '<Arrow({0} UTC)>'.format(self.arrow._datetime.isoformat())
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(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_parse_int(self):
dt, timezone = self.arrow._parse(int(time.time()), self.utc)
self.assert_dt_equal(dt, datetime.utcnow())
def test_parse_float_utc(self):
dt, timezone = self.arrow._parse(time.time(), self.utc)
self.assert_dt_equal(dt, datetime.utcnow())
def test_parse_float_local(self):
dt, timezone = self.arrow._parse(time.time(), self.local)
self.assert_dt_equal(dt, datetime.now())
def test_parse_str_float_utc(self):
dt, timezone = self.arrow._parse(str(time.time()), self.utc)
self.assert_dt_equal(dt, datetime.utcnow())
def test_parse_str_int_utc(self):
#.........这里部分代码省略.........
示例6: format_dt_iso_filter
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
def format_dt_iso_filter(dt: Arrow):
return dt.to('Europe/Prague').isoformat()
示例7: format_dt_filter
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import to [as 别名]
def format_dt_filter(dt: Arrow, fmt):
return dt.to('Europe/Prague').strftime(fmt)