improve date parsing

This commit is contained in:
Ruidy 2024-07-06 10:50:39 +02:00
parent b25d7be29d
commit 18daf5d482
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

View file

@ -261,7 +261,7 @@ func (bs Service) ParseFromApi(rawContent string) (*Booking, error) {
} }
func extractDate(pattern, content string) string { func extractDate(pattern, content string) string {
re := regexp.MustCompile(pattern + `\w+\.\s*\d{1,2}\s\w+\.*\s\d{4}`) re := regexp.MustCompile(pattern + `(lun|mar|mer|jeu|ven|sam|dim)\. \d{1,2} (janv|févr|mars|avr|mai|juin|juil|août|sept|oct|nov|déc)\.? \d{4}`)
dateMatch := re.FindString(content) dateMatch := re.FindString(content)
if dateMatch == "" { if dateMatch == "" {
@ -311,7 +311,7 @@ func extractString(pattern, content string) string {
func formatDate(date string) *time.Time { func formatDate(date string) *time.Time {
months := map[string]string{ months := map[string]string{
"janv.": "01", "fév": "02", "mar": "03", "avr": "04", "janv.": "01", "fév": "02", "mar": "03", "avr": "04",
"mai": "05", "juin": "06", "juil.": "07", "aoû": "08", "mai": "05", "juin": "06", "juil.": "07", "août": "08",
"sep": "09", "oct": "10", "nov": "11", "déc": "12", "sep": "09", "oct": "10", "nov": "11", "déc": "12",
} }
parts := strings.Split(date, " ") parts := strings.Split(date, " ")