Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Last active August 29, 2015 14:16
Show Gist options
  • Save PeterJCLaw/96a68c04d0772ccb1182 to your computer and use it in GitHub Desktop.
Save PeterJCLaw/96a68c04d0772ccb1182 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import datetime
from dateutil.tz import gettz, tzlocal
from freezegun import freeze_time
def show(timezone):
print('-'*20)
print("timezone:", timezone)
time = datetime.datetime.now()
print("no tz: ", time)
time = datetime.datetime.now(timezone)
print("with tz:", time)
def show_both():
# show(tzlocal())
show(gettz('Europe/London'))
import sys
print(sys.version_info)
TZ_OFFSET = 0
#if sys.version_info[0] == 3:
# TZ_OFFSET = 1
show_both()
with freeze_time('2014-04-26 12:01:00', tz_offset=TZ_OFFSET):
print('Freeze')
show_both()
sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)
--------------------
timezone: tzfile('/usr/share/zoneinfo/Europe/London')
no tz: 2015-03-01 02:47:05.823523
with tz: 2015-03-01 02:47:05.823535+00:00
Freeze
--------------------
timezone: tzfile('/usr/share/zoneinfo/Europe/London')
no tz: 2014-04-26 12:01:00
with tz: 2014-04-26 13:01:00+01:00
sys.version_info(major=3, minor=4, micro=0, releaselevel='final', serial=0)
--------------------
timezone: tzfile('/usr/share/zoneinfo/Europe/London')
no tz: 2015-03-01 02:47:06.915285
with tz: 2015-03-01 02:47:06.915304+00:00
Freeze
--------------------
timezone: tzfile('/usr/share/zoneinfo/Europe/London')
no tz: 2014-04-26 12:01:00
with tz: 2014-04-26 12:01:00+01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment