From 8c63a78884da5c53b7707713f7fe08be9778d659 Mon Sep 17 00:00:00 2001 From: Tzahi12345 Date: Tue, 3 Jan 2023 21:21:14 -0500 Subject: [PATCH] Added timezone information to tasks so that recurring tasks will use the timezone from the user --- Public API v1.yaml | 2 ++ backend/tasks.js | 2 +- src/api-types/models/Schedule.ts | 1 + src/app/components/tasks/tasks.component.html | 4 ++-- .../update-task-schedule-dialog.component.html | 1 + .../update-task-schedule-dialog.component.ts | 6 +++++- 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Public API v1.yaml b/Public API v1.yaml index 0418866..3e84cee 100644 --- a/Public API v1.yaml +++ b/Public API v1.yaml @@ -2589,6 +2589,8 @@ components: type: number timestamp: type: number + tz: + type: string DBBackup: required: - name diff --git a/backend/tasks.js b/backend/tasks.js index 427cdfd..4cd9795 100644 --- a/backend/tasks.js +++ b/backend/tasks.js @@ -52,7 +52,7 @@ function scheduleJob(task_key, schedule) { const dayOfWeek = schedule['data']['dayOfWeek'] != null ? schedule['data']['dayOfWeek'] : null; const hour = schedule['data']['hour'] != null ? schedule['data']['hour'] : null; const minute = schedule['data']['minute'] != null ? schedule['data']['minute'] : null; - converted_schedule = new scheduler.RecurrenceRule(null, null, null, dayOfWeek, hour, minute); + converted_schedule = new scheduler.RecurrenceRule(null, null, null, dayOfWeek, hour, minute, undefined, schedule['data']['tz'] ? schedule['data']['tz'] : undefined); } else { logger.error(`Failed to schedule job '${task_key}' as the type '${schedule['type']}' is invalid.`) return null; diff --git a/src/api-types/models/Schedule.ts b/src/api-types/models/Schedule.ts index 93206fe..a16fc5f 100644 --- a/src/api-types/models/Schedule.ts +++ b/src/api-types/models/Schedule.ts @@ -9,6 +9,7 @@ dayOfWeek?: Array; hour?: number; minute?: number; timestamp?: number; +tz?: string; }; }; diff --git a/src/app/components/tasks/tasks.component.html b/src/app/components/tasks/tasks.component.html index 4571f57..c320881 100644 --- a/src/app/components/tasks/tasks.component.html +++ b/src/app/components/tasks/tasks.component.html @@ -35,8 +35,8 @@ - Scheduled for  - {{element.next_invocation | date: 'short'}}repeat + Scheduled for + {{element.next_invocation | date: 'short'}}repeat Not scheduled diff --git a/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.html b/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.html index ee27b7c..adf2fdd 100644 --- a/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.html +++ b/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.html @@ -41,6 +41,7 @@ Time + {{Intl.DateTimeFormat().resolvedOptions().timeZone}} diff --git a/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts b/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts index 2d31782..befe4c2 100644 --- a/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts +++ b/src/app/dialogs/update-task-schedule-dialog/update-task-schedule-dialog.component.ts @@ -15,8 +15,9 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { days_of_week = []; interval = 'daily'; time = null; - date = null; + date: Date = null; today = new Date(); + Intl = Intl; constructor(@Inject(MAT_DIALOG_DATA) public data: {task: Task}, private dialogRef: MatDialogRef, private postsService: PostsService) { this.processTask(this.data.task); @@ -66,6 +67,8 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { if (!this.time) { // needs time! + this.postsService.openSnackBar($localize`You must input a time!`); + return; } const hours = parseInt(this.time.split(':')[0]); @@ -81,6 +84,7 @@ export class UpdateTaskScheduleDialogComponent implements OnInit { this.date.setHours(hours, minutes); schedule['data'] = {timestamp: this.date.getTime()}; } + schedule['data']['tz'] = this.Intl?.DateTimeFormat().resolvedOptions().timeZone; this.dialogRef.close(schedule); } }