From c9c4570594d102a62c70863ec130b03aa6fdbe07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Rol=C3=B3n?= <37310205+Angatupyry@users.noreply.github.com> Date: Fri, 6 Oct 2023 14:43:33 -0300 Subject: [PATCH] Fix - schedule single event (#791) * Fix editing single event setting the correct date Signed-off-by: angatupyry * Add toIsoFormat Signed-off-by: angatupyry * format date to isoFormat Signed-off-by: angatupyry * Format to isoFormat Signed-off-by: angatupyry * Revert to exceptDateref insted of the schedule request time Signed-off-by: angatupyry --------- Signed-off-by: angatupyry --- .../api_server/routes/tasks/scheduled_tasks.py | 18 ++++++------------ .../components/tasks/task-schedule-utils.ts | 4 +++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/api-server/api_server/routes/tasks/scheduled_tasks.py b/packages/api-server/api_server/routes/tasks/scheduled_tasks.py index 874618bd1..992e8f9da 100644 --- a/packages/api-server/api_server/routes/tasks/scheduled_tasks.py +++ b/packages/api-server/api_server/routes/tasks/scheduled_tasks.py @@ -26,15 +26,6 @@ class PostScheduledTaskRequest(BaseModel): schedules: list[ttm.ScheduledTaskSchedulePydantic] -def datetime_to_date_format(date: datetime) -> str: - # input 09/08/2023 - formatted_date = date.date().strftime("%m/%d/%Y").lstrip("0") - parts = formatted_date.split("/") - parts[1] = parts[1].lstrip("0") - # output 9/8/2023 - return "/".join(parts) - - async def schedule_task(task: ttm.ScheduledTask, task_repo: TaskRepository): await task.fetch_related("schedules") jobs: list[tuple[ttm.ScheduledTaskSchedule, schedule.Job]] = [] @@ -59,7 +50,8 @@ async def run(): def do(): logger.info(f"starting task {task.pk}") - if datetime_to_date_format(datetime.now()) in task.except_dates: + datetime_to_iso = datetime.now().isoformat() + if datetime_to_iso[:10] in task.except_dates: return asyncio.get_event_loop().create_task(run()) @@ -151,7 +143,8 @@ async def del_scheduled_tasks_event( if task is None: raise HTTPException(404) - task.except_dates.append(datetime_to_date_format(event_date)) + event_date_str = event_date.isoformat() + task.except_dates.append(event_date_str[:10]) await task.save() for sche in task.schedules: @@ -181,7 +174,8 @@ async def update_schedule_task( async with tortoise.transactions.in_transaction(): if except_date: - task.except_dates.append(datetime_to_date_format(except_date)) + event_date_str = except_date.isoformat() + task.except_dates.append(event_date_str[:10]) await task.save() for sche in task.schedules: diff --git a/packages/dashboard/src/components/tasks/task-schedule-utils.ts b/packages/dashboard/src/components/tasks/task-schedule-utils.ts index 9f3f0c867..209280ce4 100644 --- a/packages/dashboard/src/components/tasks/task-schedule-utils.ts +++ b/packages/dashboard/src/components/tasks/task-schedule-utils.ts @@ -101,7 +101,9 @@ export const scheduleToEvents = ( (scheStartFrom == null || scheStartFrom <= cur) && (scheUntil == null || scheUntil >= cur) ) { - if (!task.except_dates.includes(cur.toLocaleDateString())) { + const curToIso = cur.toISOString(); + const curFormatted = `${curToIso.slice(0, 10)}`; + if (!task.except_dates.includes(curFormatted)) { events.push({ start: cur, end: addMinutes(cur, 45),