public static void jsonDateChars(Calendar calendar, Date date, CharBuf buf) { jsonDateChars(calendar, date.getTime(), buf); }
public static void main( String... args ) { Sys.println( euroUTCSystemDateNowString() ); }
/** * Useful for generating string versions of timestamps * * @return euro style format. */ public static String euroUTCSystemDateNowString() { long now = System.currentTimeMillis(); return euroUTCSystemDateString( now ); }
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 () ) ); } }
String val = object.toString(); char[] chars = FastStringUtils.toCharArray(val); if (Dates.isISO8601QuickCheck(chars)) { return Dates.fromISO8601DateLoose(chars); } else if (Dates.isShortDate(chars)) { return Dates.fromISO8601DateLoose(chars); } else { return toDateUS(val); if (Dates.isISO8601QuickCheck(chars)) { return Dates.fromISO8601DateLoose(chars); } else if (Dates.isShortDate(chars)) { return Dates.fromISO8601DateLoose(chars); } else { return toDateUS(FastStringUtils.noCopyStringFromChars(chars));
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 toDate(Object object) { if (object instanceof Date) { return (Date) object; } else if (object instanceof Value) { return ((Value) object).dateValue(); } else if (object instanceof Calendar) { return ((Calendar) object).getTime(); } else if (object instanceof Long) { return new Date((long) object); } else if (object instanceof String) { String val = (String) object; char[] chars = FastStringUtils.toCharArray(val); if (Dates.isISO8601QuickCheck(chars)) { return Dates.fromISO8601DateLoose(chars); } else { return toDateUS(val); } } return null; }
public static Date fromISO8601DateLoose(char[] chars) { return fromISO8601DateLoose(chars, 0, chars.length); }
public static Date toEuroDate(String string) { String[] split = StringScanner.splitByChars(string, new char[]{'.', '\\', '/', ':'}); if (split.length == 3) { return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2])); } else if (split.length >= 6) { return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2]), toInt(split[3]), toInt(split[4]), toInt(split[5]) ); } else { Exceptions.die(String.format("Not able to parse %s into a Euro date", string)); return null; } }
public static Date toDateUS(String string) { String[] split = StringScanner.splitByChars(string, new char[]{'.', '\\', '/', ':'}); if (split.length == 3) { return Dates.getUSDate(toInt(split[0]), toInt(split[1]), toInt(split[2])); } else if (split.length >= 6) { return Dates.getUSDate(toInt(split[0]), toInt(split[1]), toInt(split[2]), toInt(split[3]), toInt(split[4]), toInt(split[5]) ); } else { Exceptions.die(String.format("Not able to parse %s into a US date", string)); return null; } }
public static Date fromISO8601Jackson(String string) { return fromISO8601Jackson(FastStringUtils.toCharArray(string), 0, string.length()); }
public static Date fromJsonDate( String string ) { return fromJsonDate( FastStringUtils.toCharArray(string), 0, string.length() ); }
public static Date fromISO8601( String string ) { return fromISO8601( FastStringUtils.toCharArray( string ), 0, string.length() ); }
public static void jsonDateChars( Calendar calendar, long milis, CharBuf buf ) { if (isGMT) { /* For the Unix admins of the world who avoid it all and just GMT it. */ fastJsonDateChars ( new Date(milis), buf ); return; } calendar.setTimeInMillis( milis ); int day = calendar.get( Calendar.DAY_OF_MONTH ); int month = calendar.get( Calendar.MONTH ) +1; int year = calendar.get( Calendar.YEAR ); int hour = calendar.get( Calendar.HOUR_OF_DAY ); int minute = calendar.get( Calendar.MINUTE ); int second = calendar.get( Calendar.SECOND ); int mili = calendar.get( Calendar.MILLISECOND ); buf.add( '"' ); buf.add( year ).add( '-' ); buf.add( Str.zfill( month, 2 ) ).add( '-' ); buf.add( Str.zfill ( day, 2 ) ).add('T'); buf.add( Str.zfill( hour, 2 ) ).add( ':' ); buf.add( Str.zfill( minute, 2 ) ).add( ':' ); buf.add( Str.zfill( second, 2 ) ).add( "." ); buf.add( Str.zfill( mili, 3 ) ).add( "Z" ); buf.add( '"' ); }
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 () ) ); } }
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 [] chars ) { return fromISO8601DateLoose( chars, 0, chars.length ); }
public static Date toEuroDate(String string) { String[] split = StringScanner.splitByChars(string, new char[]{'.', '\\', '/', ':'}); if (split.length == 3) { return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2])); } else if (split.length >= 6) { return Dates.getEuroDate(toInt(split[0]), toInt(split[1]), toInt(split[2]), toInt(split[3]), toInt(split[4]), toInt(split[5]) ); } else { Exceptions.die(String.format("Not able to parse %s into a Euro date", string)); return null; } }