feat: default journal period to last 7 days
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user