File size: 1,868 Bytes
1813a37 a417977 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
const iso8601ToFrenchRegex = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/;
export function iso8601ToFrench(iso8601: string): string {
const matches = iso8601.match(iso8601ToFrenchRegex);
const year = matches[1];
const month = months[parseInt(matches[2], 10) - 1];
const day = matches[3];
const hours = matches[4];
const minutes = matches[5];
const seconds = matches[6];
return `${day} ${month} ${year} à ${hours}:${minutes}:${seconds}`;
}
const frenchToIso8601Regex = /(\d{1,2}) ([a-zA-Z\u00C0-\u024F]+) (\d{4}) à (\d{2}):(\d{2}):(\d{2})/;
export function frenchToIso8601(french: string): string {
const match = french.match(frenchToIso8601Regex);
if (!match) {
throw new Error('Invalid date format');
}
const [, day, month, year, hours, minutes, seconds] = match;
// Convert the month name to a numeric format
const monthNumber = (months.indexOf(month) + 1).toString();
if (!monthNumber) {
throw new Error('Invalid month name');
}
// Construct the ISO 8601 formatted string
const isoDate = `${year}-${monthNumber.padStart(2, '0')}-${day.padStart(2, '0')}T${hours}:${minutes}:${seconds}`;
return isoDate;
}
const months = [
"janvier", "février", "mars", "avril", "mai", "juin",
"juillet", "août", "septembre", "octobre", "novembre", "décembre"
];
export function getCurrentTimeIso8601(): string {
const now = new Date();
const year = now.getFullYear().toString();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
} |