/** * Returns a copy of this datetime with different millis. * <p> * The returned object will be either be a new instance or <code>this</code>. * Only the millis will change, the chronology and time zone are kept. * * @param newMillis the new millis, from 1970-01-01T00:00:00Z * @return a copy of this datetime with different millis */ public DateTime withMillis(long newMillis) { return (newMillis == getMillis() ? this : new DateTime(newMillis, getChronology())); }
/** * Converts this object to a <code>LocalDate</code> with the * same date and chronology. * * @return a LocalDate with the same date and chronology * @since 1.3 */ public LocalDate toLocalDate() { return new LocalDate(getMillis(), getChronology()); }
@Test public void testDate() throws Exception { Date expected = new Date(new DateTime(2001, 2, 3, 4, 5, 6, DateTimeZone.UTC).getMillis()); AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance(); byte[] data = serializer.encode(DATE, expected); deserializeData(serializer, data); Date actual = serializer.getDate(COLUMN_NAME); // Convert milliseconds to days so they can be compared regardless of the time of day assertEquals(MILLISECONDS.toDays(actual.getTime()), MILLISECONDS.toDays(expected.getTime())); }
/** * Returns a copy of this datetime with the year of era field updated. * <p> * DateTime is immutable, so there are no set methods. * Instead, this method returns a new instance with the value of * year of era changed. * * @param yearOfEra the year of era to set * @return a copy of this object with the field set * @throws IllegalArgumentException if the value is invalid * @since 1.3 */ public DateTime withYearOfEra(int yearOfEra) { return withMillis(getChronology().yearOfEra().set(getMillis(), yearOfEra)); }
/** * Rounds to the nearest whole unit of this field on a copy of this DateTime, * favoring the ceiling if halfway. * * @return a copy of the DateTime with the field value changed */ public DateTime roundHalfCeilingCopy() { return iInstant.withMillis(iField.roundHalfCeiling(iInstant.getMillis())); }
/** * Sets this field in a copy of the DateTime. * <p> * The DateTime attached to this property is unchanged by this call. * This operation is faster than converting a DateTime to a MutableDateTime * and back again when setting one field. When setting multiple fields, * it is generally quicker to make the conversion to MutableDateTime. * * @param value the value to set the field in the copy to * @return a copy of the DateTime with the field value changed * @throws IllegalArgumentException if the value isn't valid */ public DateTime setCopy(int value) { return iInstant.withMillis(iField.set(iInstant.getMillis(), value)); }
/** * Returns a copy of this datetime with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
public TimestampStreamReader(StreamDescriptor streamDescriptor, DateTimeZone hiveStorageTimeZone, LocalMemoryContext systemMemoryContext) { this.streamDescriptor = requireNonNull(streamDescriptor, "stream is null"); this.baseTimestampInSeconds = new DateTime(2015, 1, 1, 0, 0, requireNonNull(hiveStorageTimeZone, "hiveStorageTimeZone is null")).getMillis() / MILLIS_PER_SECOND; this.systemMemoryContext = requireNonNull(systemMemoryContext, "systemMemoryContext is null"); }
/** * Returns a copy of this datetime with the year field updated. * <p> * DateTime is immutable, so there are no set methods. * Instead, this method returns a new instance with the value of * year changed. * * @param year the year to set * @return a copy of this object with the field set * @throws IllegalArgumentException if the value is invalid * @since 1.3 */ public DateTime withYear(int year) { return withMillis(getChronology().year().set(getMillis(), year)); }
/** * Returns a copy of this datetime with different millis. * <p> * The returned object will be either be a new instance or <code>this</code>. * Only the millis will change, the chronology and time zone are kept. * * @param newMillis the new millis, from 1970-01-01T00:00:00Z * @return a copy of this datetime with different millis */ public DateTime withMillis(long newMillis) { return (newMillis == getMillis() ? this : new DateTime(newMillis, getChronology())); }
/** * Converts this object to a <code>TimeOfDay</code> using the * same millis and chronology. * * @return a TimeOfDay using the same millis and chronology * @deprecated Use LocalTime instead of TimeOfDay */ @Deprecated public TimeOfDay toTimeOfDay() { return new TimeOfDay(getMillis(), getChronology()); }
/** * Rounds to the lowest whole unit of this field on a copy of this DateTime. * * @return a copy of the DateTime with the field value changed */ public DateTime roundFloorCopy() { return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); }
/** * Sets this field in a copy of the DateTime to a parsed text value. * <p> * The DateTime attached to this property is unchanged by this call. * This operation is faster than converting a DateTime to a MutableDateTime * and back again when setting one field. When setting multiple fields, * it is generally quicker to make the conversion to MutableDateTime. * * @param text the text value to set * @param locale optional locale to use for selecting a text symbol * @return a copy of the DateTime with the field value changed * @throws IllegalArgumentException if the text value isn't valid */ public DateTime setCopy(String text, Locale locale) { return iInstant.withMillis(iField.set(iInstant.getMillis(), text, locale)); }
/** * Returns a copy of this datetime with the partial set of fields replacing those * from this instance. * <p> * For example, if the partial is a <code>TimeOfDay</code> then the time fields * would be changed in the returned instance. * If the partial is null, then <code>this</code> is returned. * * @param partial the partial set of fields to apply to this datetime, null ignored * @return a copy of this datetime with a different set of fields * @throws IllegalArgumentException if any value is invalid */ public DateTime withFields(ReadablePartial partial) { if (partial == null) { return this; } return withMillis(getChronology().set(partial, getMillis())); }
/** * Returns a copy of this datetime with the month of year field updated. * <p> * DateTime is immutable, so there are no set methods. * Instead, this method returns a new instance with the value of * month of year changed. * * @param monthOfYear the month of year to set * @return a copy of this object with the field set * @throws IllegalArgumentException if the value is invalid * @since 1.3 */ public DateTime withMonthOfYear(int monthOfYear) { return withMillis(getChronology().monthOfYear().set(getMillis(), monthOfYear)); }