Skip to main content

django-date-extensions by Matthew Somerville

This code adds a few small extensions to Django’s DateField, to handle both approximate dates (e.g. “March 1963”) and default year dates (e.g. assume “24th June” is the most recent such).

example contains a hopefully self-contained Django project that simply shows off a form with these methods of entry.

Approximate dates

A new object, ApproximateDate, is used to represent dates that might not have a month or a day. ApproximateDateField is the model field used to represent these objects in a Model, and ApproximateDateFormField is the field used in a Django form. Everything should work seamlessly simply by specifying a model field as ApproximateDateField rather than DateField.

Default year dates

PrettyDateField is a form field to be used on DateField model fields. It takes one argument, future, which is a nullable boolean. If True, a date input that is missing a year will be taken to be the next possible occurrence of that date - e.g. on 24th November 2009, entering 24th December will be taken to be 2009-12-24, whilst entering 3rd March will be taken to be 2010-03-03. If future is False, the reverse occurs, with year-less dates being assumed to be the closest occurrence of that date in the past.

If future is not set, then PrettyDateField acts the same as a DateField, only allows suffixes on ordinals, and assumes D/M/Y rather than M/D/Y.

Testing

Run ‘tox’ with tox installed.

Todo

Improve date parsing to take more inputs like my traintimes.org.uk PHP, such as “next Friday”.

Any queries or comments, do get in touch. Something’s probably broken, as I tried to tidy up the code a little for public release :)

Matthew Somerville.

Metadata

Release files for django-date-extensions 3.1.2

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-date-extensions 3.1.2
File Size Uploaded
django_date_extensions-3.1.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-date-extensions 3.1.2
File Interpreter ABI Platform
django_date_extensions-3.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 28.5 kB

Release files / django_date_extensions-3.1.2.tar.gz

Download URL django_date_extensions-3.1.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a27d8d0e99453e1b1491584a9cbf5e26ff0a5b5bbc491a8e1d29ffa46c13e7af
BLAKE2b-256 checksum
How to use checksums
b34c6bc68a76a59a55f31790f328835b36408c8709b177a536fe9048f45f5fb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / django_date_extensions-3.1.2-py2.py3-none-any.whl

Download URL django_date_extensions-3.1.2-py2.py3-none-any.whl
Size 20.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4933e5d507ef656217a27eb20cd0e346ed3ceee6f7c8da61917b63c350b20878
BLAKE2b-256 checksum
How to use checksums
3866820af3b140cf449fc233bd929fe80fbb4a294219b047f16d325e24f327c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

3.1.2 This release

2 release files

3.1.1

2 release files

3.1

2 release files

3.0

2 release files

2.0

2 release files

1.1.0

2 release files

1.0.0

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