Fix scheduler date input and display (#1472)
Fixes #1255 ### Changes - Fixes incorrect time zone conversion when generating UTC schedule in workflow. - Fixes minute input display not prefixing single digits with `0` Co-authored-by: emma <hi@emma.cafe>
This commit is contained in:
parent
bf38063e0a
commit
896c3cc91c
@ -86,7 +86,8 @@ export class TimeInput extends LitElement {
|
|||||||
value=${this.hour}
|
value=${this.hour}
|
||||||
?disabled=${this.disabled}
|
?disabled=${this.disabled}
|
||||||
required
|
required
|
||||||
@keyup=${(e: KeyboardEvent) => {
|
@sl-change=${async (e: Event) => {
|
||||||
|
e.stopPropagation();
|
||||||
const input = e.target as SlInput;
|
const input = e.target as SlInput;
|
||||||
if (input.value) {
|
if (input.value) {
|
||||||
const int = +input.value.replace(/[^0-9]/g, "");
|
const int = +input.value.replace(/[^0-9]/g, "");
|
||||||
@ -94,10 +95,7 @@ export class TimeInput extends LitElement {
|
|||||||
} else {
|
} else {
|
||||||
input.value = "12";
|
input.value = "12";
|
||||||
}
|
}
|
||||||
}}
|
|
||||||
@sl-change=${async (e: Event) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
const input = e.target as SlInput;
|
|
||||||
await input.updateComplete;
|
await input.updateComplete;
|
||||||
this.hour = +input.value;
|
this.hour = +input.value;
|
||||||
this.dispatchChange();
|
this.dispatchChange();
|
||||||
@ -114,18 +112,19 @@ export class TimeInput extends LitElement {
|
|||||||
: this.minute}
|
: this.minute}
|
||||||
?disabled=${this.disabled}
|
?disabled=${this.disabled}
|
||||||
required
|
required
|
||||||
@keyup=${(e: KeyboardEvent) => {
|
|
||||||
const input = e.target as SlInput;
|
|
||||||
if (input.value) {
|
|
||||||
const int = +input.value.replace(/[^0-9]/g, "");
|
|
||||||
input.value = `${Math.min(59, Math.max(0, int))}`;
|
|
||||||
} else {
|
|
||||||
input.value = "00";
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
@sl-change=${async (e: Event) => {
|
@sl-change=${async (e: Event) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const input = e.target as SlInput;
|
const input = e.target as SlInput;
|
||||||
|
if (input.value) {
|
||||||
|
const int = Math.min(
|
||||||
|
59,
|
||||||
|
Math.max(0, +input.value.replace(/[^0-9]/g, ""))
|
||||||
|
);
|
||||||
|
input.value = int < 10 ? `0${int}` : `${int}`;
|
||||||
|
} else {
|
||||||
|
input.value = "00";
|
||||||
|
}
|
||||||
|
|
||||||
await input.updateComplete;
|
await input.updateComplete;
|
||||||
this.minute = +input.value;
|
this.minute = +input.value;
|
||||||
this.dispatchChange();
|
this.dispatchChange();
|
||||||
|
@ -1672,7 +1672,7 @@ https://archiveweb.page/images/${"logo.svg"}`}
|
|||||||
label=${msg("User Agent")}
|
label=${msg("User Agent")}
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder=${msg("Default")}
|
placeholder=${msg("Default")}
|
||||||
value=${this.formState.userAgent}
|
value=${this.formState.userAgent || ""}
|
||||||
>
|
>
|
||||||
</sl-input>
|
</sl-input>
|
||||||
`)}
|
`)}
|
||||||
|
@ -10,11 +10,9 @@ export type ScheduleInterval = "daily" | "weekly" | "monthly";
|
|||||||
/**
|
/**
|
||||||
* Parse interval from cron expression
|
* Parse interval from cron expression
|
||||||
**/
|
**/
|
||||||
export function getScheduleInterval(
|
export function getScheduleInterval(schedule: string): ScheduleInterval {
|
||||||
schedule: string
|
const [_minute, _hour, dayOfMonth, _month, dayOfWeek] = schedule.split(" ");
|
||||||
): "daily" | "weekly" | "monthly" {
|
if (dayOfMonth === "*") {
|
||||||
const [_minute, _hour, dayofMonth, _month, dayOfWeek] = schedule.split(" ");
|
|
||||||
if (dayofMonth === "*") {
|
|
||||||
if (dayOfWeek === "*") {
|
if (dayOfWeek === "*") {
|
||||||
return "daily";
|
return "daily";
|
||||||
}
|
}
|
||||||
@ -63,7 +61,7 @@ export function humanizeNextDate(
|
|||||||
export function humanizeSchedule(
|
export function humanizeSchedule(
|
||||||
schedule: string,
|
schedule: string,
|
||||||
options: { length?: "short" } = {},
|
options: { length?: "short" } = {},
|
||||||
numberFormatter: any = numberUtils.numberFormatter
|
numberFormatter = numberUtils.numberFormatter
|
||||||
): string {
|
): string {
|
||||||
const interval = getScheduleInterval(schedule);
|
const interval = getScheduleInterval(schedule);
|
||||||
const parsed = parseCron(schedule);
|
const parsed = parseCron(schedule);
|
||||||
@ -77,7 +75,7 @@ export function humanizeSchedule(
|
|||||||
weekday: "long",
|
weekday: "long",
|
||||||
});
|
});
|
||||||
|
|
||||||
let intervalMsg: any = "";
|
let intervalMsg = "";
|
||||||
|
|
||||||
if (options.length === "short") {
|
if (options.length === "short") {
|
||||||
switch (interval) {
|
switch (interval) {
|
||||||
@ -123,7 +121,7 @@ export function humanizeSchedule(
|
|||||||
break;
|
break;
|
||||||
case "monthly":
|
case "monthly":
|
||||||
intervalMsg = msg(
|
intervalMsg = msg(
|
||||||
str`On day ${days[0]} of the month at ${formattedTime}`
|
str`On day ${nextDate.getDate()} of the month at ${formattedTime}`
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -168,9 +166,15 @@ export function getUTCSchedule({
|
|||||||
|
|
||||||
localDate.setHours(+hour + periodOffset);
|
localDate.setHours(+hour + periodOffset);
|
||||||
localDate.setMinutes(+minute);
|
localDate.setMinutes(+minute);
|
||||||
const date =
|
|
||||||
interval === "monthly" ? dayOfMonth || localDate.getUTCDate() : "*";
|
if (interval === "monthly" && dayOfMonth) {
|
||||||
const day = interval === "weekly" ? dayOfWeek || localDate.getUTCDay() : "*";
|
localDate.setDate(dayOfMonth);
|
||||||
|
} else if (interval == "weekly" && dayOfWeek) {
|
||||||
|
localDate.setDate(localDate.getDate() + dayOfWeek - localDate.getDay());
|
||||||
|
}
|
||||||
|
|
||||||
|
const date = interval === "monthly" ? localDate.getUTCDate() : "*";
|
||||||
|
const day = interval === "weekly" ? localDate.getUTCDay() : "*";
|
||||||
const month = "*";
|
const month = "*";
|
||||||
|
|
||||||
const schedule = `${localDate.getUTCMinutes()} ${localDate.getUTCHours()} ${date} ${month} ${day}`;
|
const schedule = `${localDate.getUTCMinutes()} ${localDate.getUTCHours()} ${date} ${month} ${day}`;
|
||||||
|
Loading…
Reference in New Issue
Block a user