comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/util/DateUtils.java @ 884:12f88239fb33

Updated Javadocs to the Listed Classes. Also done some Codecleanup and removed unused Methods from the Code. geo-backend/trunk@842 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 26 Mar 2010 15:23:03 +0000
parents 25be806da62f
children 8b442223741c
comparison
equal deleted inserted replaced
883:6d568397740c 884:12f88239fb33
13 * CVS State: $State: Exp $ 13 * CVS State: $State: Exp $
14 * Project: $ProjectName$ 14 * Project: $ProjectName$
15 */ 15 */
16 package de.intevation.gnv.geobackend.util; 16 package de.intevation.gnv.geobackend.util;
17 17
18 import org.apache.log4j.Logger;
19
20 import java.text.SimpleDateFormat; 18 import java.text.SimpleDateFormat;
21 import java.util.Date; 19 import java.util.Date;
22 20
21 import org.apache.log4j.Logger;
22
23 23
24 /** 24 /**
25 * The class <code>DateUtisl</code> fulfills the following purposes: 25 * The class <code>DateUtils</code> fulfills the following purposes:
26 * <ol>
27 * <li></li>
28 * </ol>
29 *
30 * @author blume 26 * @author blume
31 * @version 1.0 27 * @author Tim Englich <tim.englich@intevation.de>
32 * @serial 1.0
33 * @see
34 * @since 21.12.2007 10:34:01
35 */ 28 */
36 public class DateUtils { 29 public class DateUtils {
37 30
38 /** 31 /**
39 * Default Logging instance 32 * Default Logging instance
40 */ 33 */
41 private static Logger sLogger = Logger.getLogger(DateUtils.class); 34 private static Logger sLogger = Logger.getLogger(DateUtils.class);
42 private static boolean sDebug = sLogger.isDebugEnabled();
43 35
36 /**
37 * The Dateformat which will be used e.g for Querying the Database
38 */
44 public static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss"; 39 public static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss";
45 public static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss";
46 public static final String TimeRangeFilterPattern = "yyyy-MM-dd'T'HH:mm:ssZ";
47 public static final String TimeRangeFilterFormPattern = "dd.MM.yyyy HH:mm";
48 40
49 public static String getPatternedDateSDF(Date pDate) { 41 private static final String DATE_PATTERN1 = "dd-MMM-yyyy HH:mm:ss";
50 SimpleDateFormat fmt = new SimpleDateFormat(); 42
51 fmt.applyPattern(DATE_PATTERN); 43 /**
52 return fmt.format(pDate); 44 * The Method returns a Date using the given pattern as a String
53 } 45 * @param pDate The Date which should be formatted
54 46 * @param sPattern The Pattern which should be used.
47 * @return the Date formatted a a String
48 */
55 public static String getPatternedDate(Date pDate, String sPattern) { 49 public static String getPatternedDate(Date pDate, String sPattern) {
56 // DateTimeZone.setDefault(DateTimeZone.UTC); 50 SimpleDateFormat fmt = new SimpleDateFormat();
57 // DateTime dtf = new DateTime (pDate);
58 // String sStr = dtf.toString(sPattern);
59 // return sStr;
60 SimpleDateFormat fmt = new SimpleDateFormat();
61 fmt.applyPattern(sPattern); 51 fmt.applyPattern(sPattern);
62 return fmt.format(pDate); 52 return fmt.format(pDate);
63 } 53 }
64 54
55 /**
56 * Returns the Date as a String formated using the
57 * @see DateUtils.DATE_PATTERN
58 * @param pDate the Date which should be formatted
59 * @return the given Data as a String
60 */
65 public static String getPatternedDateAmer(Date pDate) { 61 public static String getPatternedDateAmer(Date pDate) {
66 62 String sStr = getPatternedDate(pDate, DATE_PATTERN);
67 String sStr = getPatternedDate(pDate, DATE_PATTERN);
68 return sStr; 63 return sStr;
69 } 64 }
70 65
71 public static String getPatternedDateGerm(Date pDate) { 66 /**
72 67 * Thismethod decodes a Datevalue from the given String useing the
73 String sStr = getPatternedDate(pDate, DATE_PATTERN1); 68 * @see DateUtils.DATE_PATTERN1 format-
74 return sStr; 69 * @param sStr The String which contains the encoded Datevalue
70 * @return the decoded Datevalue as an Date-object.
71 * @throws Exception throws all Expetion which occurs during the Process.
72 */
73 public static Date getDateFromString (String sStr)throws Exception {
74 Date date = getDateFromString (sStr, DATE_PATTERN1);
75 return date;
75 } 76 }
76 77
77 public static String getPatternedDateTimeRangeFilter(Date pDate) { 78 /**
78 79 * Formats a given Date encoded as a String using the given Pattern
79 String sStr = getPatternedDate(pDate, TimeRangeFilterPattern); 80 * into a Date Object.
80 return sStr; 81 * @param sStr The String with the encoded DateValue
81 } 82 * @param sPattern The pattern which should be used to decode the Date
82 83 * @return the given Datevalue as an Date-Object.
83 public static String getPatternedDateTimeRangeFilterForm(Date pDate) { 84 * @throws Exception throws all Expetion which occurs during the Process.
84 85 */
85 String sStr = getPatternedDate(pDate, TimeRangeFilterFormPattern); 86 public static Date getDateFromString (String sStr,
86 return sStr; 87 String sPattern)throws Exception {
87 } 88 SimpleDateFormat fmt = new SimpleDateFormat();
88
89 public synchronized static Date getDateFromStringSDF (String sStr)throws Exception {
90 SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
91 Date date = (Date)formatter.parse(sStr);
92 return date;
93 }
94
95 public static Date getDateFromString (String sStr)throws Exception {
96
97 Date date = getDateFromString (sStr, DATE_PATTERN1);
98 return date;
99 }
100
101 public static Date getDateFromStringTimeRangeFilter (String sStr)throws Exception {
102
103 Date date = getDateFromString (sStr, TimeRangeFilterPattern);
104 return date;
105 }
106
107 public static Date getDateFromStringTimeRangeFilterForm (String sStr)throws Exception {
108
109 Date date = getDateFromString (sStr, TimeRangeFilterFormPattern);
110 return date;
111 }
112
113 public static Date getDateFromString (String sStr, String sPattern)throws Exception {
114 // DateTime dtf = null;
115 // DateTimeZone.setDefault(DateTimeZone.UTC);
116 //
117 // dtf = DateTimeFormat.forPattern(sPattern).parseDateTime(sStr);
118 //
119 // Date date = dtf.toDate();
120 //
121 // return date;
122 SimpleDateFormat fmt = new SimpleDateFormat();
123 fmt.applyPattern(sPattern); 89 fmt.applyPattern(sPattern);
124 return fmt.parse(sStr); 90 return fmt.parse(sStr);
125 } 91 }
126
127
128 } 92 }

http://dive4elements.wald.intevation.org