"Current time" displayed under script/report schedule displays in wrong timezone #7451

Closed
opened 2025-12-29 20:23:36 +01:00 by adam · 1 comment
Owner

Originally created by @kkthxbye-code on GitHub (Jan 4, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.2

Python version

3.10

Steps to Reproduce

  1. Set TIME_ZONE to 'Europe/Copenhagen` in configuration.py
  2. Create any test script in the script folder
  3. Go to the script in the UI
  4. Look at the label for the Schedule at field

In this example the current local time is 14:30:10

Expected Behavior

Schedule execution of script to a set time (current time: 2023-01-04 14:30:10)

Observed Behavior

Schedule execution of script to a set time (current time: 2023-01-04 13:30:10)

>>> from django.utils import timezone
>>> timezone.now()
datetime.datetime(2023, 1, 4, 13, 36, 22, 379154, tzinfo=datetime.timezone.utc)

>>> from django.utils.timezone import localtime
>>> localtime(timezone.now())
datetime.datetime(2023, 1, 4, 14, 38, 18, 340191, tzinfo=zoneinfo.ZoneInfo(key='Europe/Copenhagen'))

92ec06c694/netbox/extras/forms/scripts.py (L36-L38)

92ec06c694/netbox/extras/forms/reports.py (L37-L39)

The above snippets should probably be replaced with the localtime way of getting the current time. @jeremystretch you added this, any issues with my proposed fix?

I validated the the script is scheduled at the correct set timezone and not the displayed "current time".

Originally created by @kkthxbye-code on GitHub (Jan 4, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.2 ### Python version 3.10 ### Steps to Reproduce 1. Set TIME_ZONE to 'Europe/Copenhagen` in configuration.py 2. Create any test script in the script folder 3. Go to the script in the UI 4. Look at the label for the `Schedule at` field In this example the current local time is `14:30:10` ### Expected Behavior Schedule execution of script to a set time (current time: 2023-01-04 14:30:10) ### Observed Behavior Schedule execution of script to a set time (current time: 2023-01-04 13:30:10) ``` >>> from django.utils import timezone >>> timezone.now() datetime.datetime(2023, 1, 4, 13, 36, 22, 379154, tzinfo=datetime.timezone.utc) >>> from django.utils.timezone import localtime >>> localtime(timezone.now()) datetime.datetime(2023, 1, 4, 14, 38, 18, 340191, tzinfo=zoneinfo.ZoneInfo(key='Europe/Copenhagen')) ``` https://github.com/netbox-community/netbox/blob/92ec06c6948f0b6f3c6192f4a1be57a505930ce4/netbox/extras/forms/scripts.py#L36-L38 https://github.com/netbox-community/netbox/blob/92ec06c6948f0b6f3c6192f4a1be57a505930ce4/netbox/extras/forms/reports.py#L37-L39 The above snippets should probably be replaced with the `localtime` way of getting the current time. @jeremystretch you added this, any issues with my proposed fix? I validated the the script is scheduled at the correct set timezone and not the displayed "current time".
adam added the type: bugstatus: accepted labels 2025-12-29 20:23:36 +01:00
adam closed this issue 2025-12-29 20:23:36 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 6, 2023):

You know, when I added the current time to the form field, my gut said "Don't do it man. You know how you are with time zones." And I said, "Shut up, I can do it. Just watch." And here we are. 😞

any issues with my proposed fix?

Not at all. But I wrote it, I'll fix it. Thanks for working through this.

@jeremystretch commented on GitHub (Jan 6, 2023): You know, when I added the current time to the form field, my gut said "Don't do it man. You know how you are with time zones." And I said, "Shut up, I can do it. Just watch." And here we are. :disappointed: > any issues with my proposed fix? Not at all. But I wrote it, I'll fix it. Thanks for working through this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7451