File size: 1,764 Bytes
1813a37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1982de5
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
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)
    // Match the components of the date and time from the input string

    // const months = {
    //     janvier: '01', février: '02', mars: '03', avril: '04', mai: '05',
    //     juin: '06', juillet: '07', août: '08', septembre: '09',
    //     octobre: '10', novembre: '11', décembre: '12'
    // };

    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"
];