Skip to content

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

@kkthxbye-code

Description

@kkthxbye-code

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'))

# Annotate the current system time for reference
now = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
self.fields['_schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'

# Annotate the current system time for reference
now = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
self.fields['schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'

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".

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions