annotate flys-backend/src/main/java/de/intevation/flys/utils/DateGuesser.java @ 5566:adb6c0f14810

Removed obsolete imports.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Apr 2013 09:10:10 +0200
parents 28fa48986ae9
children
rev   line source
2357
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.utils;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 /**
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 * Copyright (c) 2006 by Intevation GmbH
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 *
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 * @author Sascha L. Teichmann (teichmann@intevation.de)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 *
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 * This program is free software under the LGPL (&gt;=v2.1)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 * Read the file LGPL coming with FLYS for details.
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 */
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.util.Date;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.util.Calendar;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.util.regex.Pattern;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import java.util.regex.Matcher;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public final class DateGuesser {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 public static final String [] MONTH = {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "jan", "feb", "mrz", "apr", "mai", "jun",
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 "jul", "aug", "sep", "okt", "nov", "dez"
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 };
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public static final int guessMonth(String s) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 s = s.toLowerCase();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 for (int i = 0; i < MONTH.length; ++i)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 if (MONTH[i].equals(s)) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 return i;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 return -1;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 public static final Pattern YYYY_MM_DD =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 public static final Pattern DD_MM_YYYY =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 Pattern.compile("^(\\d{1,2})\\.(\\d{1,2})\\.(\\d{2,4})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 public static final Pattern MMM_YYYY =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 Pattern.compile("^(\\d{0,2})\\.?(\\w{3})\\.?(\\d{2,4})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 public static final Pattern GARBAGE_YYYY =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 Pattern.compile("^\\D*(\\d{2,4})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public static final Pattern YYYY_MM_DDThh_mm =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 public static final Pattern YYYY_MM_DDThh_mm_ss =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 public static final Pattern DD_MM_YYYYThh_mm =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 Pattern.compile("^(\\d{1,2})\\.(\\d{1,2})\\.(\\d{2,4})T(\\d{1,2}):(\\d{2})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public static final Pattern DD_MM_YYYYThh_mm_ss =
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 Pattern.compile("^(\\d{1,2})\\.(\\d{1,2})\\.(\\d{2,4})T(\\d{1,2}):(\\d{2}):(\\d{2})$");
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
4763
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
57 public static final Pattern DDMMYY =
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
58 Pattern.compile("^(\\d{1,2})(\\d{1,2})(\\d{1,2})$");
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
59
2357
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 private DateGuesser() {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 public static final int calendarMonth(String month) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 return calendarMonth(Integer.parseInt(month));
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 public static final int calendarMonth(int month) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 return Math.max(Math.min(month-1, 11), 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
4764
1cfda99c024c DateGuesser: doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4763
diff changeset
71 /**
1cfda99c024c DateGuesser: doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4763
diff changeset
72 * Guess date by trying all different patterns.
1cfda99c024c DateGuesser: doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4763
diff changeset
73 * Throws IllegalArgumentException if not able to guess.
1cfda99c024c DateGuesser: doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4763
diff changeset
74 * @param s The date to be guessed (e.g. 11.02.2001).
1cfda99c024c DateGuesser: doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4763
diff changeset
75 * @return the parsed Date.
1cfda99c024c DateGuesser: doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4763
diff changeset
76 */
2357
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 public static Date guessDate(String s) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 if (s == null || (s = s.trim()).length() == 0) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 throw new IllegalArgumentException();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 Matcher m;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 m = YYYY_MM_DD.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 String day = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 Integer.parseInt(year),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 m = DD_MM_YYYY.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 Integer.parseInt(m.group(1)),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 m = MMM_YYYY.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 int month = guessMonth(m.group(2));
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 if (month >= 0) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 month,
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 day.length() == 0 ? 15 : Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 m = YYYY_MM_DDThh_mm.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 String day = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 Integer.parseInt(year),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 0
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 m = YYYY_MM_DDThh_mm_ss.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 String day = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 String second = m.group(6);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 Integer.parseInt(year),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 Integer.parseInt(second)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 m = DD_MM_YYYYThh_mm.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 0
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 m = DD_MM_YYYYThh_mm_ss.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 String second = m.group(6);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 Integer.parseInt(second)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212
4763
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
213 m = DDMMYY.matcher(s);
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
214
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
215 if (m.matches()) {
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
216 Calendar cal = Calendar.getInstance();
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
217 String day = m.group(1);
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
218 String month = m.group(2);
4770
28fa48986ae9 DateGuesser: Take current year modulo 100 if compare it with a two digit year value. Removed auto boxing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4764
diff changeset
219 String yearS = m.group(3);
28fa48986ae9 DateGuesser: Take current year modulo 100 if compare it with a two digit year value. Removed auto boxing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4764
diff changeset
220 int year = Integer.parseInt(yearS);
28fa48986ae9 DateGuesser: Take current year modulo 100 if compare it with a two digit year value. Removed auto boxing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4764
diff changeset
221
28fa48986ae9 DateGuesser: Take current year modulo 100 if compare it with a two digit year value. Removed auto boxing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4764
diff changeset
222 if (year <= cal.get(Calendar.YEAR) % 100) {
4763
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
223 year += 2000;
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
224 }
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
225 else {
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
226 year += 1900;
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
227 }
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
228 cal.set(
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
229 year,
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
230 Integer.parseInt(month), // month
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
231 Integer.parseInt(day), // day
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
232 12, 0, 0);
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
233 return cal.getTime();
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
234 }
8195396b23ce DateGuesser: Added and handle DDMMYY pattern.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2357
diff changeset
235
2357
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 m = GARBAGE_YYYY.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242 Integer.parseInt(year) + (year.length() == 2 ? 1900 : 0),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 5, // month
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
244 15, // day
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
245 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
248
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
249 throw new IllegalArgumentException();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
250 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
251
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252 public static void main(String [] args) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
253 for (int i = 0; i < args.length; ++i) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
254 System.out.println(args[i] + ": " + guessDate(args[i]));
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
255 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
257 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258 // end of file

http://dive4elements.wald.intevation.org