Consolidate scattered +330/+6mo date-window literals into shared dateWindow module

This commit is contained in:
2026-04-21 17:09:17 +03:00
parent ead18fc5e5
commit 4f840486b8
3 changed files with 10 additions and 22 deletions
+4 -6
View File
@@ -9,6 +9,8 @@
* Matches Angular `FlightsMapFiltersStateService` calendar behavior.
*/
import { mapWindowBounds } from "@/shared/dateWindow.js";
/** Today with time set to 00:00:00 local. */
export function today(): Date {
const d = new Date();
@@ -18,16 +20,12 @@ export function today(): Date {
/** minDate = today - 1 day (Angular parity). */
export function getMinDate(): Date {
const d = today();
d.setDate(d.getDate() - 1);
return d;
return mapWindowBounds()[0];
}
/** maxDate = today + 6 months (Angular parity). */
export function getMaxDate(): Date {
const d = today();
d.setMonth(d.getMonth() + 6);
return d;
return mapWindowBounds()[1];
}
/**
@@ -18,6 +18,7 @@ import { CityAutocomplete } from "@/ui/city-autocomplete/index.js";
import { useDictionaries } from "@/shared/dictionaries/index.js";
import { buildScheduleUrl } from "../url.js";
import type { ScheduleParams } from "../url.js";
import { scheduleWindowBounds } from "@/shared/dateWindow.js";
import "./ScheduleFilter.scss";
function minutesToTime(minutes: number): string {
@@ -74,17 +75,11 @@ function hhmmToMinutes(value: string | undefined, fallback: number): number {
// scheduleSearchTo (330 days forward). Keeps the schedule-filter calendar
// to the same range Angular uses via `settings.scheduleMinDate`/`Max`.
function getScheduleMinDate(): Date {
const d = new Date();
d.setHours(0, 0, 0, 0);
d.setDate(d.getDate() - 1);
return d;
return scheduleWindowBounds()[0];
}
function getScheduleMaxDate(): Date {
const d = new Date();
d.setHours(0, 0, 0, 0);
d.setDate(d.getDate() + 330);
return d;
return scheduleWindowBounds()[1];
}
export const ScheduleFilter: FC<ScheduleFilterProps> = ({
@@ -34,6 +34,7 @@ import {
} from "@/shared/dictionaries/index.js";
import type { IDictionaries } from "@/shared/dictionaries/index.js";
import { buildScheduleUrl } from "../url.js";
import { scheduleWindowBounds } from "@/shared/dateWindow.js";
import "./ScheduleStartPage.scss";
function toCityCode(code: string, dictionaries: IDictionaries | null): string {
@@ -64,17 +65,11 @@ function addDays(base: Date, days: number): Date {
// scheduleSearchTo (330 days forward). Constrains both the outbound and
// return-flight calendar pickers on the Schedule start page.
function getScheduleMinDate(): Date {
const d = new Date();
d.setHours(0, 0, 0, 0);
d.setDate(d.getDate() - 1);
return d;
return scheduleWindowBounds()[0];
}
function getScheduleMaxDate(): Date {
const d = new Date();
d.setHours(0, 0, 0, 0);
d.setDate(d.getDate() + 330);
return d;
return scheduleWindowBounds()[1];
}
/**