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:
bchanot committed 2026-11-02 21:29:33 +01:00
1 parent 4111efa1d1
commit 51225cacf6
17 files changed
+437 -61

No files matched your search

+7 -2
View File
@@ -83,12 +83,17 @@ export function personName(
return person?.display_name || t('admin.person.unnamed')
}
/** A server timestamp as a date in the interface language. */
export function formatDay(iso: string, locale: Locale): string {
/** A server timestamp as a date in the interface language (in `timeZone` when given). */
export function formatDay(
iso: string,
locale: Locale,
timeZone?: string,
): string {
return new Date(iso).toLocaleDateString(locale, {
day: 'numeric',
month: 'long',
year: 'numeric',
...(timeZone ? { timeZone } : {}),
})
}
+15 -9
View File
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { codePointLength } from '@faunosteo/supabase'
import { localDateIso } from '@/lib/dates'
import { endOfParisDayIso, parisDateIso } from '@/lib/dates'
/**
* The administration forms (contract §5.2, §7.2, §7.4). Bounds and patterns
@@ -173,11 +173,20 @@ export interface GrantFields {
kind: GrantKind
reason: string
verification_note?: string
/** The end of the chosen day, device time zone. */
/** The end of the chosen day, Europe/Paris (owner 2026-11-02). */
expires_at?: string
}
/** The expiry is a day after today (device date): the server refuses a past one. */
/** YYYY-MM-DD naming a real calendar day (no 2026-02-30). */
function isRealDay(day: string): boolean {
const match = day.match(/^(\d{4})-(\d{2})-(\d{2})$/)
if (!match) return false
const [y, mo, d] = [Number(match[1]), Number(match[2]), Number(match[3])]
const date = new Date(Date.UTC(y, mo - 1, d))
return date.getUTCMonth() === mo - 1 && date.getUTCDate() === d
}
/** The expiry is a real day after today (Paris date): the server refuses a past one. */
function grantSchema(today: string) {
return z
.object({
@@ -195,8 +204,7 @@ function grantSchema(today: string) {
expires_on: z
.string()
.refine(
(day) =>
day === '' || (/^\d{4}-\d{2}-\d{2}$/.test(day) && day > today),
(day) => day === '' || (isRealDay(day) && day > today),
'admin.access.error.expiry',
),
})
@@ -228,9 +236,7 @@ function grantSchema(today: string) {
: {}),
...(values.expires_on
? {
expires_at: new Date(
`${values.expires_on}T23:59:59`,
).toISOString(),
expires_at: endOfParisDayIso(values.expires_on),
}
: {}),
}),
@@ -239,7 +245,7 @@ function grantSchema(today: string) {
export function parseGrant(
values: GrantFormValues,
today: string = localDateIso(),
today: string = parisDateIso(),
): Parsed<GrantFields, keyof GrantFormValues> {
return parse(grantSchema(today), values)
}
+2 -1
View File
@@ -7,6 +7,7 @@ import FormField from '@/components/ui/FormField'
import Notice from '@/components/ui/Notice'
import Select from '@/components/ui/Select'
import { formatDay } from '@/admin/labels'
import { PARIS_TIME_ZONE } from '@/lib/dates'
import type { Locale } from '@/i18n/types'
import { useLocaleStore } from '@/state/localeStore'
import { useT } from '@/i18n/useT'
@@ -51,7 +52,7 @@ function GrantItem({
const expiry = grant.expires_at
? t('admin.access.list.expires').replace(
'{date}',
formatDay(grant.expires_at, locale),
formatDay(grant.expires_at, locale, PARIS_TIME_ZONE),
)
: t('admin.access.list.no_expiry')
const live = grant.state === 'active' || grant.state === 'expiring'
+2 -2
View File
@@ -23,7 +23,7 @@ import {
type GrantFormValues,
} from '@/admin/validation'
import { translateFieldError } from '@/account/validation'
import { localDateIso } from '@/lib/dates'
import { parisTomorrowIso } from '@/lib/dates'
import { getSupabaseClient } from '@/lib/supabase'
import { useT } from '@/i18n/useT'
@@ -277,7 +277,7 @@ export default function GrantPanel({ onGranted }: { onGranted: () => void }) {
<Input
id="grant-expiry"
type="date"
min={localDateIso(new Date(Date.now() + 86_400_000))}
min={parisTomorrowIso()}
value={values.expires_on}
onChange={(e) => set('expires_on')(e.target.value)}
aria-invalid={Boolean(errors.expires_on)}
+1 -1
View File
@@ -1171,7 +1171,7 @@ export const en: Dict = {
'catalogue.failure.rate_limited': 'Too many requests. Wait a few minutes before trying again.',
'catalogue.failure.unavailable': 'The catalogue is temporarily unavailable. Try again later.',
'catalogue.failure.drawing_missing': 'A drawing of this version cannot be found.',
'catalogue.failure.drawing_hash_mismatch': "A drawing's file content does not match its recorded SHA-256 fingerprint.",
'catalogue.failure.drawing_hash_mismatch': "The illustration file's contents do not match its recorded SHA-256 hash.",
'catalogue.failure.fingerprint_mismatch': "This version's fingerprint does not match the one recorded at its publication.",
'catalogue.failure.invalid_document': "This version's content cannot be read.",
'catalogue.failure.caps': 'This version exceeds the size limits of a sheet.',
+1 -1
View File
@@ -987,7 +987,7 @@ export const fr: Dict = {
'admin.person.unnamed': 'Compte sans nom',
'admin.grant_kind.catalog_reader': 'Accès au catalogue',
'admin.grant_kind.sheet_editor': 'Éditeur de fiches',
'admin.grant_kind.sheet_reviewer': 'Relecteur, relectrice',
'admin.grant_kind.sheet_reviewer': 'Relecteur ou relectrice',
'admin.grant_kind.sheet_publisher': 'Responsable de publication',
'admin.grant_state.active': 'En vigueur',
'admin.grant_state.expiring': 'Expire sous 30 jours',
+68
View File
@@ -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()
}