mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
fix: cron per local time for utc.
This commit is contained in:
+9
-3
@@ -5,7 +5,6 @@
|
||||
FormList,
|
||||
InputRadio,
|
||||
InputSelect,
|
||||
InputSelectCheckbox,
|
||||
InputText,
|
||||
InputTime,
|
||||
Label
|
||||
@@ -59,7 +58,14 @@
|
||||
let backupFrequency: string = 'end';
|
||||
|
||||
const generateCronExpression = () => {
|
||||
const [hour, minute] = selectedTime.split(':');
|
||||
const [localHour, localMinute] = selectedTime.split(':');
|
||||
|
||||
// Convert local time to UTC
|
||||
const now = new Date();
|
||||
now.setHours(parseInt(localHour), parseInt(localMinute), 0);
|
||||
|
||||
const utcHour = now.getUTCHours();
|
||||
const utcMinute = now.getUTCMinutes();
|
||||
|
||||
let dayOfWeek = '*';
|
||||
let dayOfMonth = '*';
|
||||
@@ -77,7 +83,7 @@
|
||||
return `${new Date().getMinutes()} * * * *`;
|
||||
}
|
||||
|
||||
return `${minute} ${hour} ${dayOfMonth} * ${dayOfWeek}`;
|
||||
return `${utcMinute} ${utcHour} ${dayOfMonth} * ${dayOfWeek}`;
|
||||
};
|
||||
|
||||
// TODO: reset values on modal close.
|
||||
|
||||
+10
-3
@@ -55,7 +55,7 @@
|
||||
return `Retained for ${retention} day${retention > 1 ? 's' : ''}`;
|
||||
};
|
||||
|
||||
function getPolicyDescription(cron: string): string {
|
||||
const getPolicyDescription = (cron: string): string => {
|
||||
const cronParts = cron.split(' ');
|
||||
|
||||
// A standard cron has 5 parts: minute, hour, day of month, month, day of week
|
||||
@@ -88,7 +88,14 @@
|
||||
) {
|
||||
return 'Runs daily';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Switches to UTC for non-hourly,
|
||||
// keeps local time for hourly schedules.
|
||||
const isHourlySchedule = (cron: string): boolean => {
|
||||
const [_, hour, dayOfMonth, month, dayOfWeek] = cron.split(' ');
|
||||
return hour === '*' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*';
|
||||
};
|
||||
</script>
|
||||
|
||||
<Card
|
||||
@@ -167,7 +174,7 @@
|
||||
<div
|
||||
class="u-flex u-gap-4 u-cross-center policy-item-subtitles darker-neutral-color">
|
||||
{toLocaleDateTime(
|
||||
parseExpression(policy.schedule, { utc: false }).next().toString()
|
||||
parseExpression(policy.schedule, { utc: !isHourlySchedule(policy.schedule) }).next().toString()
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user