diff --git a/cx_Freeze/samples/pytz/requirements.txt b/cx_Freeze/samples/pytz/requirements.txt index b71feddca..47d6c16f5 100644 --- a/cx_Freeze/samples/pytz/requirements.txt +++ b/cx_Freeze/samples/pytz/requirements.txt @@ -1,4 +1,3 @@ cx-freeze pytz -tzlocal diff --git a/cx_Freeze/samples/pytz/setup.py b/cx_Freeze/samples/pytz/setup.py index 6cda78be9..c4b9187e9 100644 --- a/cx_Freeze/samples/pytz/setup.py +++ b/cx_Freeze/samples/pytz/setup.py @@ -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' # @@ -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': []} + }) diff --git a/cx_Freeze/samples/pytz/setup2.py b/cx_Freeze/samples/pytz/setup2.py new file mode 100644 index 000000000..14b4dca12 --- /dev/null +++ b/cx_Freeze/samples/pytz/setup2.py @@ -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} + }) diff --git a/cx_Freeze/samples/pytz/test_pytz.py b/cx_Freeze/samples/pytz/test_pytz.py index a2dc89cd2..2f1d2000d 100644 --- a/cx_Freeze/samples/pytz/test_pytz.py +++ b/cx_Freeze/samples/pytz/test_pytz.py @@ -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))