Skip to main content
Latest Version Test Status Coverage Status Code Health Supported Python versions License Development Status

django-timezone-utils adds automatic time zone conversions and support utilities to Django.

Suggestions, constructive criticism, and feedback are certainly welcomed and appreciated.

Documentation

Documentation for django-timezone-utils is available at Read the Docs.

Inspiration

On 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 use Model.clean, we can now create the models with the validation built into the model field.

Quick Example

from datetime import datetime
from timezone_utils.fields import LinkedTZDateTimeField, TimeZoneField
from timezone_utils.choices import PRETTY_ALL_TIMEZONES_CHOICES

class Location(models.Model):
    # ...
    timezone = TimeZoneField(choices=PRETTY_ALL_TIMEZONES_CHOICES)


def get_location_timezone(obj):
    """Returns the Location.timezone field from above"""

    return obj.location.timezone


class LocationReport(models.Model):
    # ...
    location = models.ForeignKey('app_label.Location', related_name='reports')

    # Populates from the Location.timezone
    timestamp = LinkedTZDateTimeField(populate_from=get_location_timezone)


class LocationPeriod(models.Model):
    # ...
    location = models.ForeignKey('app_label.Location', related_name='periods')

    # Sets the time to 12:00am in the location.timezone
    start = LinkedTZDateTimeField(
        populate_from=get_location_timezone,
        time_override=datetime.min.time()
    )

    # Sets the time to 11:59:59.99999pm in the location.timezone
    end = LinkedTZDateTimeField(
        populate_from=get_location_timezone,
        time_override=datetime.max.time()
    )

Contributors

Changelog

  • 0.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 where time_override caused 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 where time_override caused invalid date due to not converting to the correct timezone first. Added choices GROUPED_ALL_TIMEZONES_CHOICES and GROUPED_COMMON_TIMEZONES_CHOICES to 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 choices GROUPED_ALL_TIMEZONES_CHOICES and GROUPED_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 properly

  • 0.4 Removed support for Python 2.5

  • 0.3 Code cleanup.

  • 0.2 Multiple bug fixes based on testing.

  • 0.1 Initial release.

Release files for django-timezone-utils 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-timezone-utils 0.15.0
File Size Uploaded
django-timezone-utils-0.15.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-timezone-utils 0.15.0
File Interpreter ABI Platform
django_timezone_utils-0.15.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 18.5 kB

Release files / django-timezone-utils-0.15.0.tar.gz

Download URL django-timezone-utils-0.15.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ce1ab713e80710d53a8f3860411b0e5c15f227667e56d118a4d7118f30a7e617
BLAKE2b-256 checksum
How to use checksums
9e26494cbba00e778e53be9d4a39c4618d27f0aa6ad1034363e684d7609c6614
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release files / django_timezone_utils-0.15.0-py2.py3-none-any.whl

Download URL django_timezone_utils-0.15.0-py2.py3-none-any.whl
Size 9.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f07cd32ec82406c8fc7a36cbcc9355e8109f2a54342754edd14f22f591653e44
BLAKE2b-256 checksum
How to use checksums
62e8eb4b928d3340218e6127ba65a996b8eb9603ac9f920710f7e80a6e303b89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.15.0 This release

2 release files

0.13

4 release files

0.11

1 release file

0.10

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page