Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : packages/engine/src/format.ts9 * Module : engine10 * Repository : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website : https://jeux.uqo-eval.app12 * Created : 2026-11-2513 * Last Modified : 2026-11-2514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243/** Formatage en français canadien, partagé par le serveur et l'interface. */4445const money = new Intl.NumberFormat("fr-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0 });46const integer = new Intl.NumberFormat("fr-CA", { maximumFractionDigits: 0 });4748export function formatMoney(value: number): string {49 return money.format(Math.round(value));50}5152export function formatSignedMoney(value: number): string {53 const rounded = Math.round(value);54 if (rounded === 0) return money.format(0);55 return `${rounded > 0 ? "+" : "−"}${money.format(Math.abs(rounded))}`;56}5758export function formatInt(value: number): string {59 return integer.format(Math.round(value));60}6162export function formatPercent(value: number, digits = 1): string {63 return `${new Intl.NumberFormat("fr-CA", { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(value)} %`;64}6566export function formatDecimal(value: number, digits = 1): string {67 return new Intl.NumberFormat("fr-CA", { minimumFractionDigits: digits, maximumFractionDigits: digits }).format(value);68}6970const SQFT_PER_M2 = 10.7639;7172export function sqftToM2(sqft: number): number {73 return sqft / SQFT_PER_M2;74}7576export function formatLivingArea(sqft: number): string {77 return `${formatInt(sqft)} pi² (${formatInt(sqftToM2(sqft))} m²)`;78}7980export function formatLotArea(sqft: number): string {81 const m2 = sqftToM2(sqft);82 if (m2 >= 10_000) return `${formatDecimal(m2 / 10_000, 2)} ha (${formatInt(sqft)} pi²)`;83 return `${formatInt(sqft)} pi² (${formatInt(m2)} m²)`;84}8586export function formatDate(isoDay: string): string {87 const date = new Date(`${isoDay.slice(0, 10)}T12:00:00Z`);88 return new Intl.DateTimeFormat("fr-CA", { day: "numeric", month: "long", year: "numeric", timeZone: "UTC" }).format(date);89}9091export function ordinal(rank: number): string {92 return rank === 1 ? "1er" : `${rank}e`;93}9495/** Date et heure au fuseau de Montréal, ex. « 29 novembre 2026 à 23 h 59 ». */96export function formatDeadline(iso: string | Date): string {97 const date = typeof iso === "string" ? new Date(iso) : iso;98 const day = new Intl.DateTimeFormat("fr-CA", { day: "numeric", month: "long", year: "numeric", timeZone: "America/Toronto" }).format(date);99 const parts = new Intl.DateTimeFormat("fr-CA", { hour: "2-digit", minute: "2-digit", hour12: false, timeZone: "America/Toronto" }).formatToParts(date);100 const hour = Number(parts.find((p) => p.type === "hour")?.value ?? 0) % 24;101 const minute = parts.find((p) => p.type === "minute")?.value ?? "00";102 return `${day} à ${hour} h ${minute}`;103}104