feat: default journal period to last 7 days
Frontend verify / commits (pull_request) Successful in 50s
Frontend verify / security (pull_request) Failing after 13s
Frontend verify / verify (pull_request) Skipped

This commit is contained in:
2026-10-06 22:05:41 +03:00
parent c25f6bd85b
commit 0ea8d7b62d
11 changed files with 121 additions and 34 deletions
+12 -1
View File
@@ -9,6 +9,9 @@ function isValidPeriod(from: null | string, to: null | string) {
);
}
const DAY_MS = 86_400_000;
const DEFAULT_PERIOD_DAYS = 6;
const moscowFormatter = new Intl.DateTimeFormat("en-CA", {
day: "2-digit",
month: "2-digit",
@@ -22,6 +25,14 @@ function compareDateDesc(a: null | string, b: null | string) {
return (b ?? "").localeCompare(a ?? "");
}
// Last 7 days including today. An empty period always means this range.
function defaultPeriod(): [string, string] {
const to = new Date();
const from = new Date(to.getTime() - DEFAULT_PERIOD_DAYS * DAY_MS);
return [moscowDate(from), moscowDate(to)];
}
function moscowDate(value: Date): string {
const parts = moscowFormatter.formatToParts(value);
@@ -31,4 +42,4 @@ function moscowDate(value: Date): string {
return `${part("year")}-${part("month")}-${part("day")}`;
}
export { compareDateDesc, isValidPeriod, moscowDate };
export { compareDateDesc, defaultPeriod, isValidPeriod, moscowDate };