Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytz sample using only pytz #555

Merged
merged 1 commit into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))