Skip to content

Not correct showing datetime in UI for task-type OnceTaskType "Run once:" #280

Closed
@dmitriev-e

Description

@dmitriev-e

Describe the bug
OnceTaskType shows in Admin UI in the field "Schedule" raw datetime from Database
But in my case - my timezone is UTC+3
My Database store datetime in UTC timezone

So, it means that for task at 23:00 in the filed "Schedule" I see "20:00", cause this time is stored in DB.

To Reproduce
Steps to reproduce the behavior:

  1. Be sure, that you have different timezones: in the Django, and stored Datetime in Database.
  2. Create a task with type OnceTaskType
  3. Go to page /scheduler/task/ in admin UI
  4. Check Datetime for Run once in Column "Schedule"
  5. If you have differences between system timezone and stored datetime in DB

Expected behavior
I would like to see true datetime in my timezone and my configured Datetime format

Desktop (please complete the following information):

  • OS: Windows
  • python 3.12.3
  • django version 5.1.8

Additional context
My suggestion is to change file
scheduler/admin/task_admin.py

function
def task_schedule(self, o: Task):

Line 123

from django.utils import timezone, formats
...

        if o.task_type == TaskType.ONCE.value:

            local_time = timezone.localtime(o.scheduled_time)  #<----

            return f"Run once: {formats.date_format(local_time, "DATETIME_FORMAT")}"  #<----

        elif o.task_type == TaskType.CRON.value:
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions