/** * Returns an encoding of the given {@link Temporal} that complies with <code>xs:date</code>. * <p> * The returned format is <code<YYYY-MM-DD[TZ]</code>. The timezone is used from the {@link Temporal} object, if * time zone is unknown {@link Temporal#isTimeZoneUnknown()}, no time zone information is appended (= local * time). * </p> * * @param date * point in time to be encoded, must not be <code>null</code> * @return encoded <code>xs:date</code>, never <code>null</code> */ public static String formatDate( Temporal date ) { TimeZone tz = date.getCalendar().getTimeZone(); SimpleDateFormat sdf = new SimpleDateFormat( ISO_8601_2004_FORMAT_DATE ); sdf.setTimeZone( tz ); String s = sdf.format( date.getDate() ); if ( !date.isTimeZoneUnknown() ) { s += getTzString( tz, date.getTimeInMilliseconds() ); } return s; }
public TimeGeometricPrimitive createPeriodOrInstant( final Temporal begin, final Temporal end ) { if ( begin != null && begin.equals( end ) ) { return createInstant( begin ); } return createPeriod( begin, end ); }
theVal = (Date) o; } else if ( o instanceof Temporal ) { theVal = ( (Temporal) o ).getDate(); } else { throw new RuntimeException( "Unexpected dimension value class: " + o.getClass() );
public static int compareBegin( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ) { final Temporal beginA = new TemporalConverter().convert( begin( a ) ); final Temporal beginB = new TemporalConverter().convert( begin( b ) ); if ( beginA == null && beginB == null ) { return 0; } else if ( beginA == null ) { return -1; } else if ( beginB == null ) { return 1; } return beginA.compareTo( beginB ); }
/** * TODO handling of SQL timezone * * @param input * @return */ protected Timestamp toSqlTimestamp( Object input ) { if ( input instanceof Timestamp ) { return (Timestamp) input; } Timestamp value = null; if ( input instanceof java.util.Date ) { java.util.Date date = (java.util.Date) input; value = new Timestamp( date.getTime() ); } else if ( input instanceof Temporal ) { Temporal timeInstant = (Temporal) input; value = new Timestamp( timeInstant.getTimeInMilliseconds() ); } else { String s = input.toString(); if ( s.isEmpty() ) { return null; } DateTime timeInstant = parseDateTime( s ); value = toSqlTimestamp( timeInstant ); } return value; }
public static int compareBeginWithEnd( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ) { final Temporal beginA = new TemporalConverter().convert( begin( a ) ); final Temporal endB = new TemporalConverter().convert( end( b ) ); if ( beginA == null && endB == null ) { return -1; } else if ( beginA == null ) { return -1; } else if ( endB == null ) { return -1; } int compared = beginA.compareTo( endB ); if ( compared == 0 && b instanceof TimeInstant ) { return -1; } return compared; }
/** * TODO handling of SQL timezone * * @param input * @return */ protected java.sql.Date toSqlDate( Object input ) { if ( input instanceof java.sql.Date ) { return (java.sql.Date) input; } java.sql.Date value = null; if ( input instanceof java.util.Date ) { java.util.Date date = (java.util.Date) input; value = new java.sql.Date( date.getTime() ); } else if ( input instanceof Temporal ) { Temporal timeInstant = (Temporal) input; value = new java.sql.Date( timeInstant.getTimeInMilliseconds() ); } else { String s = input.toString(); Date timeInstant = parseDate( s ); value = toSqlDate( timeInstant ); } return value; }
/** * Returns an encoding of the given {@link Temporal} that complies with <code>xs:time</code>. * <p> * The returned format is <code>hh:mm:ss[.SSS][TZ]</code>. The timezone is used from the {@link Temporal} object, * if time zone is unknown {@link Temporal#isTimeZoneUnknown()}, no time zone information is appended (= local * time). * </p> * * @param date * point in time to be encoded, must not be <code>null</code> * @return encoded <code>xs:date</code>, never <code>null</code> */ public static String formatTime( Temporal date ) { TimeZone tz = date.getCalendar().getTimeZone(); SimpleDateFormat sdf = null; if ( date.getCalendar().get( MILLISECOND ) == 0 ) { sdf = new SimpleDateFormat( ISO_8601_2004_FORMAT_TIME_NO_MS ); } else { sdf = new SimpleDateFormat( ISO_8601_2004_FORMAT_TIME ); } sdf.setTimeZone( tz ); String s = sdf.format( date.getDate() ); if ( !date.isTimeZoneUnknown() ) { s += getTzString( tz, date.getTimeInMilliseconds() ); } return s; }
/** * Compares the end of a with the begin of b. * * @param a * never <code>null</code> * @param b * never <code>null</code> * @return -1 if the end of a is before the begin of b; 0 if a and b are the equal or a and/or b are UNKNOWN; 1 if * the end of a is after the begin of b * @throws NullPointerException * if a and/or b is <code>null</code> */ public static int compareEndWithBegin( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ) { final Temporal endA = new TemporalConverter().convert( end( a ) ); final Temporal beginB = new TemporalConverter().convert( begin( b ) ); if ( endA == null || beginB == null ) return 0; return endA.compareTo( beginB ); }
/** * TODO handling of SQL timezone * * @param input * @return */ private java.sql.Time toSqlTime( Object input ) { if ( input instanceof java.sql.Time ) { return (java.sql.Time) input; } java.sql.Time value = null; if ( input instanceof java.util.Date ) { java.util.Date date = (java.util.Date) input; value = new java.sql.Time( date.getTime() ); } else if ( input instanceof Temporal ) { Temporal timeInstant = (Temporal) input; value = new java.sql.Time( timeInstant.getTimeInMilliseconds() ); } else { String s = input.toString(); Time timeInstant = parseTime( s ); value = toSqlTime( timeInstant ); } return value; }
private boolean equalsParsed( final String v1, final String v2 ) { try { final Temporal d1 = new TemporalConverter().convert( v1 ); final Temporal d2 = new TemporalConverter().convert( v2 ); return d1.equals( d2 ); } catch ( IllegalArgumentException e ) { // nothing to do } return false; }
/** * Returns an encoding of the given {@link Temporal} that complies with <code>xs:dateTime</code>. * <p> * The returned format is <code<YYYY-MM-DDThh:mm:ss[.SSS][TZ]</code>. The timezone is used from the * {@link Temporal} object, if time zone is unknown {@link Temporal#isTimeZoneUnknown()}, no time zone * information is appended (= local time). * </p> * * @param date * point in time to be encoded, must not be <code>null</code> * @return encoded <code>xs:dateTime</code>, never <code>null</code> */ public static String formatDateTime( Temporal date ) { TimeZone tz = date.getCalendar().getTimeZone(); SimpleDateFormat sdf = null; if ( date.getCalendar().get( MILLISECOND ) == 0 ) { sdf = new SimpleDateFormat( ISO_8601_2004_FORMAT_DATE_TIME_NO_MS ); } else { sdf = new SimpleDateFormat( ISO_8601_2004_FORMAT_DATE_TIME ); } sdf.setTimeZone( tz ); String s = sdf.format( date.getDate() ); if ( !date.isTimeZoneUnknown() ) { s += getTzString( tz, date.getTimeInMilliseconds() ); } return s; }
public static int compareEnd( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ) { final Temporal endA = new TemporalConverter().convert( end( a ) ); final Temporal endB = new TemporalConverter().convert( end( b ) ); if ( endA == null && endB == null ) { return 0; } else if ( endA == null ) { return 1; } else if ( endB == null ) { return -1; } final int compared = endA.compareTo( endB ); if ( compared == 0 ) { if ( a instanceof TimePeriod && b instanceof TimeInstant ) { return -1; } if ( a instanceof TimeInstant && b instanceof TimePeriod ) { return 1; } } return compared; }
case DATE: sqlValue = new java.sql.Date( ( (Temporal) value ).getTimeInMilliseconds() ); break; case DATE_TIME: sqlValue = new Timestamp( ( (Temporal) value ).getTimeInMilliseconds() ); break; case TIME: sqlValue = new Time( ( (Temporal) value ).getTimeInMilliseconds() ); break; case DECIMAL: