chore: scaffold Next.js + Prisma schema + dev MariaDB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c4cee91ed7
commit
8d41c2fffe
27 files changed
+9616
No files matched your search
@@ -0,0 +1,69 @@
|
||||
// Les dates métier sont des chaînes "YYYY-MM-DD" et les mois "YYYY-MM" :
|
||||
// aucune logique jour/mois ne passe par un Date JS, pour éviter tout décalage UTC/Paris.
|
||||
|
||||
const parisDay = new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: "Europe/Paris",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
|
||||
const MONTHS_FR = [
|
||||
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
|
||||
"Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre",
|
||||
];
|
||||
|
||||
const pad = (n: number, len = 2) => String(n).padStart(len, "0");
|
||||
|
||||
export function todayParis(now: Date = new Date()): string {
|
||||
return parisDay.format(now);
|
||||
}
|
||||
|
||||
export function currentMonthParis(now: Date = new Date()): string {
|
||||
return monthOf(todayParis(now));
|
||||
}
|
||||
|
||||
export function monthOf(iso: string): string {
|
||||
return iso.slice(0, 7);
|
||||
}
|
||||
|
||||
export function addMonths(month: string, n: number): string {
|
||||
const [y, m] = month.split("-").map(Number);
|
||||
const index = y * 12 + (m - 1) + n;
|
||||
return `${pad(Math.floor(index / 12), 4)}-${pad((index % 12) + 1)}`;
|
||||
}
|
||||
|
||||
/** Nombre de mois de `from` à `to` (positif si `to` est après). */
|
||||
export function monthsBetween(from: string, to: string): number {
|
||||
const [fy, fm] = from.split("-").map(Number);
|
||||
const [ty, tm] = to.split("-").map(Number);
|
||||
return ty * 12 + tm - (fy * 12 + fm);
|
||||
}
|
||||
|
||||
export function daysInMonth(month: string): number {
|
||||
const [y, m] = month.split("-").map(Number);
|
||||
return new Date(Date.UTC(y, m, 0)).getUTCDate();
|
||||
}
|
||||
|
||||
/** Jour `day` du mois, ramené au dernier jour si le mois est plus court. */
|
||||
export function dateInMonth(month: string, day: number): string {
|
||||
return `${month}-${pad(Math.min(day, daysInMonth(month)))}`;
|
||||
}
|
||||
|
||||
export function toIsoDate(d: Date): string {
|
||||
return `${pad(d.getUTCFullYear(), 4)}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
||||
}
|
||||
|
||||
export function fromIsoDate(iso: string): Date {
|
||||
return new Date(`${iso}T00:00:00.000Z`);
|
||||
}
|
||||
|
||||
export function formatDateFr(iso: string): string {
|
||||
const [y, m, d] = iso.split("-");
|
||||
return `${d}/${m}/${y}`;
|
||||
}
|
||||
|
||||
export function monthLabelFr(month: string): string {
|
||||
const [y, m] = month.split("-").map(Number);
|
||||
return `${MONTHS_FR[m - 1]} ${y}`;
|
||||
}
|
||||
Reference in new issue
Block a user