fix(app): grant expiry ends the chosen day in Paris; species order 0..9999 (V1-2.5 L2)
Owner checkpoint 2026-11-02: expiry 23:59:59.999 Europe/Paris (picker, validation, display), tests under non-Paris zones and DST days; M7 redefines create_species and update_inactive_species with the range check; pgTAP 015 and 022; « Relecteur ou relectrice »; object_conflict EN; setup key selectable, no Copy.
This commit is contained in:
1 parent
4111efa1d1
commit
51225cacf6
17 files changed
+437
-61
No files matched your search
@@ -11,6 +11,74 @@ export function localDateIso(date: Date = new Date()): string {
|
||||
return `${date.getFullYear()}-${month}-${day}`
|
||||
}
|
||||
|
||||
/** The zone of the French perimeter: grant expiries are days there (owner 2026-11-02). */
|
||||
export const PARIS_TIME_ZONE = 'Europe/Paris'
|
||||
|
||||
const PARIS_PARTS = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: PARIS_TIME_ZONE,
|
||||
year: 'numeric',
|
||||
month: 'numeric',
|
||||
day: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
second: 'numeric',
|
||||
hourCycle: 'h23',
|
||||
})
|
||||
|
||||
/** The Paris wall clock at an instant, as numbers (month 1-12). */
|
||||
function parisParts(instant: number) {
|
||||
const parts: Record<string, number> = {}
|
||||
for (const part of PARIS_PARTS.formatToParts(instant))
|
||||
if (part.type !== 'literal') parts[part.type] = Number(part.value)
|
||||
return parts
|
||||
}
|
||||
|
||||
function isoDay(year: number, month: number, day: number): string {
|
||||
const pad = (n: number, width: number) => String(n).padStart(width, '0')
|
||||
return `${pad(year, 4)}-${pad(month, 2)}-${pad(day, 2)}`
|
||||
}
|
||||
|
||||
/** The date in Paris as YYYY-MM-DD, whatever the device zone. */
|
||||
export function parisDateIso(date: Date = new Date()): string {
|
||||
const p = parisParts(date.getTime())
|
||||
return isoDay(p.year, p.month, p.day)
|
||||
}
|
||||
|
||||
/** The calendar day after the Paris date (day arithmetic, never + 24 h). */
|
||||
export function parisTomorrowIso(date: Date = new Date()): string {
|
||||
const p = parisParts(date.getTime())
|
||||
const next = new Date(Date.UTC(p.year, p.month - 1, p.day + 1))
|
||||
return isoDay(
|
||||
next.getUTCFullYear(),
|
||||
next.getUTCMonth() + 1,
|
||||
next.getUTCDate(),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The last millisecond of a Paris day (YYYY-MM-DD) as a UTC ISO instant,
|
||||
* with the offset in force at that instant. Paris changes offset at 01:00
|
||||
* UTC, so one correction is exact for 23:59 local.
|
||||
*/
|
||||
export function endOfParisDayIso(day: string): string {
|
||||
const match = day.match(/^(\d{4})-(\d{2})-(\d{2})$/)
|
||||
if (!match) throw new Error(`Invalid ISO date: ${day}`)
|
||||
const [y, mo, d] = [Number(match[1]), Number(match[2]), Number(match[3])]
|
||||
const guess = Date.UTC(y, mo - 1, d, 23, 59, 59, 999)
|
||||
const check = new Date(guess)
|
||||
if (
|
||||
check.getUTCFullYear() !== y ||
|
||||
check.getUTCMonth() !== mo - 1 ||
|
||||
check.getUTCDate() !== d
|
||||
)
|
||||
throw new Error(`Invalid ISO date: ${day}`)
|
||||
const p = parisParts(guess)
|
||||
const offset =
|
||||
Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second, 999) -
|
||||
guess
|
||||
return new Date(guess - offset).toISOString()
|
||||
}
|
||||
|
||||
export function nowIso(): string {
|
||||
return new Date().toISOString()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user