Skip to content

Commit

Permalink
pytz sample using only pytz (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte authored and anthony-tuininga committed Jan 4, 2020
1 parent 43d322c commit 8085266
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
1 change: 0 additions & 1 deletion cx_Freeze/samples/pytz/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cx-freeze
pytz
tzlocal

14 changes: 9 additions & 5 deletions cx_Freeze/samples/pytz/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# A setup script to demonstrate the use o pytz
'''A setup script to demonstrate build using pytz
This version requires the zoneinfo in the zip file
'''
#
# Run the build process by running the command 'python setup.py build'
#
Expand All @@ -7,9 +9,11 @@

from cx_Freeze import setup, Executable

setup(name='test_pytz',
version='0.1',
setup(name='test_pytz_zip',
version='0.2',
description='cx_Freeze script to test pytz',
executables=[Executable("test_pytz.py")],
options={'build_exe': {'zip_include_packages': ["*"],
'zip_exclude_packages': []}})
options={
'build_exe': {'zip_include_packages': ["*"],
'zip_exclude_packages': []}
})
28 changes: 28 additions & 0 deletions cx_Freeze/samples/pytz/setup2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'''A setup script to demonstrate build using pytz
This version requires the zoneinfo in the file system
'''
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the script without Python

import distutils
import sys
import os

from cx_Freeze import setup, Executable

dir_name = "exe.%s-%s.2" % \
(distutils.util.get_platform(), sys.version[0:3])
build_exe = os.path.join('build', dir_name)

setup(name='test_pytz',
version='0.2',
description='cx_Freeze script to test pytz',
executables=[Executable("test_pytz.py")],
options={
'build_exe': {'zip_include_packages': ["*"],
'zip_exclude_packages': ["pytz"],
'build_exe': build_exe}
})
22 changes: 11 additions & 11 deletions cx_Freeze/samples/pytz/test_pytz.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'''sample to show the datetime in RFC1123 (timezone is required)'''
from datetime import datetime
import datetime
import pytz
import tzlocal

RFC1123 = '%a, %d %b %Y %H:%M:%S %z'

try:
tz = tzlocal.get_localzone()
print('Using your local timezone:', tz.zone)
except pytz.exceptions.UnknownTimeZoneError as exc:
print('Detected your local timezone:', exc.args[0])
print("WARNING: fail to load pytz timezones, fallback to UTC")
tz = pytz.utc
finally:
print(datetime.now(tz).strftime(RFC1123))
utc_time = datetime.datetime.utcnow()
print('UTC time:', utc_time.strftime(RFC1123))

tz1 = pytz.timezone('America/Sao_Paulo')
brz_time = tz1.fromutc(utc_time)
print('Brazil time:', brz_time.strftime(RFC1123))

tz2 = pytz.timezone('US/Eastern')
eas_time = tz2.fromutc(utc_time)
print('US Eastern time:', eas_time.strftime(RFC1123))

0 comments on commit 8085266

Please sign in to comment.