Django DateTimeUTC
django-datetime-utc provides DateTimeUTCField, a naive datetime model field. In PostgreSQL this translates to the field timestamp without time zone. All timestamps are saved in UTC.
Why use this?
The problem with using Django's DateTimeField is unless the default timezone on your (PostgreSQL) database server is set to UTC it doesn't matter which TZ settings you select in Django, PostgreSQL will save all timestamps in local time with an offset.
Features
- Supports the default
DateTimeFieldoptions such asauto_now_addandauto_now - Saves all timestamps in UTC
- Values automatically converted to local time (specified by
TIME_ZONEin your projectsettings.py) in forms and templates
Install
From PyPi:
pip install django-datetime-utc
In settings.py add datetimeutc to the list of installed apps, set your local time zone and ensure time zone support is enabled:
TIME_ZONE = 'Europe/London'
USE_TZ = True
INSTALLED_APPS = (
#...
'datetimeutc',
)
Usage
In models.py:
from django.db import models
from datetimeutc.fields import DateTimeUTCField
class Journey(models.Model):
name = models.CharField(max_length=100)
departure_time = DateTimeUTCField(null=True)
arrival_time = DateTimeUTCField(null=True)
record_created = DateTimeUTCField(auto_now_add=True)
Notes
If your code creates datetime objects, they should always be TZ aware so they are automatically converted correctly to UTC (if necessary) before being saved to the database.
Using the Journey model above as an example, to set departure_time correctly you would:
import datetime
from zoneinfo import ZoneInfo
departure_time = datetime.datetime.now(datetime.UTC)
# or user defined (naive) datetime objects
departure_time = user_datetime.replace(tzinfo=ZoneInfo(settings.TIME_ZONE))
Journey.objects.create(name='Flight to LA', departure_time=departure_time)
Metadata
Release files for django-datetime-utc 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_datetime_utc-1.0.6.tar.gz | 3.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_datetime_utc-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.0 kB
Release files / django_datetime_utc-1.0.6.tar.gz
| Download URL | django_datetime_utc-1.0.6.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88e6276619ef401220e4abf660e56e500d5cd27b261076d92addc54190435b13
|
|
BLAKE2b-256 checksum How to use checksums |
4b3e96c4d914c1739603e85334e44351cee47645806057876ebfa242d7488894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Release files / django_datetime_utc-1.0.6-py3-none-any.whl
| Download URL | django_datetime_utc-1.0.6-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59a3c5c33a483ef4d3a007da54f8bd5dc77f6366b74671710b6f2ad4aea39400
|
|
BLAKE2b-256 checksum How to use checksums |
f15971d527e8431100944db1f54809d06a97cfe95dca9974a1f046d8364f2aca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Security for django-datetime-utc 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.