public static boolean isJsonDate( String str ) { return isJsonDate(FastStringUtils.toCharArray(str), 0, str.length()); }
public static boolean isJsonDate(String str) { return isJsonDate(FastStringUtils.toCharArray(str), 0, str.length()); }
public static long toLong(Object obj, final long longDefault) { if (obj instanceof Long) { return (Long) obj; } if (obj instanceof Number) { return ((Number) obj).longValue(); } else if (obj instanceof CharSequence) { String str = Str.toString(obj); if (Dates.isJsonDate(str)) { return Dates.fromJsonDate(str).getTime(); } try { return StringScanner.parseLong(str); } catch (Exception ex) { return longDefault; } } else if (obj instanceof Date) { return ((Date) obj).getTime(); } else { return toInt(obj); } }
public static long toLong(Object obj, final long longDefault) { if (obj instanceof Long) { return (Long) obj; } if (obj instanceof Number) { return ((Number) obj).longValue(); } else if (obj instanceof CharSequence) { String str = Str.toString(obj); if (Dates.isJsonDate(str)) { return Dates.fromJsonDate(str).getTime(); } try { return StringScanner.parseLong(str); } catch (Exception ex) { return longDefault; } } else if (obj instanceof Date) { return ((Date) obj).getTime(); } else { return toInt(obj); } }
public static Date fromISO8601DateLoose( char[] buffer, int startIndex, int endIndex ) { if ( Dates.isISO8601QuickCheck( buffer, startIndex, endIndex ) ) { if ( Dates.isJsonDate( buffer, startIndex, endIndex ) ) { return Dates.fromJsonDate( buffer, startIndex, endIndex ); } else if ( Dates.isISO8601( buffer, startIndex, endIndex ) ) { return Dates.fromISO8601( buffer, startIndex, endIndex ); } else { try { return looseParse( buffer, startIndex, endIndex ); } catch ( Exception ex ) { throw new IllegalStateException( "unable to do a loose parse", ex ); } } } else { try { return looseParse( buffer, startIndex, endIndex ); } catch ( Exception ex ) { throw new IllegalStateException( "unable to do a loose parse", ex ); } } }
public static Date fromISO8601DateLoose(char[] buffer, int startIndex, int endIndex) { if (Dates.isISO8601QuickCheck(buffer, startIndex, endIndex)) { if (Dates.isJsonDate(buffer, startIndex, endIndex)) { return Dates.fromJsonDate(buffer, startIndex, endIndex); } else if (Dates.isISO8601(buffer, startIndex, endIndex)) { return Dates.fromISO8601(buffer, startIndex, endIndex); } else { try { return looseParse(buffer, startIndex, endIndex); } catch (Exception ex) { throw new IllegalStateException("unable to do a loose parse", ex); } } } else { try { return looseParse(buffer, startIndex, endIndex); } catch (Exception ex) { throw new IllegalStateException("unable to do a loose parse", ex); } } }
@Override public Date dateValue () { if ( type == TypeType.STRING ) { if ( Dates.isISO8601QuickCheck ( buffer, startIndex, endIndex ) ) { if ( Dates.isJsonDate ( buffer, startIndex, endIndex ) ) { return Dates.fromJsonDate ( buffer, startIndex, endIndex ); } else if ( Dates.isISO8601Jackson(buffer, startIndex, endIndex) ) { return Dates.fromISO8601Jackson(buffer, startIndex, endIndex); } else if ( Dates.isISO8601 ( buffer, startIndex, endIndex ) ) { return Dates.fromISO8601 ( buffer, startIndex, endIndex ); } else { throw new IllegalStateException( "Unable to convert " + stringValue () + " to date " ); } } else { throw new IllegalStateException ( "Unable to convert " + stringValue () + " to date " ); } } else { return new Date ( Dates.utc ( longValue () ) ); } }
@Override public Date dateValue () { if ( type == TypeType.STRING ) { if ( Dates.isISO8601QuickCheck ( buffer, startIndex, endIndex ) ) { if ( Dates.isJsonDate ( buffer, startIndex, endIndex ) ) { return Dates.fromJsonDate ( buffer, startIndex, endIndex ); } else if ( Dates.isISO8601Jackson(buffer, startIndex, endIndex) ) { return Dates.fromISO8601Jackson(buffer, startIndex, endIndex); } else if ( Dates.isISO8601 ( buffer, startIndex, endIndex ) ) { return Dates.fromISO8601 ( buffer, startIndex, endIndex ); } else { throw new IllegalStateException( "Unable to convert " + stringValue () + " to date " ); } } else { throw new IllegalStateException ( "Unable to convert " + stringValue () + " to date " ); } } else { return new Date ( Dates.utc ( longValue () ) ); } }
public static Date fromJsonDate( char[] charArray, int from, int to ) { try { if ( isJsonDate( charArray, from, to ) ) { int year = CharScanner.parseInt(charArray, from + 0, from + 4); int month = CharScanner.parseInt(charArray, from + 5, from + 7); int day = CharScanner.parseInt(charArray, from + 8, from + 10); int hour = CharScanner.parseInt(charArray, from + 11, from + 13); int minute = CharScanner.parseInt(charArray, from + 14, from + 16); int second = CharScanner.parseInt(charArray, from + 17, from + 19); int milliseconds = CharScanner.parseInt(charArray, from + 20, from + 23); TimeZone tz = GMT; return toDate( tz, year, month, day, hour, minute, second, milliseconds ); } else { return null; } } catch (Exception ex) { return null; } }
public static Date fromJsonDate(char[] charArray, int from, int to) { try { if (isJsonDate(charArray, from, to)) { int year = CharScanner.parseInt(charArray, from + 0, from + 4); int month = CharScanner.parseInt(charArray, from + 5, from + 7); int day = CharScanner.parseInt(charArray, from + 8, from + 10); int hour = CharScanner.parseInt(charArray, from + 11, from + 13); int minute = CharScanner.parseInt(charArray, from + 14, from + 16); int second = CharScanner.parseInt(charArray, from + 17, from + 19); int milliseconds = CharScanner.parseInt(charArray, from + 20, from + 23); TimeZone tz = GMT; return toDate(tz, year, month, day, hour, minute, second, milliseconds); } else { return null; } } catch (Exception ex) { return null; } }
Date date = null; if ( Dates.isISO8601QuickCheck ( buffer, startIndex, endIndex ) ) { if (Dates.isJsonDate ( buffer,startIndex, endIndex )) { date = Dates.fromJsonDate ( buffer, startIndex, endIndex ); } else if (Dates.isISO8601( buffer, startIndex, endIndex )) {
Date date = null; if ( Dates.isISO8601QuickCheck ( buffer, startIndex, endIndex ) ) { if (Dates.isJsonDate ( buffer,startIndex, endIndex )) { date = Dates.fromJsonDate ( buffer, startIndex, endIndex ); } else if (Dates.isISO8601( buffer, startIndex, endIndex )) {