dstIdx = append00(res, dstIdx, x); dstIdx = append00(res, dstIdx, x); dstIdx = append00(res, dstIdx, x); dstIdx = append00(res, dstIdx, x); dstIdx = append00(res, dstIdx, x); } else { res[dstIdx++] = positive ? '+' : '-'; dstIdx = append00(res, dstIdx, offH); res[dstIdx++] = ':'; dstIdx = append00(res, dstIdx, offM); if (offS != 0) { res[dstIdx++] = ':'; dstIdx = append00(res, dstIdx, offS);
@Override protected String format(Date date, boolean datePart, boolean timePart, boolean offsetPart, int accuracy, TimeZone timeZone, DateToISO8601CalendarFactory calendarFactory) { return DateUtil.dateToISO8601String( date, datePart, timePart, timePart && offsetPart, accuracy, timeZone, calendarFactory); }
/** * Returns the time zone object for the name (or ID). This differs from * {@link TimeZone#getTimeZone(String)} in that the latest returns GMT * if it doesn't recognize the name, while this throws an * {@link UnrecognizedTimeZoneException}. * * @throws UnrecognizedTimeZoneException If the time zone name wasn't understood */ public static TimeZone getTimeZone(String name) throws UnrecognizedTimeZoneException { if (isGMTish(name)) { if (name.equalsIgnoreCase("UTC")) { return UTC; } return TimeZone.getTimeZone(name); } TimeZone tz = TimeZone.getTimeZone(name); if (isGMTish(tz.getID())) { throw new UnrecognizedTimeZoneException(name); } return tz; }
NullArgumentException.check("defaultTZ", defaultTZ); try { int year = groupToInt(m.group(1), "year", Integer.MIN_VALUE, Integer.MAX_VALUE); int month = groupToInt(m.group(2), "month", 1, 12) - 1; int day = groupToInt(m.group(3), "day-of-month", 1, 31); TimeZone tz = xsMode ? parseMatchingTimeZone(m.group(4), defaultTZ) : defaultTZ;
int hours = groupToInt(m.group(1), "hour-of-day", 0, 24); boolean hourWas24; if (hours == 24) { int minutes = minutesStr != null ? groupToInt(minutesStr, "minute", 0, 59) : 0; int secs = secsStr != null ? groupToInt(secsStr, "second", 0, 60) : 0; int millisecs = groupToMillisecond(m.group(4)); TimeZone tz = parseMatchingTimeZone(m.group(5), defaultTZ);
String tzName = EvalUtil.modelToString((TemplateScalarModel) tzArgTM, null, null); try { tzArg = DateUtil.getTimeZone(tzName); } catch (UnrecognizedTimeZoneException e) { throw new _TemplateModelException( return new SimpleScalar(DateUtil.dateToISO8601String( date, dateType != TemplateDateModel.TIME,
private static int groupToMillisecond(String g) throws DateParseException { if (g == null) { return 0; } if (g.length() > 3) { g = g.substring(0, 3); } int i = groupToInt(g, "partial-seconds", 0, Integer.MAX_VALUE); return g.length() == 1 ? i * 100 : (g.length() == 2 ? i * 10 : i); }
/** * Same as {@link #dateToISO8601String}, but gives XML Schema compliant format. */ public static String dateToXSString( Date date, boolean datePart, boolean timePart, boolean offsetPart, int accuracy, TimeZone timeZone, DateToISO8601CalendarFactory calendarFactory) { return dateToString(date, datePart, timePart, offsetPart, accuracy, timeZone, true, calendarFactory); }
/** * Same as {@link #parseXSDate(String, TimeZone, CalendarFieldsToDateConverter)}, but for ISO 8601 dates. */ public static Date parseISO8601Date( String dateStr, TimeZone defaultTimeZone, CalendarFieldsToDateConverter calToDateConverter) throws DateParseException { Matcher m = PATTERN_ISO8601_EXTENDED_DATE.matcher(dateStr); if (!m.matches()) { m = PATTERN_ISO8601_BASIC_DATE.matcher(dateStr); if (!m.matches()) { throw new DateParseException("The value didn't match the expected pattern: " + PATTERN_ISO8601_EXTENDED_DATE + " or " + PATTERN_ISO8601_BASIC_DATE); } } return parseDate_parseMatcher( m, defaultTimeZone, false, calToDateConverter); }
/** * Same as {@link #parseXSDateTime(String, TimeZone, CalendarFieldsToDateConverter)} but for ISO 8601 format. */ public static Date parseISO8601DateTime( String dateTimeStr, TimeZone defaultTZ, CalendarFieldsToDateConverter calToDateConverter) throws DateParseException { Matcher m = PATTERN_ISO8601_EXTENDED_DATE_TIME.matcher(dateTimeStr); if (!m.matches()) { m = PATTERN_ISO8601_BASIC_DATE_TIME.matcher(dateTimeStr); if (!m.matches()) { throw new DateParseException("The value (" + dateTimeStr + ") didn't match the expected pattern: " + PATTERN_ISO8601_EXTENDED_DATE_TIME + " or " + PATTERN_ISO8601_BASIC_DATE_TIME); } } return parseDateTime_parseMatcher( m, defaultTZ, false, calToDateConverter); }
@Override protected String format(Date date, boolean datePart, boolean timePart, boolean offsetPart, int accuracy, TimeZone timeZone, DateToISO8601CalendarFactory calendarFactory) { return DateUtil.dateToXSString( date, datePart, timePart, offsetPart, accuracy, timeZone, calendarFactory); }
NullArgumentException.check("defaultTZ", defaultTZ); try { int year = groupToInt(m.group(1), "year", Integer.MIN_VALUE, Integer.MAX_VALUE); int month = groupToInt(m.group(2), "month", 1, 12) - 1; int day = groupToInt(m.group(3), "day-of-month", 1, 31); int hours = groupToInt(m.group(4), "hour-of-day", 0, 24); boolean hourWas24; if (hours == 24) { int minutes = minutesStr != null ? groupToInt(minutesStr, "minute", 0, 59) : 0; int secs = secsStr != null ? groupToInt(secsStr, "second", 0, 60) : 0; int millisecs = groupToMillisecond(m.group(7)); TimeZone tz = parseMatchingTimeZone(m.group(8), defaultTZ);
String tzName = ((TemplateScalarModel) tzArgTM).getAsString(); try { tzArg = DateUtil.getTimeZone(tzName); } catch (UnrecognizedTimeZoneException e) { throw new TemplateModelException( return new SimpleScalar(DateUtil.dateToISO8601String( date, dateType != TemplateDateModel.TIME,
NullArgumentException.check("defaultTZ", defaultTZ); try { int year = groupToInt(m.group(1), "year", Integer.MIN_VALUE, Integer.MAX_VALUE); int month = groupToInt(m.group(2), "month", 1, 12) - 1; int day = groupToInt(m.group(3), "day-of-month", 1, 31); TimeZone tz = xsMode ? parseMatchingTimeZone(m.group(4), defaultTZ) : defaultTZ;
private static TimeZone parseMatchingTimeZone( String s, TimeZone defaultZone) throws DateParseException { if (s == null) { return defaultZone; } if (s.equals("Z")) { return DateUtil.UTC; } StringBuilder sb = new StringBuilder(9); sb.append("GMT"); sb.append(s.charAt(0)); String h = s.substring(1, 3); groupToInt(h, "offset-hours", 0, 23); sb.append(h); String m; int ln = s.length(); if (ln > 3) { int startIdx = s.charAt(3) == ':' ? 4 : 3; m = s.substring(startIdx, startIdx + 2); groupToInt(m, "offset-minutes", 0, 59); sb.append(':'); sb.append(m); } return TimeZone.getTimeZone(sb.toString()); }
TimeZone timeZone, DateToISO8601CalendarFactory calendarFactory) { return dateToString(date, datePart, timePart, offsetPart, accuracy, timeZone, false, calendarFactory);
/** * Parses an W3C XML Schema date string (not time or date-time). * Unlike in ISO 8601:2000 Second Edition, year -1 means B.C 1, and year 0 is invalid. * * @param dateStr the string to parse. * @param defaultTimeZone used if the date doesn't specify the * time zone offset explicitly. Can't be {@code null}. * @param calToDateConverter Used internally to calculate the result from the calendar field values. * If you don't have a such object around, you can just use * {@code new }{@link TrivialCalendarFieldsToDateConverter}{@code ()}. * * @throws DateParseException if the date is malformed, or if the time * zone offset is unspecified and the {@code defaultTimeZone} is * {@code null}. */ public static Date parseXSDate( String dateStr, TimeZone defaultTimeZone, CalendarFieldsToDateConverter calToDateConverter) throws DateParseException { Matcher m = PATTERN_XS_DATE.matcher(dateStr); if (!m.matches()) { throw new DateParseException("The value didn't match the expected pattern: " + PATTERN_XS_DATE); } return parseDate_parseMatcher( m, defaultTimeZone, true, calToDateConverter); }
/** * Parses an W3C XML Schema date-time string (not date or time). * Unlike in ISO 8601:2000 Second Edition, year -1 means B.C 1, and year 0 is invalid. * * @param dateTimeStr the string to parse. * @param defaultTZ used if the dateTime doesn't specify the * time zone offset explicitly. Can't be {@code null}. * * @throws DateParseException if the dateTime is malformed. */ public static Date parseXSDateTime( String dateTimeStr, TimeZone defaultTZ, CalendarFieldsToDateConverter calToDateConverter) throws DateParseException { Matcher m = PATTERN_XS_DATE_TIME.matcher(dateTimeStr); if (!m.matches()) { throw new DateParseException( "The value didn't match the expected pattern: " + PATTERN_XS_DATE_TIME); } return parseDateTime_parseMatcher( m, defaultTZ, true, calToDateConverter); }
@Override protected String format(Date date, boolean datePart, boolean timePart, boolean offsetPart, int accuracy, TimeZone timeZone, DateToISO8601CalendarFactory calendarFactory) { return DateUtil.dateToXSString( date, datePart, timePart, offsetPart, accuracy, timeZone, calendarFactory); }
int hours = groupToInt(m.group(1), "hour-of-day", 0, 24); boolean hourWas24; if (hours == 24) { int minutes = minutesStr != null ? groupToInt(minutesStr, "minute", 0, 59) : 0; int secs = secsStr != null ? groupToInt(secsStr, "second", 0, 60) : 0; int millisecs = groupToMillisecond(m.group(4)); TimeZone tz = parseMatchingTimeZone(m.group(5), defaultTZ);