|
const iso8601ToFrenchRegex = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/; |
|
export function iso8601ToFrench(iso8601: string): string { |
|
console.log("iso8601ToTokens", iso8601) |
|
|
|
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 { |
|
console.log("tokensToIso8601", french) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const match = french.match(frenchToIso8601Regex); |
|
|
|
if (!match) { |
|
throw new Error('Invalid date format'); |
|
} |
|
|
|
const [, day, month, year, hours, minutes, seconds] = match; |
|
|
|
|
|
const monthNumber = (months.indexOf(month) + 1).toString(); |
|
|
|
if (!monthNumber) { |
|
throw new Error('Invalid month name'); |
|
} |
|
|
|
|
|
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" |
|
]; |