1
>
/*---------------------------------------------------------------------------------------------
schedule.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IAutomationSchedule } from './automation.js';
7
>
import { localize } from '../../../../../nls.js';
8
>
9
>
export const DAYS_OF_WEEK: readonly string[] = [
10
>
localize('automation.day.sun', "Sunday"),
11
>
localize('automation.day.mon', "Monday"),
12
>
localize('automation.day.tue', "Tuesday"),
13
>
localize('automation.day.wed', "Wednesday"),
14
>
localize('automation.day.thu', "Thursday"),
15
>
localize('automation.day.fri', "Friday"),
16
>
localize('automation.day.sat', "Saturday"),
17
>
];
18
>
19
>
/**
20
>
* Computes the next fire time for a schedule. Daily/weekly times are
21
>
* local wall-clock (not UTC) so DST transitions don't shift them.
22
>
* Day advances use `Date` constructor overflow, not milliseconds, to
23
>
* avoid skipping spring-forward days. Returns `undefined` for `manual`.
24
>
*/
25
>
export function computeNextRunAt(schedule: IAutomationSchedule, now: Date): Date | undefined {
26
>
const { interval, scheduleHour, scheduleMinute, scheduleDay } = schedule;
27
>
28
>
switch (interval) {
29
>
case 'manual':
30
return undefined;
32
>
case 'hourly':
33
return new Date(now.getTime() + 60 * 60 * 1000);
35
>
case 'daily': {
36
if (!isValidHourMinute(scheduleHour, scheduleMinute)) {
37
return undefined;