// Display rule of the license expiry date on the License card (#347, D9). // // Keys issued since maximus-api#63 last 100 years: a date in 2126 is noise, and the // key does not end in any practical sense. Beyond the horizon the card shows // "No expiry date"; closer dates show in the app language. /** Beyond this horizon, an expiry date is shown as "no expiry date". */ export const NO_EXPIRY_HORIZON_YEARS = 50; const SECONDS_PER_YEAR = 365.25 * 24 * 3600; export type LicenseExpiryDisplay = { kind: "noExpiry" } | { kind: "date"; text: string }; /** * How the card shows `expiresAt` (seconds since the epoch) at `nowSeconds`: no date * beyond the horizon, otherwise the date formatted for `locale` (`fr-CA` or `en-CA`, * chosen by the card from the app language). */ export function licenseExpiryDisplay( expiresAt: number, nowSeconds: number, locale: string, ): LicenseExpiryDisplay { if (expiresAt - nowSeconds > NO_EXPIRY_HORIZON_YEARS * SECONDS_PER_YEAR) { return { kind: "noExpiry" }; } return { kind: "date", text: new Date(expiresAt * 1000).toLocaleDateString(locale) }; }