1 | |
package org.apache.maven.plugins.pdf; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.text.SimpleDateFormat; |
23 | |
|
24 | |
import java.util.Date; |
25 | |
import java.util.Locale; |
26 | |
import java.util.TimeZone; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class DateBean |
39 | |
{ |
40 | 1 | private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); |
41 | |
|
42 | 1 | private static final SimpleDateFormat YEAR = new SimpleDateFormat( "yyyy", Locale.US ); |
43 | 1 | private static final SimpleDateFormat MONTH = new SimpleDateFormat( "MM", Locale.US ); |
44 | 1 | private static final SimpleDateFormat DAY = new SimpleDateFormat( "dd", Locale.US ); |
45 | 1 | private static final SimpleDateFormat HOUR = new SimpleDateFormat( "HH", Locale.US ); |
46 | 1 | private static final SimpleDateFormat MINUTE = new SimpleDateFormat( "mm", Locale.US ); |
47 | 1 | private static final SimpleDateFormat SECOND = new SimpleDateFormat( "ss", Locale.US ); |
48 | 1 | private static final SimpleDateFormat MILLI_SECOND = new SimpleDateFormat( "SSS", Locale.US ); |
49 | 1 | private static final SimpleDateFormat DATE = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ); |
50 | 1 | private static final SimpleDateFormat TIME = new SimpleDateFormat( "HH:mm:ss\'Z\'", Locale.US ); |
51 | 1 | private static final SimpleDateFormat DATE_TIME = new SimpleDateFormat( "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'", Locale.US ); |
52 | |
|
53 | |
static |
54 | |
{ |
55 | 1 | YEAR.setTimeZone( UTC_TIME_ZONE ); |
56 | 1 | MONTH.setTimeZone( UTC_TIME_ZONE ); |
57 | 1 | DAY.setTimeZone( UTC_TIME_ZONE ); |
58 | 1 | HOUR.setTimeZone( UTC_TIME_ZONE ); |
59 | 1 | MINUTE.setTimeZone( UTC_TIME_ZONE ); |
60 | 1 | SECOND.setTimeZone( UTC_TIME_ZONE ); |
61 | 1 | MILLI_SECOND.setTimeZone( UTC_TIME_ZONE ); |
62 | 1 | DATE.setTimeZone( UTC_TIME_ZONE ); |
63 | 1 | TIME.setTimeZone( UTC_TIME_ZONE ); |
64 | 1 | DATE_TIME.setTimeZone( UTC_TIME_ZONE ); |
65 | 1 | } |
66 | |
|
67 | |
private Date date; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public DateBean() |
73 | |
{ |
74 | 7 | this( new Date() ); |
75 | 7 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public DateBean( final Date date ) |
83 | 7 | { |
84 | 7 | this.date = date; |
85 | 7 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public void setDate( final Date date ) |
93 | |
{ |
94 | 1 | this.date = date; |
95 | 1 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public String getYear() |
102 | |
{ |
103 | 1 | synchronized ( this ) |
104 | |
{ |
105 | 1 | return YEAR.format( date ); |
106 | 0 | } |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public String getMonth() |
113 | |
{ |
114 | 1 | synchronized ( this ) |
115 | |
{ |
116 | 1 | return MONTH.format( date ); |
117 | 0 | } |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public String getDay() |
124 | |
{ |
125 | 1 | synchronized ( this ) |
126 | |
{ |
127 | 1 | return DAY.format( date ); |
128 | 0 | } |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
public String getHour() |
135 | |
{ |
136 | 1 | synchronized ( this ) |
137 | |
{ |
138 | 1 | return HOUR.format( date ); |
139 | 0 | } |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public String getMinute() |
146 | |
{ |
147 | 1 | synchronized ( this ) |
148 | |
{ |
149 | 1 | return MINUTE.format( date ); |
150 | 0 | } |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public String getSecond() |
157 | |
{ |
158 | 1 | synchronized ( this ) |
159 | |
{ |
160 | 1 | return SECOND.format( date ); |
161 | 0 | } |
162 | |
} |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public String getMillisecond() |
168 | |
{ |
169 | 1 | synchronized ( this ) |
170 | |
{ |
171 | 1 | return MILLI_SECOND.format( date ); |
172 | 0 | } |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
public String getDate() |
179 | |
{ |
180 | 4 | synchronized ( this ) |
181 | |
{ |
182 | 4 | return DATE.format( date ); |
183 | 0 | } |
184 | |
} |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public String getTime() |
190 | |
{ |
191 | 1 | synchronized ( this ) |
192 | |
{ |
193 | 1 | return TIME.format( date ); |
194 | 0 | } |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
public String getDateTime() |
201 | |
{ |
202 | 1 | synchronized ( this ) |
203 | |
{ |
204 | 1 | return DATE_TIME.format( date ); |
205 | 0 | } |
206 | |
} |
207 | |
} |