Spaces:
Runtime error
Runtime error
Download apps/web/src/lib/dates.ts from ClaraSu/llm-router: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/web/src/lib/dates.ts
- Command line
-
hf download hf://spaces/ClaraSu/llm-router/apps/web/src/lib/dates.ts
-
curl -L -o dates.ts https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/web/src/lib/dates.ts
1.7 kB
| export function getCurrentMonth(): string { | |
| const now = new Date() | |
| return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}` | |
| } | |
| export function monthRange(month: string): { from: string; to: string } { | |
| const parts = month.split('-') | |
| const year = Number(parts[0]) | |
| const mon = Number(parts[1]) | |
| const from = `${year}-${String(mon).padStart(2, '0')}-01` | |
| const lastDay = new Date(year, mon, 0).getDate() | |
| const to = `${year}-${String(mon).padStart(2, '0')}-${String(lastDay).padStart(2, '0')}` | |
| return { from, to } | |
| } | |
| export function formatMonth(month: string): string { | |
| const parts = month.split('-') | |
| const year = Number(parts[0]) | |
| const mon = Number(parts[1]) | |
| return new Date(year, mon - 1, 1).toLocaleString('default', { month: 'long', year: 'numeric' }) | |
| } | |
| export function getLast12Months(): string[] { | |
| const months: string[] = [] | |
| const now = new Date() | |
| for (let i = 0; i < 12; i++) { | |
| const d = new Date(now.getFullYear(), now.getMonth() - i, 1) | |
| months.push(`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`) | |
| } | |
| return months | |
| } | |
| // Takes a YYYY-MM-DD date string and returns its full weekday name (e.g. | |
| // "Sunday"). A bare calendar date's weekday is a timezone-independent fact — | |
| // this avoids the classic new Date("2026-08-09") UTC-parse-vs-local-read | |
| // mismatch by constructing AND reading the Date in local time throughout, so | |
| // it can never disagree with itself no matter what timezone the browser is in. | |
| export function weekdayOf(dateStr: string): string { | |
| const [year, month, day] = dateStr.split('-').map(Number) | |
| return new Date(year!, month! - 1, day!).toLocaleDateString('en-US', { weekday: 'long' }) | |
| } | |