本文整理汇总了Python中pytz.utc.localize方法的典型用法代码示例。如果您正苦于以下问题:Python utc.localize方法的具体用法?Python utc.localize怎么用?Python utc.localize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytz.utc
的用法示例。
在下文中一共展示了utc.localize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_at
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_at(self):
now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 11, 59, 59)))
self.assertListEqual(
[(t.slug, t.start) for t in list(now)],
[('the-best-wine', utc.localize(datetime.datetime(2015, 1, 6, 11, 0, 0)))])
now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))
self.assertListEqual(
[(t.slug, t.start) for t in list(now)],
[('local-gossips', utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))])
now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 12, 59, 59)))
self.assertListEqual(
[(t.slug, t.start) for t in list(now)],
[('local-gossips', utc.localize(datetime.datetime(2015, 1, 6, 12, 0, 0)))])
now = Transmission.at(utc.localize(datetime.datetime(2015, 1, 6, 13, 0, 0)))
self.assertListEqual(list(now), [])
示例2: setUp
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def setUp(self):
self.manager = CalendarManager()
programme = Programme.objects.filter(name="Classic hits").get()
programme.name = "Classic hits - ScheduleUtilsTests"
programme.slug = None
programme.id = programme.pk = None
programme.save()
self.programme = programme
Schedule.objects.get_or_create(
programme=programme,
type='L',
calendar=self.calendar,
recurrences=recurrence.Recurrence(rrules=[recurrence.Rule(recurrence.DAILY)]),
start_dt=pytz.utc.localize(datetime.datetime(2015, 1, 1, 14, 0, 0)))
for number in range(1, 11):
Episode.objects.create(
title='Episode %s' % number,
programme=programme,
summary='',
season=1,
number_in_season=number,
)
programme.rearrange_episodes(pytz.utc.localize(datetime.datetime(1970, 1, 1)), Calendar.get_active())
示例3: test_rearrange_only_non_emited_episodes
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_rearrange_only_non_emited_episodes(self):
Schedule.objects.create(
programme=self.programme,
calendar=Calendar.objects.create(),
type="L",
start_dt=utc.localize(datetime.datetime(2015, 1, 3, 16, 0, 0)),
recurrences=recurrence.Recurrence(
rrules=[recurrence.Rule(
recurrence.WEEKLY, until=utc.localize(datetime.datetime(2015, 1, 31, 16, 0, 0)))]))
# save should call rearrange
self.assertListEqual(
[e.issue_date for e in self.programme.episode_set.all().order_by('issue_date')[:5]],
[
utc.localize(datetime.datetime(2015, 1, 1, 14, 0)),
utc.localize(datetime.datetime(2015, 1, 2, 14, 0)),
utc.localize(datetime.datetime(2015, 1, 3, 14, 0)),
utc.localize(datetime.datetime(2015, 1, 4, 14, 0)),
utc.localize(datetime.datetime(2015, 1, 5, 14, 0)),
]
)
示例4: make_aware
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def make_aware(naive_datetime, timezone_name):
# naive means: tzinfo is None
try:
tz = timezone(timezone_name)
aware_datetime = naive_datetime.replace(tzinfo=tz)
aware_datetime_in_utc = aware_datetime.astimezone(utc)
naive_datetime_as_utc_converted_to_tz = tz.localize(naive_datetime)
except UnknownTimeZoneError:
# ... handle the error ..
pass
# Getting a location's time zone offset from UTC in minutes:
# adapted solution from https://github.com/communikein and `phineas-pta <https://github.com/phineas-pta>`__
示例5: test_retrieve_statement
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_retrieve_statement(self):
id_str = str(uuid.uuid4())
statement = Statement(
actor=self.agent,
verb=self.verb,
object=self.activity,
context=self.context,
result=self.result,
id=id_str,
version=Version.latest,
timestamp=utc.localize(datetime.utcnow())
)
save_resp = self.lrs.save_statement(statement)
self.assertTrue(save_resp.success)
response = self.lrs.retrieve_statement(save_resp.content.id)
self.assertIsInstance(response, LRSResponse)
self.assertTrue(response.success)
self._vars_verifier(response.content, statement, ['_authority', '_stored'])
示例6: test_retrieve_statement_no_microsecond
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_retrieve_statement_no_microsecond(self):
id_str = str(uuid.uuid4())
dt = utc.localize(datetime.utcnow())
statement = Statement(
actor=self.agent,
verb=self.verb,
object=self.activity,
context=self.context,
result=self.result,
id=id_str,
version=Version.latest,
timestamp=dt
)
save_resp = self.lrs.save_statement(statement)
self.assertTrue(save_resp.success)
response = self.lrs.retrieve_statement(save_resp.content.id)
self.assertIsInstance(response, LRSResponse)
self.assertTrue(response.success)
self._vars_verifier(response.content, statement, ['_authority', '_stored'])
示例7: check_results
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def check_results(self, holiday, start, end, expected):
assert list(holiday.dates(start, end)) == expected
# Verify that timezone info is preserved.
assert (list(holiday.dates(utc.localize(Timestamp(start)),
utc.localize(Timestamp(end)))) ==
[utc.localize(dt) for dt in expected])
示例8: localize_date
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def localize_date(self, date):
if not date.tzinfo:
date = utc.localize(date)
return date.astimezone(PST_TIMEZONE)
示例9: config_logger
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def config_logger(path):
def custom_time(*args):
utc_dt = utc.localize(datetime.utcnow())
my_tz = timezone("Asia/Shanghai")
converted = utc_dt.astimezone(my_tz)
return converted.timetuple()
logging.basicConfig()
logging.getLogger().handlers.pop()
fmt = '%(asctime)s %(message)s'
date_fmt = '%m-%d %H:%M:%S'
formatter = logging.Formatter(fmt=fmt, datefmt=date_fmt)
formatter.converter = custom_time
logging.getLogger().setLevel(logging.INFO)
log_file_save_name = path
file_handler = logging.FileHandler(filename=log_file_save_name, mode='w')
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
logging.getLogger().addHandler(file_handler)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
console.setFormatter(formatter)
logging.getLogger().addHandler(console)
示例10: mock_now
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def mock_now(dt=pytz.utc.localize(datetime.datetime(2014, 1, 1, 13, 30, 0))):
return dt
示例11: test_start
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_start(self):
self.assertEqual(
self.schedule.start_dt, utc.localize(datetime.datetime(2014, 1, 6, 14, 0, 0)))
示例12: test_start_lt_calendar
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_start_lt_calendar(self):
self.programme.start_date = datetime.date(2014, 1, 14)
self.programme.save()
self.schedule.refresh_from_db()
self.assertEqual(
self.schedule.effective_start_dt, utc.localize(datetime.datetime(2014, 1, 20, 14, 0, 0)))
示例13: test_end_gt_calendar
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_end_gt_calendar(self):
self.programme.end_date = datetime.date(2014, 1, 14)
self.programme.save()
self.schedule.refresh_from_db()
self.assertEqual(
self.schedule.effective_end_dt,
utc.localize(datetime.datetime(2014, 1, 13, 15, 0, 0)) # last date including runtime duration
)
示例14: test_date_after
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_date_after(self):
self.assertEqual(
self.schedule.date_after(utc.localize(datetime.datetime(2014, 1, 14))),
utc.localize(datetime.datetime(2014, 1, 20, 14, 0)))
示例15: test_date_after_exclude
# 需要导入模块: from pytz import utc [as 别名]
# 或者: from pytz.utc import localize [as 别名]
def test_date_after_exclude(self):
self.assertEqual(
self.schedule.date_after(utc.localize(datetime.datetime(2014, 1, 6, 14, 0, 0, 1))),
utc.localize(datetime.datetime(2014, 1, 13, 14, 0)))