* Derive a BCP 47 locale tag from POSIX env vars. * LC_ALL > LC_TIME > LANG, falls back to undefined (system default). * Converts POSIX format (en_GB.UTF-8) to BCP 47 (en-GB).
()
| 56 | * Converts POSIX format (en_GB.UTF-8) to BCP 47 (en-GB). |
| 57 | */ |
| 58 | function getLocale(): string | undefined { |
| 59 | const raw = |
| 60 | process.env.LC_ALL || process.env.LC_TIME || process.env.LANG || '' |
| 61 | if (!raw || raw === 'C' || raw === 'POSIX') { |
| 62 | return undefined |
| 63 | } |
| 64 | // Strip codeset (.UTF-8) and modifier (@euro), replace _ with - |
| 65 | const base = raw.split('.')[0]!.split('@')[0]! |
| 66 | if (!base) { |
| 67 | return undefined |
| 68 | } |
| 69 | const tag = base.replaceAll('_', '-') |
| 70 | // Validate by trying to construct an Intl locale — invalid tags throw |
| 71 | try { |
| 72 | new Intl.DateTimeFormat(tag) |
| 73 | return tag |
| 74 | } catch { |
| 75 | return undefined |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | function startOfDay(d: Date): number { |
| 80 | return new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime() |
no outgoing calls
no test coverage detected