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