JacksonThymeleafISO8601DateFormat() { super(); this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"); setCalendar(this.dateFormat.getCalendar()); setNumberFormat(this.dateFormat.getNumberFormat()); }
@Override public Object convertFromString(Class<?> cls, String str) { if (str.length() < 31 || str.charAt(26) != ':' || str.charAt(29) != '[' || str.charAt(str.length() - 1) != ']') { throw new IllegalArgumentException("Unable to parse date: " + str); } TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1)); String str2 = str.substring(0, 26) + str.substring(27, 29); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); GregorianCalendar cal = new GregorianCalendar(zone); cal.setTimeInMillis(0); f.setCalendar(cal); try { f.parseObject(str2); return f.getCalendar(); } catch (ParseException ex) { throw new RuntimeException(ex); } } },
@Override public synchronized Calendar getCalendar() { return format.getCalendar(); }
/** * {@inheritDoc} * * @deprecated as it is not considered to be thread safe. */ @Deprecated @Override public Calendar getCalendar() { return super.getCalendar(); }
public Calendar getCalendar() { return localSimpleDateFormat.get().getCalendar(); }
public Calendar getCalendar() { return localSimpleDateFormat.get().getCalendar(); }
/** * Returns a SimpleDateFormat for the given format string which is * configured with a compatible Calendar instance (see * {@link #toCompatibleCalendar}). */ public static SimpleDateFormat createDateFormat(String formatStr) { SimpleDateFormat sdf = new SimpleDateFormat(formatStr); toCompatibleCalendar(sdf.getCalendar()); return sdf; }
static SimpleDateFormat createSimpleDateFormat(String pt) { SimpleDateFormat sdf = new SimpleDateFormat(pt); ((GregorianCalendar) sdf.getCalendar()).setGregorianChange(new java.util.Date(Long.MIN_VALUE)); return sdf; }
/** * Constructor for dates from Strings */ public Date(String value) throws DateFormatException{ df = new SimpleDateFormat("yyyy-MM-dd"); try{ df.parse(value); calendar = (GregorianCalendar) df.getCalendar(); }catch (ParseException e){ throw new DateFormatException(); } }
public Object decode(String data) throws DataDecodeException { if (decoder == null) { throw new IllegalStateException("Calendar decoder not initialised. A decoder for this type (" + getClass().getName() + ") must be explicitly configured (unlike the primitive type decoders) with a date 'format'. See Javadoc."); } try { // Must be sync'd - DateFormat is not synchronized. synchronized(decoder) { decoder.parse(data.trim()); return decoder.getCalendar().clone(); } } catch (ParseException e) { throw new DataDecodeException("Error decoding Date data value '" + data + "' with decode format '" + format + "'.", e); } } }
public Object decode(String data) throws DataDecodeException { if (decoder == null) { throw new IllegalStateException("Calendar decoder not initialised. A decoder for this type (" + getClass().getName() + ") must be explicitly configured (unlike the primitive type decoders) with a date 'format'. See Javadoc."); } try { // Must be sync'd - DateFormat is not synchronized. synchronized(decoder) { decoder.parse(data.trim()); return decoder.getCalendar().clone(); } } catch (ParseException e) { throw new DataDecodeException("Error decoding Date data value '" + data + "' with decode format '" + format + "'.", e); } } }
public Object decode(String data) throws DataDecodeException { if (decoder == null) { throw new IllegalStateException("Calendar decoder not initialised. A decoder for this type (" + getClass().getName() + ") must be explicitly configured (unlike the primitive type decoders) with a date 'format'. See Javadoc."); } try { // Must be sync'd - DateFormat is not synchronized. synchronized(decoder) { decoder.parse(data.trim()); return decoder.getCalendar().clone(); } } catch (ParseException e) { throw new DataDecodeException("Error decoding Date data value '" + data + "' with decode format '" + format + "'.", e); } } }
public Object convertFromString(Class<?> cls, String str) { if (str.length() < 31 || str.charAt(26) != ':' || str.charAt(29) != '[' || str.charAt(str.length() - 1) != ']') { throw new IllegalArgumentException("Unable to parse date: " + str); } TimeZone zone = TimeZone.getTimeZone(str.substring(30, str.length() - 1)); str = str.substring(0, 26) + str.substring(27, 29); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); GregorianCalendar cal = new GregorianCalendar(zone); cal.setTimeInMillis(0); f.setCalendar(cal); try { f.parseObject(str); return f.getCalendar(); } catch (ParseException ex) { throw new RuntimeException(ex); } } },
private static void updateRawValues( RawValues rawValues, SimpleDateFormat sdf ) { if (rawValues != null) { rawValues.accept(new Parsed(XCalendar.class.cast(sdf.getCalendar()))); } }
public SafeDateFormat(String template) { this.formatter = ThreadLocal.withInitial(() -> { return new SimpleDateFormat(template); }); this.setCalendar(this.formatter.get().getCalendar()); this.setNumberFormat(this.formatter.get().getNumberFormat()); }
public IValue parseDateTime(IString inputDateTime, IString formatString) //@doc{Parse an input datetime given as a string using the given format string} { try { java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue()); fmt.setLenient(false); fmt.parse(inputDateTime.getValue()); java.util.Calendar cal = fmt.getCalendar(); int zoneHours = cal.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60); int zoneMinutes = (cal.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60; return values.datetime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND), zoneHours, zoneMinutes); } catch (IllegalArgumentException iae) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + " using format string: " + formatString.getValue(), null, null); } catch (ParseException e) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + " using format string: " + formatString.getValue(), null, null); } }
@Override public java.util.Calendar getCalendar() { Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_TEXT_SIMPLEDATEFORMAT, this, "getCalendar", "()Ljava/util/Calendar;", new Object[] {}); java.util.Calendar ret = new Calendar(super.getCalendar()); Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_TEXT_SIMPLEDATEFORMAT, this, ret); return ret; }
public IValue parseDateTimeInLocale(IString inputDateTime, IString formatString, IString locale) //@doc{Parse an input datetime given as a string using a specific locale and format string} { try { java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue(), new Locale(locale.getValue())); fmt.parse(inputDateTime.getValue()); java.util.Calendar cal = fmt.getCalendar(); int zoneHours = cal.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60); int zoneMinutes = (cal.get(Calendar.ZONE_OFFSET) / (1000 * 60)) % 60; return values.datetime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND), zoneHours, zoneMinutes); } catch (IllegalArgumentException iae) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null); } catch (ParseException e) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input datetime: " + inputDateTime.getValue() + " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null); } }
public IValue parseDate(IString inputDate, IString formatString) //@doc{Parse an input date given as a string using the given format string} { try { java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue()); fmt.parse(inputDate.getValue()); java.util.Calendar cal = fmt.getCalendar(); return values.date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE)); } catch (IllegalArgumentException iae) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + " using format string: " + formatString.getValue(), null, null); } catch (ParseException e) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + " using format string: " + formatString.getValue(), null, null); } }
public IValue parseDateInLocale(IString inputDate, IString formatString, IString locale) //@doc{Parse an input date given as a string using a specific locale and format string} { try { java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat(formatString.getValue(), new Locale(locale.getValue())); fmt.parse(inputDate.getValue()); java.util.Calendar cal = fmt.getCalendar(); return values.date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE)); } catch (IllegalArgumentException iae) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null); } catch (ParseException e) { throw RuntimeExceptionFactory.dateTimeParsingError("Cannot parse input date: " + inputDate.getValue() + " using format string: " + formatString.getValue() + " in locale: " + locale.getValue(), null, null); } }