Package: django-timezone-utils
django-timezone-utilsadds automatic time zone conversions and support
utilities to Django.Suggestions, constructive criticism, and feedback are certainly
welcomed and appreciated.DocumentationDocumentation for django-timezone-utils is available atRead the Docs.InspirationOn multiple occasions, I have had the need to store time zone information to the
one model, then base another model’s datetime on that time zone. If you have
ever had to deal with this, you will know how complicated this can be.I created these fields to ease the process of manipulating times based on
another field’s or models timezone choice. Instead of having to remember to useModel.clean, we can now create the models with the validation built
into the model field.Quick Examplefromdatetimeimportdatetimefromtimezone_utils.fieldsimportLinkedTZDateTimeField,TimeZoneFieldfromtimezone_utils.choicesimportPRETTY_ALL_TIMEZONES_CHOICESclassLocation(models.Model):# ...timezone=TimeZoneField(choices=PRETTY_ALL_TIMEZONES_CHOICES)defget_location_timezone(obj):"""Returns the Location.timezone field from above"""returnobj.location.timezoneclassLocationReport(models.Model):# ...location=models.ForeignKey('app_label.Location',related_name='reports')# Populates from the Location.timezonetimestamp=LinkedTZDateTimeField(populate_from=get_location_timezone)classLocationPeriod(models.Model):# ...location=models.ForeignKey('app_label.Location',related_name='periods')# Sets the time to 12:00am in the location.timezonestart=LinkedTZDateTimeField(populate_from=get_location_timezone,time_override=datetime.min.time())# Sets the time to 11:59:59.99999pm in the location.timezoneend=LinkedTZDateTimeField(populate_from=get_location_timezone,time_override=datetime.max.time())ContributorsMichael BarrKosei KitaharaAlex KamedovPi DelportChangelog0.15.0 Add support for Django 4.0. Drop support for Django 1.11.0.14.0 Add support for Django 2.2, 3.0. Drop support for Django 2.0, 2.1.0.13 Fixed error for Python 3 on PyPi.0.12 Add support for Django 2.1. Support Python 3.7. Drop support for Django 1.8.0.11 Removed reference to django.db.models.fields.subclassing.SubfieldBase, which means that only Django 1.8+ is now supported. Removed support for Python versions < 2.6. The Django 1.6 series was the last to support Python 2.6. Added testing support for Django 1.10. Changed development status from Beta to Production/Stable.0.10 Added testing support for Python 3.5 and Django 1.9.0.9 Corrected a bug to wheretime_overridecaused invalid date due to not converting to the correct timezone first. Refactored conversion code. Added testing support for Django 1.8. Removed Django from setup requirements - the onus of having a supported version of Django is on the developer.0.8 Corrected a bug to wheretime_overridecaused invalid date due to not converting to the correct timezone first. Added choicesGROUPED_ALL_TIMEZONES_CHOICESandGROUPED_COMMON_TIMEZONES_CHOICESto the documentation.0.7 Corrected a bug where datetime.max.time() resulted in incorrect date/time. Changed tests to compare time_override models via string to prevent future regressions. Added choicesGROUPED_ALL_TIMEZONES_CHOICESandGROUPED_COMMON_TIMEZONES_CHOICES.0.6 Added RTD documentation. LinkedTZDateTimeField now returns the datetime object in the overidden timezone and time.0.5 Bug fix: time override on datetime.min.time() failed to set time properly0.4 Removed support for Python 2.50.3 Code cleanup.0.2 Multiple bug fixes based on testing.0.1 Initial release.