mirror of
https://github.com/napnap75/multiarch-docker-images.git
synced 2026-11-13 09:31:46 +01:00
feat(config): add frDate helper for French natural-language dates
Go date layouts only know English month names, so date(value, layout) cannot parse "le 19 janvier 2026". frDate(text) extracts and parses such dates (day optional, abbreviated months, accents optional) into a native date; no match is a rule error routing the document to pending/. Documented in arch.md §5, covered by unit tests.
This commit is contained in:
@@ -24,3 +24,33 @@ func TestDefaultConfigExpressionHelpers(t *testing.T) {
|
||||
t.Fatal("default config rendered an empty file name")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestFrenchDate(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"Facture en date du 19 janvier 2026", "19/01/2026"},
|
||||
{"le 1er févr. 2026", "01/02/2026"},
|
||||
{"Janvier 2026", "01/01/2026"}, // no day: first of the month
|
||||
{"Avis arrêté au 3 septembre 2026", "03/09/2026"},
|
||||
{"Situation au 31 decembre 2026", "31/12/2026"}, // unaccented
|
||||
}
|
||||
for _, c := range cases {
|
||||
v, err := FrenchDate(c.in)
|
||||
if err != nil {
|
||||
t.Fatalf("frDate(%q): %v", c.in, err)
|
||||
}
|
||||
got, ok := v.(time.Time)
|
||||
if !ok || got.Format("02/01/2006") != c.want {
|
||||
t.Fatalf("frDate(%q) = %v, want %s", c.in, v, c.want)
|
||||
}
|
||||
}
|
||||
if _, err := FrenchDate("no date in this text 123"); err == nil {
|
||||
t.Fatal("frDate: expected an error when no French date is found")
|
||||
}
|
||||
if _, err := FrenchDate("le 31 février 2026"); err == nil {
|
||||
t.Fatal("frDate: expected an error on an invalid date")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user