Ejemplo n.º 1
0
 /**
  * Set the time from fields. The date part of this object will be unaffected.
  *
  * @param hour the hour
  * @param minuteOfHour the minute of the hour
  * @param secondOfMinute the second of the minute
  * @param millisOfSecond the millisecond of the second
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setTime(
     final int hour, final int minuteOfHour, final int secondOfMinute, final int millisOfSecond) {
   long instant =
       getChronology()
           .getDateTimeMillis(getMillis(), hour, minuteOfHour, secondOfMinute, millisOfSecond);
   setMillis(instant);
 }
Ejemplo n.º 2
0
 /**
  * Sets the status of rounding to use the specified field and mode. A null field or mode of
  * ROUND_NONE will disable rounding. Once set, the instant is then rounded using the new field and
  * mode.
  *
  * <p>Enabling rounding will cause all subsequent calls to {@link #setMillis(long)} to be rounded.
  * This can be used to control the precision of the instant, for example by setting a rounding
  * field of minuteOfDay, the seconds and milliseconds will always be zero.
  *
  * @param field rounding field or null to disable
  * @param mode rounding mode or ROUND_NONE to disable
  * @throws IllegalArgumentException if mode is unknown, no exception if field is null
  */
 public void setRounding(DateTimeField field, int mode) {
   if (field != null && (mode < ROUND_NONE || mode > ROUND_HALF_EVEN)) {
     throw new IllegalArgumentException("Illegal rounding mode: " + mode);
   }
   iRoundingField = (mode == ROUND_NONE ? null : field);
   iRoundingMode = (field == null ? ROUND_NONE : mode);
   setMillis(getMillis());
 }
Ejemplo n.º 3
0
  /**
   * 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);
  }
Ejemplo n.º 4
0
 /**
  * Set the date and time from fields.
  *
  * @param year the year
  * @param monthOfYear the month of the year
  * @param dayOfMonth the day of the month
  * @param hourOfDay the hour of the day
  * @param minuteOfHour the minute of the hour
  * @param secondOfMinute the second of the minute
  * @param millisOfSecond the millisecond of the second
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setDateTime(
     final int year,
     final int monthOfYear,
     final int dayOfMonth,
     final int hourOfDay,
     final int minuteOfHour,
     final int secondOfMinute,
     final int millisOfSecond) {
   long instant =
       getChronology()
           .getDateTimeMillis(
               year,
               monthOfYear,
               dayOfMonth,
               hourOfDay,
               minuteOfHour,
               secondOfMinute,
               millisOfSecond);
   setMillis(instant);
 }
Ejemplo n.º 5
0
 /**
  * Set the minute of the hour to the specified value.
  *
  * @param minuteOfHour the minute of hour
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setMinuteOfHour(final int minuteOfHour) {
   setMillis(getChronology().minuteOfHour().set(getMillis(), minuteOfHour));
 }
Ejemplo n.º 6
0
 /**
  * Sets the value of one of the fields of the instant, such as hourOfDay.
  *
  * @param type a field type, usually obtained from DateTimeFieldType, not null
  * @param value the value to set the field to
  * @throws IllegalArgumentException if the value is null or invalid
  */
 public void set(DateTimeFieldType type, int value) {
   if (type == null) {
     throw new IllegalArgumentException("Field must not be null");
   }
   setMillis(type.getField(getChronology()).set(getMillis(), value));
 }
Ejemplo n.º 7
0
 /**
  * Add a number of hours to the date.
  *
  * @param hours the hours to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addHours(final int hours) {
   setMillis(getChronology().hours().add(getMillis(), hours));
 }
Ejemplo n.º 8
0
 /**
  * Set the date from milliseconds. The time part of this object will be unaffected.
  *
  * @param instant an instant to copy the date from, time part ignored
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setDate(final long instant) {
   setMillis(getChronology().millisOfDay().set(instant, getMillisOfDay()));
 }
Ejemplo n.º 9
0
 /**
  * Add an amount of time to the datetime.
  *
  * @param duration the millis to add
  * @throws ArithmeticException if the result exceeds the capacity of the instant
  */
 public void add(long duration) {
   setMillis(FieldUtils.safeAdd(getMillis(), duration)); // set via this class not super
 }
Ejemplo n.º 10
0
 /**
  * Add a number of seconds to the date.
  *
  * @param seconds the seconds to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addSeconds(final int seconds) {
   setMillis(getChronology().seconds().add(getMillis(), seconds));
 }
Ejemplo n.º 11
0
 /**
  * Set the millis of the second to the specified value.
  *
  * @param millisOfSecond the millis of second
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setMillisOfSecond(final int millisOfSecond) {
   setMillis(getChronology().millisOfSecond().set(getMillis(), millisOfSecond));
 }
Ejemplo n.º 12
0
 /**
  * Set the week of weekyear to the specified value.
  *
  * @param weekOfWeekyear the week of the weekyear
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setWeekOfWeekyear(final int weekOfWeekyear) {
   setMillis(getChronology().weekOfWeekyear().set(getMillis(), weekOfWeekyear));
 }
Ejemplo n.º 13
0
 /**
  * Add a number of weeks to the date.
  *
  * @param weeks the weeks to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addWeeks(final int weeks) {
   setMillis(getChronology().weeks().add(getMillis(), weeks));
 }
Ejemplo n.º 14
0
 /**
  * Set the month of the year to the specified value.
  *
  * @param monthOfYear the month of the year
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setMonthOfYear(final int monthOfYear) {
   setMillis(getChronology().monthOfYear().set(getMillis(), monthOfYear));
 }
Ejemplo n.º 15
0
 /**
  * Add a number of months to the date.
  *
  * @param months the months to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addMonths(final int months) {
   setMillis(getChronology().months().add(getMillis(), months));
 }
Ejemplo n.º 16
0
 /**
  * Add a number of years to the date.
  *
  * @param years the years to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addYears(final int years) {
   setMillis(getChronology().years().add(getMillis(), years));
 }
Ejemplo n.º 17
0
 /**
  * Set the year to the specified value.
  *
  * @param year the year
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setYear(final int year) {
   setMillis(getChronology().year().set(getMillis(), year));
 }
Ejemplo n.º 18
0
 /**
  * Adds to the instant specifying the duration and multiple to add.
  *
  * @param type a field type, usually obtained from DateTimeFieldType, not null
  * @param amount the amount to add of this duration
  * @throws IllegalArgumentException if the value is null or invalid
  * @throws ArithmeticException if the result exceeds the capacity of the instant
  */
 public void add(DurationFieldType type, int amount) {
   if (type == null) {
     throw new IllegalArgumentException("Field must not be null");
   }
   setMillis(type.getField(getChronology()).add(getMillis(), amount));
 }
Ejemplo n.º 19
0
 /**
  * Set the second of the day to the specified value.
  *
  * @param secondOfDay the second of day
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setSecondOfDay(final int secondOfDay) {
   setMillis(getChronology().secondOfDay().set(getMillis(), secondOfDay));
 }
Ejemplo n.º 20
0
 /**
  * Set the day of year to the specified value.
  *
  * @param dayOfYear the day of the year
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setDayOfYear(final int dayOfYear) {
   setMillis(getChronology().dayOfYear().set(getMillis(), dayOfYear));
 }
Ejemplo n.º 21
0
 /**
  * Set the second of the minute to the specified value.
  *
  * @param secondOfMinute the second of minute
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setSecondOfMinute(final int secondOfMinute) {
   setMillis(getChronology().secondOfMinute().set(getMillis(), secondOfMinute));
 }
Ejemplo n.º 22
0
 /**
  * Set the day of the month to the specified value.
  *
  * @param dayOfMonth the day of the month
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setDayOfMonth(final int dayOfMonth) {
   setMillis(getChronology().dayOfMonth().set(getMillis(), dayOfMonth));
 }
Ejemplo n.º 23
0
 /**
  * Set the millis of the day to the specified value.
  *
  * @param millisOfDay the millis of day
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setMillisOfDay(final int millisOfDay) {
   setMillis(getChronology().millisOfDay().set(getMillis(), millisOfDay));
 }
Ejemplo n.º 24
0
 /**
  * Sets the millisecond instant of this instant from another.
  *
  * <p>This method does not change the chronology of this instant, just the millisecond instant.
  *
  * @param instant the instant to use, null means now
  */
 public void setMillis(ReadableInstant instant) {
   long instantMillis = DateTimeUtils.getInstantMillis(instant);
   setMillis(instantMillis); // set via this class not super
 }
Ejemplo n.º 25
0
 /**
  * Add a number of milliseconds to the date. The implementation of this method differs from the
  * {@link #add(long)} method in that a DateTimeField performs the addition.
  *
  * @param millis the milliseconds to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addMillis(final int millis) {
   setMillis(getChronology().millis().add(getMillis(), millis));
 }
Ejemplo n.º 26
0
 /**
  * Add a number of days to the date.
  *
  * @param days the days to add
  * @throws IllegalArgumentException if the value is invalid
  */
 public void addDays(final int days) {
   setMillis(getChronology().days().add(getMillis(), days));
 }
Ejemplo n.º 27
0
 /**
  * Set the time from milliseconds. The date part of this object will be unaffected.
  *
  * @param millis an instant to copy the time from, date part ignored
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setTime(final long millis) {
   int millisOfDay = ISOChronology.getInstanceUTC().millisOfDay().get(millis);
   setMillis(getChronology().millisOfDay().set(getMillis(), millisOfDay));
 }
Ejemplo n.º 28
0
 /**
  * Set the hour of the day to the specified value.
  *
  * @param hourOfDay the hour of day
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setHourOfDay(final int hourOfDay) {
   setMillis(getChronology().hourOfDay().set(getMillis(), hourOfDay));
 }
Ejemplo n.º 29
0
 /**
  * Set the day of week to the specified value.
  *
  * @param dayOfWeek the day of the week
  * @throws IllegalArgumentException if the value is invalid
  */
 public void setDayOfWeek(final int dayOfWeek) {
   setMillis(getChronology().dayOfWeek().set(getMillis(), dayOfWeek));
 }
Ejemplo n.º 30
0
 /**
  * Adds a period to this instant specifying how many times to add.
  *
  * <p>This will typically change the value of most fields.
  *
  * @param period the period to add, null means add zero
  * @param scalar direction and amount to add, which may be negative
  * @throws ArithmeticException if the result exceeds the capacity of the instant
  */
 public void add(ReadablePeriod period, int scalar) {
   if (period != null) {
     setMillis(getChronology().add(period, getMillis(), scalar)); // set via this class not super
   }
 }