KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > util > SimpleDateFormatAnalyzer


1 /*
2  * SimpleDateFormatAnalyzer.java jchart2d
3  * Copyright (C) Achim Westermann, created on 09.07.2005, 15:29:54
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  *
22  */

23 package info.monitorenter.util;
24
25 import java.text.SimpleDateFormat JavaDoc;
26
27 /**
28  * Hack for a <code>{@link java.text.SimpleDateFormat}</code> to get further
29  * information about the fields that will be displayed.
30  * <p>
31  *
32  * @version $Revision: 1.1 $
33  *
34  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
35  *
36  */

37 public final class SimpleDateFormatAnalyzer {
38
39   /**
40    * Returns true if the given date format displays days.
41    * <p>
42    *
43    * @param format
44    * the date format to check.
45    *
46    * @return true if the given date format displays days.
47    */

48   public static boolean displaysDay(final SimpleDateFormat JavaDoc format) {
49     boolean ret = false;
50     String JavaDoc fmt = format.toPattern();
51     // day in month, day in year, day of week in month, day of week.
52
ret = fmt.indexOf('d') != -1 || fmt.indexOf('D') != -1 || fmt.indexOf('F') != -1
53         || fmt.indexOf('E') != -1;
54     return ret;
55   }
56
57   /**
58    * Returns true if the given date format displays hours.
59    * <p>
60    *
61    * @param format
62    * the date format to check.
63    *
64    * @return true if the given date format displays hours.
65    */

66   public static boolean displaysHour(final SimpleDateFormat JavaDoc format) {
67     boolean ret = false;
68     String JavaDoc fmt = format.toPattern();
69     ret = fmt.indexOf('H') != -1 || fmt.indexOf('h') != -1 || fmt.indexOf('K') != -1
70         || fmt.indexOf('k') != -1;
71     return ret;
72   }
73
74   /**
75    * Returns true if the given date format displays milliseconds.
76    * <p>
77    *
78    * @param format
79    * the date format to check.
80    *
81    * @return true if the given date format displays milliseconds.
82    */

83   public static boolean displaysMillisecond(final SimpleDateFormat JavaDoc format) {
84     boolean ret = false;
85     String JavaDoc fmt = format.toPattern();
86     ret = fmt.indexOf('S') != -1;
87     return ret;
88   }
89
90   /**
91    * Returns true if the given date format displays minutes.
92    * <p>
93    *
94    * @param format
95    * the date format to check.
96    *
97    * @return true if the given date format displays minutes.
98    */

99   public static boolean displaysMinute(final SimpleDateFormat JavaDoc format) {
100     boolean ret = false;
101     String JavaDoc fmt = format.toPattern();
102     ret = fmt.indexOf('m') != -1;
103     return ret;
104   }
105
106   /**
107    * Returns true if the given date format displays months.
108    * <p>
109    *
110    * @param format
111    * the date format to check.
112    *
113    * @return true if the given date format displays months.
114    */

115   public static boolean displaysMonth(final SimpleDateFormat JavaDoc format) {
116     boolean ret = false;
117     String JavaDoc fmt = format.toPattern();
118     ret = fmt.indexOf('M') != -1;
119     return ret;
120   }
121
122   /**
123    * Returns true if the given date format displays seconds.
124    * <p>
125    *
126    * @param format
127    * the date format to check.
128    *
129    * @return true if the given date format displays seconds.
130    */

131   public static boolean displaysSecond(final SimpleDateFormat JavaDoc format) {
132     boolean ret = false;
133     String JavaDoc fmt = format.toPattern();
134     ret = fmt.indexOf('s') != -1;
135     return ret;
136   }
137
138   /**
139    * Returns true if the given date format displays weeks.
140    * <p>
141    *
142    * @param format
143    * the date format to check.
144    *
145    * @return true if the given date format displays weeks.
146    */

147   public static boolean displaysWeek(final SimpleDateFormat JavaDoc format) {
148     boolean ret = false;
149     String JavaDoc fmt = format.toPattern();
150     ret = fmt.indexOf('W') != -1 || fmt.indexOf('w') != -1;
151     return ret;
152   }
153
154   /**
155    * Returns true if the given date format displays years.
156    * <p>
157    *
158    * @param format
159    * the date format to check.
160    *
161    * @return true if the given date format displays years.
162    */

163   public static boolean displaysYear(final SimpleDateFormat JavaDoc format) {
164     boolean ret = false;
165     String JavaDoc fmt = format.toPattern();
166     ret = fmt.indexOf('y') != -1;
167     return ret;
168   }
169
170   /**
171    * Private utility class constructor: Everything is static.
172    * <p>
173    */

174   private SimpleDateFormatAnalyzer() {
175     super();
176   }
177 }
178
Popular Tags