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