annotate flys-backend/src/main/java/de/intevation/flys/utils/DateGuesser.java @ 2385:83abe19d4f40

Added a method Gauge.fetchMasterDischargeTable() to retrieve the discharge table with kind = 0. flys-backend/trunk@3994 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 09 Feb 2012 11:30:26 +0000
parents 2e18e12fac11
children 8195396b23ce
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
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 private DateGuesser() {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 public static final int calendarMonth(String month) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 return calendarMonth(Integer.parseInt(month));
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
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 public static final int calendarMonth(int month) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 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
66 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 public static Date guessDate(String s) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 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
70 throw new IllegalArgumentException();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 Matcher m;
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 m = YYYY_MM_DD.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 String day = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 Integer.parseInt(year),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 m = DD_MM_YYYY.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 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
99 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 Integer.parseInt(m.group(1)),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 m = MMM_YYYY.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 int month = guessMonth(m.group(2));
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 if (month >= 0) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 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
115 month,
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 day.length() == 0 ? 15 : Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 m = YYYY_MM_DDThh_mm.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 String day = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 Integer.parseInt(year),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 0
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 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
143
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 String day = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 String second = m.group(6);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 Integer.parseInt(year),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 Integer.parseInt(second)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 m = DD_MM_YYYYThh_mm.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 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
174 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 0
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 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
184
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 String year = m.group(3);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 String month = m.group(2);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 String day = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 String hour = m.group(4);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 String minute = m.group(5);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 String second = m.group(6);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 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
195 calendarMonth(month),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 Integer.parseInt(day),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 Integer.parseInt(hour),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 Integer.parseInt(minute),
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 Integer.parseInt(second)
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 );
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 m = GARBAGE_YYYY.matcher(s);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 if (m.matches()) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 Calendar cal = Calendar.getInstance();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 String year = m.group(1);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 cal.set(
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210 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
211 5, // month
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 15, // day
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 12, 0, 0);
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 return cal.getTime();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 throw new IllegalArgumentException();
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220 public static void main(String [] args) {
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 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
222 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
223 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 }
2e18e12fac11 Added date guesser for WST columns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 // end of file

http://dive4elements.wald.intevation.org