From 251d4ef76167126a9dc3503fffc8809c5ee96f4f Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 22 Jan 2022 03:30:18 +0100 Subject: [PATCH] Improved property date get. --- .../properties/PathPropertyList.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index 954296d..bec72fa 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -322,14 +322,45 @@ public class PathPropertyList extends ArrayList implements PathPro } else { - try + String pattern; + if (value.matches("\\d{1,2}/\\d{1,2}/\\d{4}")) { - result = LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy")); + pattern = "dd/MM/yyyy"; } - catch (DateTimeParseException exception) + else if (value.matches("\\d{4}-\\d{2}-\\d{2}")) + { + pattern = "yyyy-MM-dd"; + } + else if (value.matches("\\d{1,2}/\\d{4}")) + { + value = "01/" + value; + pattern = "dd/MM/yyyy"; + } + else if (value.matches("\\d{4}-\\d{2}")) + { + value = value + "-01"; + pattern = "yyyy-MM-dd"; + } + else + { + pattern = null; + } + + if (pattern == null) { result = null; } + else + { + try + { + result = LocalDate.parse(value, DateTimeFormatter.ofPattern(pattern)); + } + catch (DateTimeParseException exception) + { + result = null; + } + } } //