You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
880 B
TypeScript
34 lines
880 B
TypeScript
import { format, parseISO } from 'date-fns';
|
|
import { fr } from 'date-fns/locale';
|
|
|
|
/**
|
|
* Extract the week number from an ISO week string like "2026-W12".
|
|
* Returns the numeric string (e.g. "12") or the raw input if parsing fails.
|
|
*/
|
|
export function extractWeekNumber(week: string): string {
|
|
const match = week.match(/-W(\d{1,2})$/);
|
|
return match ? match[1] : week;
|
|
}
|
|
|
|
/**
|
|
* Format an ISO date string (e.g. "2026-03-21T10:00:00Z") as "21 mars 2026".
|
|
*/
|
|
export function formatDate(isoDate: string): string {
|
|
try {
|
|
return format(parseISO(isoDate), 'dd MMM yyyy', { locale: fr });
|
|
} catch {
|
|
return isoDate;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Format an ISO date string as "21 mars 2026" (full month name).
|
|
*/
|
|
export function formatDateLong(isoDate: string): string {
|
|
try {
|
|
return format(parseISO(isoDate), 'dd MMMM yyyy', { locale: fr });
|
|
} catch {
|
|
return isoDate;
|
|
}
|
|
}
|