protected DateTime getCurrentDateTimeWithoutMilliseconds() { long msSince1970 = new Date().getTime(); msSince1970 = msSince1970 / 1000 * 1000; return new DateTime( new Date( msSince1970 ), GMT ); }
@Override public DateTime toTimeZone( TimeZone tz ) { Calendar cal = null; if ( tz == null ) { cal = getInstance(); } else { cal = getInstance( tz ); } cal.setTimeInMillis( this.cal.getTimeInMillis() ); return new DateTime( cal, tz == null ); }
protected PrimitiveValue toDateTimeParticle( Object sqlValue ) { Temporal value = null; if ( sqlValue instanceof java.util.Date ) { Calendar cal = Calendar.getInstance(); cal.setTime( (java.util.Date) sqlValue ); value = new DateTime( cal, true ); } else if ( sqlValue != null ) { throw new IllegalArgumentException( "Unable to convert SQL result value of type '" + sqlValue.getClass() + "' to DateTime particle." ); } return new PrimitiveValue( value, pt ); }
@Deprecated public static String formatDateTime( java.util.Date date ) { return formatDateTime( new DateTime( date, GMT ) ); }
/** * Returns the point in time that is at the beginning of this duration (relative to the given {@link DateTime}. * * @param end * end of the duration interval, must not be <code>null</code> * @return the point in time that marks the begin of the duration interval, never <code>null</code> */ public DateTime getBegin( DateTime end ) { Calendar before = Calendar.getInstance( end.getCalendar().getTimeZone() ); before.setTime( end.getDate() ); before.add( Calendar.YEAR, -years ); before.add( Calendar.MONTH, -months ); before.add( Calendar.DAY_OF_MONTH, -days ); before.add( Calendar.HOUR_OF_DAY, -hours ); before.add( Calendar.MINUTE, -minutes ); before.add( Calendar.SECOND, -seconds ); return new DateTime( before, end.isTimeZoneUnknown() ); }
/** * Returns the point in time that is at the end of this duration (relative to the given {@link DateTime}. * * @param begin * begin of the duration interval, must not be <code>null</code> * @return the point in time that marks the end of the duration interval, never <code>null</code> */ public DateTime getEnd( DateTime begin ) { Calendar after = Calendar.getInstance( begin.getCalendar().getTimeZone() ); after.setTime( begin.getDate() ); after.add( Calendar.YEAR, years ); after.add( Calendar.MONTH, months ); after.add( Calendar.DAY_OF_MONTH, days ); after.add( Calendar.HOUR_OF_DAY, hours ); after.add( Calendar.MINUTE, minutes ); after.add( Calendar.SECOND, seconds ); return new DateTime( after, begin.isTimeZoneUnknown() ); }
public Temporal convert( final TimePosition t ) { final IndeterminateValue indeterminateness = t.getIndeterminatePosition(); if ( indeterminateness == NOW ) { return new DateTime( new Date(), null ); } else if ( indeterminateness == UNKNOWN ) { return null; } else if ( indeterminateness != null ) { throw new UnsupportedOperationException(); } return convert( t.getValue() ); }
private static double getAsDouble( final Object o ) { if ( o instanceof Double ) { return (Double) o; } if ( o instanceof Integer ) { return (Integer) o; } if ( o instanceof Long ) { return (Long) o; } if ( o instanceof Date ) { return ( (Date) o ).getTime(); } if ( o instanceof Duration ) { return ( (Duration) o ).getEnd( new DateTime( new Date( 0 ), null ) ).getTimeInMilliseconds(); } return 0; // what else? }
/** * Parses the given <code>xs:dateTime</code> string. * * @param xsDateTime * the <code>xs:dateTime</code> to be parsed, must not be <code>null</code> * @return the parsed date, never <code>null</code> (available timezone information is kept) * @throws IllegalArgumentException * if parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for * <code>xs:dateTime</code> */ public static DateTime parseDateTime( final String xsDateTime ) throws IllegalArgumentException { Calendar cal = DatatypeConverter.parseDateTime( xsDateTime ); boolean isTimeZoneUnknown = isLocal( xsDateTime ); return new DateTime( cal, isTimeZoneUnknown ); }