annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java @ 129:110e3ac1b7d2

Library Dependencies Added to pom.xml-File Import of SDE-Datasources geo-backend/trunk@5 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 02 Sep 2009 09:07:03 +0000
parents
children 25be806da62f
rev   line source
129
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 /**
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2 * Title: DateUtisl, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/util/DateUtils.java,v 1.2 2008/08/18 14:50:33 drewnak Exp $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
3 * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/util/DateUtils.java,v $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
4 * created by: Stefan Blume (blume)
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
5 * erstellt am: 21.12.2007
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
6 * Copyright: con terra GmbH, 2005
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
7 *
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
8 * modified by: $Author: drewnak $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
9 * modified on: $Date: 2008/08/18 14:50:33 $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
10 * Version: $Revision: 1.2 $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
11 * TAG: $Name: $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
12 * locked from: $Locker: $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
13 * CVS State: $State: Exp $
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
14 * Project: $ProjectName$
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
15 */
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
16 package de.intevation.gnv.geobackend.util;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
17
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
18 import org.apache.log4j.Logger;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20 import java.text.SimpleDateFormat;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
21 import java.util.Date;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
22
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
23
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 /**
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
25 * The class <code>DateUtisl</code> fulfills the following purposes:
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26 * <ol>
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 * <li></li>
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
28 * </ol>
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
29 *
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
30 * @author blume
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
31 * @version 1.0
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
32 * @serial 1.0
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
33 * @see
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
34 * @since 21.12.2007 10:34:01
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
35 */
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
36 public class DateUtils {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
37
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
38 /**
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
39 * Default Logging instance
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
40 */
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 private static Logger sLogger = Logger.getLogger(DateUtils.class);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
42 private static boolean sDebug = sLogger.isDebugEnabled();
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
43
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
44 private static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss";
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
45 private static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss";
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
46 private static final String TimeRangeFilterPattern = "yyyy-MM-dd'T'HH:mm:ssZ";
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
47 private static final String TimeRangeFilterFormPattern = "dd.MM.yyyy HH:mm";
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
48
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
49 public static String getPatternedDateSDF(Date pDate) {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
50 SimpleDateFormat fmt = new SimpleDateFormat();
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
51 fmt.applyPattern(DATE_PATTERN);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52 return fmt.format(pDate);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
53 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 public static String getPatternedDate(Date pDate, String sPattern) {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
56 // DateTimeZone.setDefault(DateTimeZone.UTC);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
57 // DateTime dtf = new DateTime (pDate);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
58 // String sStr = dtf.toString(sPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
59 // return sStr;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
60 SimpleDateFormat fmt = new SimpleDateFormat();
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
61 fmt.applyPattern(sPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
62 return fmt.format(pDate);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
63 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
64
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
65 public static String getPatternedDateAmer(Date pDate) {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
66
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
67 String sStr = getPatternedDate(pDate, DATE_PATTERN);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
68 return sStr;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
69 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
70
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
71 public static String getPatternedDateGerm(Date pDate) {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
72
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
73 String sStr = getPatternedDate(pDate, DATE_PATTERN1);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
74 return sStr;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
75 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
76
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
77 public static String getPatternedDateTimeRangeFilter(Date pDate) {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
78
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
79 String sStr = getPatternedDate(pDate, TimeRangeFilterPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
80 return sStr;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
81 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
82
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
83 public static String getPatternedDateTimeRangeFilterForm(Date pDate) {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
84
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
85 String sStr = getPatternedDate(pDate, TimeRangeFilterFormPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
86 return sStr;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
87 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
88
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
89 public synchronized static Date getDateFromStringSDF (String sStr)throws Exception {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
90 SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
91 Date date = (Date)formatter.parse(sStr);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
92 return date;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
93 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
94
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
95 public static Date getDateFromString (String sStr)throws Exception {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
96
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
97 Date date = getDateFromString (sStr, DATE_PATTERN1);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
98 return date;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
99 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
100
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
101 public static Date getDateFromStringTimeRangeFilter (String sStr)throws Exception {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
102
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
103 Date date = getDateFromString (sStr, TimeRangeFilterPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
104 return date;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
105 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
106
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
107 public static Date getDateFromStringTimeRangeFilterForm (String sStr)throws Exception {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
108
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
109 Date date = getDateFromString (sStr, TimeRangeFilterFormPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
110 return date;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
111 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
112
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
113 public static Date getDateFromString (String sStr, String sPattern)throws Exception {
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
114 // DateTime dtf = null;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
115 // DateTimeZone.setDefault(DateTimeZone.UTC);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
116 //
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
117 // dtf = DateTimeFormat.forPattern(sPattern).parseDateTime(sStr);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
118 //
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
119 // Date date = dtf.toDate();
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
120 //
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
121 // return date;
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
122 SimpleDateFormat fmt = new SimpleDateFormat();
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
123 fmt.applyPattern(sPattern);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
124 return fmt.parse(sStr);
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
125 }
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
126
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
127
110e3ac1b7d2 Library Dependencies Added to pom.xml-File
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
128 }

http://dive4elements.wald.intevation.org