refactor: centralize domain values and enforce numeric lint
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
const MOSCOW_UTC_OFFSET_HOURS = 3;
|
||||
const MOSCOW_DAY_END_UTC = {
|
||||
hours: 20,
|
||||
minutes: 59,
|
||||
seconds: 59,
|
||||
milliseconds: 999,
|
||||
};
|
||||
export type DateOnlyRange = { from: string; to: string };
|
||||
const moscow = 'Europe/Moscow';
|
||||
export function moscowDate(value: Date): string {
|
||||
@@ -14,9 +21,21 @@ export function moscowDate(value: Date): string {
|
||||
export function dateOnlyBounds(range: DateOnlyRange): { from: Date; to: Date } {
|
||||
const from = dateParts(range.from);
|
||||
const end = dateParts(range.to);
|
||||
const to = new Date(Date.UTC(end[0], end[1] - 1, end[2], 20, 59, 59, 999));
|
||||
const to = new Date(
|
||||
Date.UTC(
|
||||
end[0],
|
||||
end[1] - 1,
|
||||
end[2],
|
||||
MOSCOW_DAY_END_UTC.hours,
|
||||
MOSCOW_DAY_END_UTC.minutes,
|
||||
MOSCOW_DAY_END_UTC.seconds,
|
||||
MOSCOW_DAY_END_UTC.milliseconds,
|
||||
),
|
||||
);
|
||||
return {
|
||||
from: new Date(Date.UTC(from[0], from[1] - 1, from[2], -3)),
|
||||
from: new Date(
|
||||
Date.UTC(from[0], from[1] - 1, from[2], -MOSCOW_UTC_OFFSET_HOURS),
|
||||
),
|
||||
to: to > new Date() ? new Date() : to,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user