40 import net.fortuna.ical4j.util.CompatibilityHints; |
40 import net.fortuna.ical4j.util.CompatibilityHints; |
41 import net.fortuna.ical4j.util.Dates; |
41 import net.fortuna.ical4j.util.Dates; |
42 import net.fortuna.ical4j.util.TimeZones; |
42 import net.fortuna.ical4j.util.TimeZones; |
43 |
43 |
44 import org.apache.commons.lang.builder.EqualsBuilder; |
44 import org.apache.commons.lang.builder.EqualsBuilder; |
45 import org.apache.commons.lang.builder.HashCodeBuilder; |
|
46 |
45 |
47 /** |
46 /** |
48 * $Id$ |
47 * $Id$ |
49 * |
48 * |
50 * Created on 26/06/2005 |
49 * Created on 26/06/2005 |
159 private static final long serialVersionUID = -6407231357919440387L; |
158 private static final long serialVersionUID = -6407231357919440387L; |
160 |
159 |
161 private static final String DEFAULT_PATTERN = "yyyyMMdd'T'HHmmss"; |
160 private static final String DEFAULT_PATTERN = "yyyyMMdd'T'HHmmss"; |
162 |
161 |
163 private static final String UTC_PATTERN = "yyyyMMdd'T'HHmmss'Z'"; |
162 private static final String UTC_PATTERN = "yyyyMMdd'T'HHmmss'Z'"; |
|
163 |
|
164 private static final String VCARD_PATTERN = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"; |
164 |
165 |
165 private static final String RELAXED_PATTERN = "yyyyMMdd"; |
166 private static final String RELAXED_PATTERN = "yyyyMMdd"; |
166 |
167 |
167 /** |
168 /** |
168 * Used for parsing times in a UTC date-time representation. |
169 * Used for parsing times in a UTC date-time representation. |
193 } |
194 } |
194 |
195 |
195 private static final DateFormatCache RELAXED_FORMAT; |
196 private static final DateFormatCache RELAXED_FORMAT; |
196 static { |
197 static { |
197 final DateFormat format = new SimpleDateFormat(RELAXED_PATTERN); |
198 final DateFormat format = new SimpleDateFormat(RELAXED_PATTERN); |
198 format.setLenient(false); |
199 format.setLenient(true); |
199 RELAXED_FORMAT = new DateFormatCache(format); |
200 RELAXED_FORMAT = new DateFormatCache(format); |
|
201 } |
|
202 |
|
203 private static final DateFormatCache VCARD_FORMAT; |
|
204 static { |
|
205 final DateFormat format = new SimpleDateFormat(VCARD_PATTERN); |
|
206 VCARD_FORMAT = new DateFormatCache(format); |
200 } |
207 } |
201 |
208 |
202 private Time time; |
209 private Time time; |
203 |
210 |
204 private TimeZone timezone; |
211 private TimeZone timezone; |
303 getFormat().getTimeZone()); |
310 getFormat().getTimeZone()); |
304 } |
311 } |
305 setTimeZone(timezone); |
312 setTimeZone(timezone); |
306 } |
313 } |
307 } catch (ParseException pe) { |
314 } catch (ParseException pe) { |
308 if (CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING)) { |
315 if (CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_VCARD_COMPATIBILITY)) { |
309 |
316 |
|
317 try { |
|
318 setTime(value, (DateFormat) VCARD_FORMAT.get(), timezone); |
|
319 setTimeZone(timezone); |
|
320 } catch (ParseException pe2) { |
|
321 if (CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING)) { |
|
322 setTime(value, (DateFormat) RELAXED_FORMAT.get(), timezone); |
|
323 setTimeZone(timezone); |
|
324 } |
|
325 } |
|
326 } else if (CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING)) { |
310 setTime(value, (DateFormat) RELAXED_FORMAT.get(), timezone); |
327 setTime(value, (DateFormat) RELAXED_FORMAT.get(), timezone); |
311 setTimeZone(timezone); |
328 setTimeZone(timezone); |
312 } else { |
329 } else { |
313 throw pe; |
330 throw pe; |
314 } |
331 } |