Spaces:
Sleeping
Sleeping
Download frontend/src/utils/date.ts from fyliu/Flight-Search: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/fyliu/Flight-Search/resolve/main/frontend/src/utils/date.ts
- Command line
-
hf download hf://spaces/fyliu/Flight-Search/frontend/src/utils/date.ts
-
curl -L -o date.ts https://huggingface.co/spaces/fyliu/Flight-Search/resolve/main/frontend/src/utils/date.ts
1.32 kB
| /** When set, all "now" references use this fixed date instead of Date.now(). */ | |
| let _benchmarkDate: string | null = null; | |
| export function setBenchmarkDate(isoDate: string | null): void { | |
| _benchmarkDate = isoDate; | |
| } | |
| export function getNow(): Date { | |
| return _benchmarkDate ? new Date(_benchmarkDate + 'T00:00:00') : new Date(); | |
| } | |
| export function toDateString(d: Date): string { | |
| return d.toISOString().split('T')[0]; | |
| } | |
| export function addDays(d: Date, n: number): Date { | |
| const result = new Date(d); | |
| result.setDate(result.getDate() + n); | |
| return result; | |
| } | |
| export function getDefaultDepartureDate(): string { | |
| return toDateString(addDays(getNow(), 14)); | |
| } | |
| export function getDefaultReturnDate(): string { | |
| return toDateString(addDays(getNow(), 21)); | |
| } | |
| export function getMaxBookingDate(): string { | |
| const d = getNow(); | |
| d.setMonth(d.getMonth() + 12); | |
| return toDateString(d); | |
| } | |
| export function getDaysInMonth(year: number, month: number): number { | |
| return new Date(year, month, 0).getDate(); | |
| } | |
| export function getFirstDayOfMonth(year: number, month: number): number { | |
| return new Date(year, month - 1, 1).getDay(); | |
| } | |
| export function formatMonthYear(year: number, month: number): string { | |
| return new Date(year, month - 1).toLocaleDateString('en-US', { | |
| month: 'long', | |
| year: 'numeric', | |
| }); | |
| } | |