[Dive4elements-commits] [PATCH 09 of 13] DateGuesser: Added and handle DDMMYY pattern

Wald Commits scm-commit at wald.intevation.org
Fri Jan 4 11:12:48 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1357294382 -3600
# Node ID 8195396b23ce63c52ca613639f6e6ed584e5bb18
# Parent  c6654a19b00fe7f8841626eaff230b6b3af6db9c
DateGuesser: Added and handle DDMMYY pattern.

diff -r c6654a19b00f -r 8195396b23ce flys-backend/src/main/java/de/intevation/flys/utils/DateGuesser.java
--- 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()) {


More information about the Dive4elements-commits mailing list