/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
/** * Set the date from another instant. * The time part of this object will be unaffected. * <p> * If the input is a {@code ReadableDateTime} then it is converted to the * same time-zone as this object before using the instant millis. * * @param instant an instant to copy the date from, time part ignored * @throws IllegalArgumentException if the object is invalid */ public void setDate(final ReadableInstant instant) { long instantMillis = DateTimeUtils.getInstantMillis(instant); if (instant instanceof ReadableDateTime) { ReadableDateTime rdt = (ReadableDateTime) instant; Chronology instantChrono = DateTimeUtils.getChronology(rdt.getChronology()); DateTimeZone zone = instantChrono.getZone(); if (zone != null) { instantMillis = zone.getMillisKeepLocal(getZone(), instantMillis); } } setDate(instantMillis); }
@Override public XMLGregorianCalendar convertToDatum(Object timestamp) { if (timestamp == null) { return null; } long timestampMillis; if (timestamp instanceof Long) { timestampMillis = ((Long) timestamp).longValue(); } else if (timestamp instanceof Date) { timestampMillis = ((Date) timestamp).getTime(); } else { throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp); } MutableDateTime dateTime = new MutableDateTime(); dateTime.setMillis(timestampMillis); XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }
/** * Sets the time zone of the datetime, changing the chronology and millisecond. * <p> * Changing the zone using this method retains the field values. * The millisecond instant is adjusted in the new zone to compensate. * <p> * If the chronology already has this time zone, no change occurs. * * @param newZone the time zone to use, null means default zone * @see #setZone */ public void setZoneRetainFields(DateTimeZone newZone) { newZone = DateTimeUtils.getZone(newZone); DateTimeZone originalZone = DateTimeUtils.getZone(getZone()); if (newZone == originalZone) { return; } long millis = originalZone.getMillisKeepLocal(newZone, getMillis()); setChronology(getChronology().withZone(newZone)); // set via this class not super setMillis(millis); }