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