Improved property date get.

This commit is contained in:
Christian P. MOMON 2022-01-22 03:30:18 +01:00
parent a1b0c34645
commit 251d4ef761

View file

@ -321,16 +321,47 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
result = null; result = null;
} }
else else
{
String pattern;
if (value.matches("\\d{1,2}/\\d{1,2}/\\d{4}"))
{
pattern = "dd/MM/yyyy";
}
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 try
{ {
result = LocalDate.parse(value, DateTimeFormatter.ofPattern("dd/MM/yyyy")); result = LocalDate.parse(value, DateTimeFormatter.ofPattern(pattern));
} }
catch (DateTimeParseException exception) catch (DateTimeParseException exception)
{ {
result = null; result = null;
} }
} }
}
// //
return result; return result;