changeset 4763:8195396b23ce

DateGuesser: Added and handle DDMMYY pattern.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 04 Jan 2013 11:13:02 +0100
parents c6654a19b00f
children 1cfda99c024c
files flys-backend/src/main/java/de/intevation/flys/utils/DateGuesser.java
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/utils/DateGuesser.java	Fri Jan 04 11:12:28 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/utils/DateGuesser.java	Fri Jan 04 11:13:02 2013 +0100
@@ -54,6 +54,9 @@
     public static final Pattern DD_MM_YYYYThh_mm_ss =
         Pattern.compile("^(\\d{1,2})\\.(\\d{1,2})\\.(\\d{2,4})T(\\d{1,2}):(\\d{2}):(\\d{2})$");
 
+    public static final Pattern DDMMYY =
+        Pattern.compile("^(\\d{1,2})(\\d{1,2})(\\d{1,2})$");
+
     private DateGuesser() {
     }
 
@@ -201,6 +204,28 @@
             return cal.getTime();
         }
 
+        m = DDMMYY.matcher(s);
+
+        if (m.matches()) {
+            Calendar cal = Calendar.getInstance();
+            String day   = m.group(1);
+            String month = m.group(2);
+            String yearS  = m.group(3);
+            Integer year = Integer.parseInt(yearS);
+            if (year <= Calendar.getInstance().get(Calendar.YEAR)) {
+                year += 2000;
+            }
+            else {
+                year += 1900;
+            }
+            cal.set(
+                year,
+                Integer.parseInt(month),  // month
+                Integer.parseInt(day), // day
+                12, 0, 0);
+            return cal.getTime();
+        }
+
         m = GARBAGE_YYYY.matcher(s);
 
         if (m.matches()) {

http://dive4elements.wald.intevation.org