Date/Time formatting not working #9435

Closed
opened 2025-12-29 20:49:54 +01:00 by adam · 7 comments
Owner

Originally created by @julianstolp on GitHub (Apr 4, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0-beta1

Python Version

3.10

Steps to Reproduce

  1. Upgrade to v4.0-beta1
  2. Date and Time formatting defaults to Created 03/10/2022 1 a.m. or 04/04/2024 12:50 p.m. CEST
  3. Check config configuration.py
# Date/time formatting. See the following link for supported formats:
# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date
DATE_FORMAT = 'N j, Y'
SHORT_DATE_FORMAT = 'Y-m-d'
TIME_FORMAT = 'g:i a'
SHORT_TIME_FORMAT = 'H:i:s'
DATETIME_FORMAT = 'N j, Y g:i a'
SHORT_DATETIME_FORMAT = 'Y-m-d H:i'

Expected Behavior

Date and Time is formatted as defined in Config Created 2022-03-10 01:00 or 2024-04-04 13:34 CEST

Observed Behavior

Created 03/10/2022 1 a.m. or 04/04/2024 12:50 p.m. CEST are displayed also standard values defined in settings.py are not used.

Originally created by @julianstolp on GitHub (Apr 4, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0-beta1 ### Python Version 3.10 ### Steps to Reproduce 1. Upgrade to v4.0-beta1 2. Date and Time formatting defaults to ` Created 03/10/2022 1 a.m. ` or `04/04/2024 12:50 p.m. CEST` 3. Check config `configuration.py` ``` # Date/time formatting. See the following link for supported formats: # https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date DATE_FORMAT = 'N j, Y' SHORT_DATE_FORMAT = 'Y-m-d' TIME_FORMAT = 'g:i a' SHORT_TIME_FORMAT = 'H:i:s' DATETIME_FORMAT = 'N j, Y g:i a' SHORT_DATETIME_FORMAT = 'Y-m-d H:i' ``` ### Expected Behavior Date and Time is formatted as defined in Config `Created 2022-03-10 01:00 ` or `2024-04-04 13:34 CEST` ### Observed Behavior ` Created 03/10/2022 1 a.m. ` or `04/04/2024 12:50 p.m. CEST` are displayed also standard values defined in `settings.py` are not used.
adam added the type: bugstatus: acceptedbeta labels 2025-12-29 20:49:54 +01:00
adam closed this issue 2025-12-29 20:49:54 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 4, 2024):

Reminder: Please don't prefix your issue title with any sort of faux tag. Just indicate the affected NetBox version and the appropriate tag(s) will be assigned during triage.

@jeremystretch commented on GitHub (Apr 4, 2024): Reminder: Please don't prefix your issue title with any sort of faux tag. Just indicate the affected NetBox version and the appropriate tag(s) will be assigned during triage.
Author
Owner

@opericgithub commented on GitHub (Apr 4, 2024):

I believe you should additionally enable localization in configuration.py

ENABLE_LOCALIZATION = True

@opericgithub commented on GitHub (Apr 4, 2024): I believe you should additionally enable localization in configuration.py ENABLE_LOCALIZATION = True
Author
Owner

@julianstolp commented on GitHub (Apr 4, 2024):

I believe you should additionally enable localization in configuration.py

ENABLE_LOCALIZATION = True

I already added this option. Does it work for you?

@julianstolp commented on GitHub (Apr 4, 2024): > I believe you should additionally enable localization in configuration.py > > ENABLE_LOCALIZATION = True I already added this option. Does it work for you?
Author
Owner

@jeremystretch commented on GitHub (Apr 4, 2024):

From the Django 4.0 release notes:

In order to follow good practice, the default value of the USE_L10N setting is changed from False to True.

Moreover USE_L10N is deprecated as of this release. Starting with Django 5.0, by default, any date or number displayed by Django will be localized.

This was on our radar back when we moved to Django 4.0, but fell off more recently. As Django now effectively mandates the localization of dates and times, the configurable formats will be used only when the user's locale cannot be determined (AFAICT).

We should at least remove the USE_L10N ("use localization") variable from settings.py, but beyond that I'm not sure there's any other action to take.

@jeremystretch commented on GitHub (Apr 4, 2024): From the [Django 4.0 release notes](https://docs.djangoproject.com/en/5.0/releases/4.0/#localization): > In order to follow good practice, the default value of the `USE_L10N` setting is changed from False to True. > > Moreover `USE_L10N` is deprecated as of this release. Starting with Django 5.0, by default, any date or number displayed by Django will be localized. This was on our radar back when we moved to Django 4.0, but fell off more recently. As Django now effectively mandates the localization of dates and times, the configurable formats will be used only when the user's locale cannot be determined (AFAICT). We should at least remove the `USE_L10N` ("use localization") variable from `settings.py`, but beyond that I'm not sure there's any other action to take.
Author
Owner

@opericgithub commented on GitHub (Apr 4, 2024):

I already added this option. Does it work for you?

It works in 3.7.
Currently I'm unable to upgrade to 4.0 and check that.

Here is what we use in v3.7 with enabled localization, might help you:

DATE_FORMAT = 'd. F, Y.'
SHORT_DATE_FORMAT = 'd.m.Y.'
TIME_FORMAT = 'H:i'
SHORT_TIME_FORMAT = 'H:i:s'
DATETIME_FORMAT = 'd. F, Y. H:i'
SHORT_DATETIME_FORMAT = 'd.m.Y. H:i'

And here is what we use in v3.6:

DATE_FORMAT = 'N j, Y'
SHORT_DATE_FORMAT = 'Y-m-d'
TIME_FORMAT = 'g:i a'
SHORT_TIME_FORMAT = 'H:i:s'
DATETIME_FORMAT = 'N j, Y g:i a'
SHORT_DATETIME_FORMAT = 'Y-m-d H:i'

@opericgithub commented on GitHub (Apr 4, 2024): > I already added this option. Does it work for you? It works in 3.7. Currently I'm unable to upgrade to 4.0 and check that. Here is what we use in v3.7 with enabled localization, might help you: ``` DATE_FORMAT = 'd. F, Y.' SHORT_DATE_FORMAT = 'd.m.Y.' TIME_FORMAT = 'H:i' SHORT_TIME_FORMAT = 'H:i:s' DATETIME_FORMAT = 'd. F, Y. H:i' SHORT_DATETIME_FORMAT = 'd.m.Y. H:i' ``` And here is what we use in v3.6: ``` DATE_FORMAT = 'N j, Y' SHORT_DATE_FORMAT = 'Y-m-d' TIME_FORMAT = 'g:i a' SHORT_TIME_FORMAT = 'H:i:s' DATETIME_FORMAT = 'N j, Y g:i a' SHORT_DATETIME_FORMAT = 'Y-m-d H:i' ```
Author
Owner

@opericgithub commented on GitHub (Apr 8, 2024):

I already added this option. Does it work for you?

It works in 3.7. Currently I'm unable to upgrade to 4.0 and check that.

Here is what we use in v3.7 with enabled localization, might help you:

I was wrong, this time/date format actually doesn't work in our environment.
We were doing some tests with enabling/disabling localization, but we never made it work.

@opericgithub commented on GitHub (Apr 8, 2024): > > I already added this option. Does it work for you? > > It works in 3.7. Currently I'm unable to upgrade to 4.0 and check that. > > Here is what we use in v3.7 with enabled localization, might help you: I was wrong, this time/date format actually doesn't work in our environment. We were doing some tests with enabling/disabling localization, but we never made it work.
Author
Owner

@jeremystretch commented on GitHub (Apr 16, 2024):

As Django 5.0 now enforces the use of localized date & time formats by default, and as the consensus (per discussion in #15706) is that users generally prefer ISO 8601-formatted timestamps anyway, I've split this into three discrete pieces of work:

  1. [PR #19853] [CLOSED] Update un_locode.py (#15735)
  2. [PR #19856] [CLOSED] Fix 19633 interrupting event processing in the process_event_rules() function (#15736)
  3. [PR #19854] [CLOSED] Update un_locode.py (#15738)

Hopefully this clears up any lingering frustrations with date & time formatting in NetBox once and for all.

@jeremystretch commented on GitHub (Apr 16, 2024): As Django 5.0 now enforces the use of localized date & time formats by default, and as the consensus (per discussion in #15706) is that users generally prefer ISO 8601-formatted timestamps anyway, I've split this into three discrete pieces of work: 1. #15735 2. #15736 3. #15738 Hopefully this clears up any lingering frustrations with date & time formatting in NetBox once and for all.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9435