Class RemainderDateTimeField


  • public class RemainderDateTimeField
    extends DecoratedDateTimeField
    Counterpart remainder datetime field to DividedDateTimeField. The field's unit duration is unchanged, but the range duration is scaled accordingly.

    RemainderDateTimeField is thread-safe and immutable.

    Since:
    1.0
    See Also:
    DividedDateTimeField
    • Constructor Detail

      • RemainderDateTimeField

        public RemainderDateTimeField​(DateTimeField field,
                                      DateTimeFieldType type,
                                      int divisor)
        Constructor.
        Parameters:
        field - the field to wrap, like "year()".
        type - the field type this field actually uses
        divisor - divisor, such as 100 years in a century
        Throws:
        java.lang.IllegalArgumentException - if divisor is less than two
      • RemainderDateTimeField

        public RemainderDateTimeField​(DateTimeField field,
                                      DurationField rangeField,
                                      DateTimeFieldType type,
                                      int divisor)
        Constructor.
        Parameters:
        field - the field to wrap, like "year()".
        rangeField - the range field
        type - the field type this field actually uses
        divisor - divisor, such as 100 years in a century
        Throws:
        java.lang.IllegalArgumentException - if divisor is less than two
      • RemainderDateTimeField

        public RemainderDateTimeField​(DividedDateTimeField dividedField)
        Construct a RemainderDateTimeField that compliments the given DividedDateTimeField.
        Parameters:
        dividedField - complimentary divided field, like "century()".
      • RemainderDateTimeField

        public RemainderDateTimeField​(DividedDateTimeField dividedField,
                                      DateTimeFieldType type)
        Construct a RemainderDateTimeField that compliments the given DividedDateTimeField.
        Parameters:
        dividedField - complimentary divided field, like "century()".
        type - the field type this field actually uses
      • RemainderDateTimeField

        public RemainderDateTimeField​(DividedDateTimeField dividedField,
                                      DurationField durationField,
                                      DateTimeFieldType type)
        Construct a RemainderDateTimeField that compliments the given DividedDateTimeField. This constructor allows the duration field to be set.
        Parameters:
        dividedField - complimentary divided field, like "century()".
        durationField - the duration field
        type - the field type this field actually uses
    • Method Detail

      • get

        public int get​(long instant)
        Get the remainder from the specified time instant.
        Overrides:
        get in class DecoratedDateTimeField
        Parameters:
        instant - the time instant in millis to query.
        Returns:
        the remainder extracted from the input.
      • addWrapField

        public long addWrapField​(long instant,
                                 int amount)
        Add the specified amount to the specified time instant, wrapping around within the remainder range if necessary. The amount added may be negative.
        Overrides:
        addWrapField in class BaseDateTimeField
        Parameters:
        instant - the time instant in millis to update.
        amount - the amount to add (can be negative).
        Returns:
        the updated time instant.
      • set

        public long set​(long instant,
                        int value)
        Set the specified amount of remainder units to the specified time instant.
        Overrides:
        set in class DecoratedDateTimeField
        Parameters:
        instant - the time instant in millis to update.
        value - value of remainder units to set.
        Returns:
        the updated time instant.
        Throws:
        java.lang.IllegalArgumentException - if value is too large or too small.
      • getDurationField

        public DurationField getDurationField()
        Description copied from class: BaseDateTimeField
        Returns the duration per unit value of this field. For example, if this field represents "hour of day", then the unit duration is an hour.
        Overrides:
        getDurationField in class DecoratedDateTimeField
        Returns:
        the duration of this field, or UnsupportedDurationField if field has no duration
      • getMinimumValue

        public int getMinimumValue()
        Get the minimum value for the field, which is always zero.
        Overrides:
        getMinimumValue in class DecoratedDateTimeField
        Returns:
        the minimum value of zero.
      • getMaximumValue

        public int getMaximumValue()
        Get the maximum value for the field, which is always one less than the divisor.
        Overrides:
        getMaximumValue in class DecoratedDateTimeField
        Returns:
        the maximum value
      • roundFloor

        public long roundFloor​(long instant)
        Description copied from class: BaseDateTimeField
        Round to the lowest whole unit of this field. After rounding, the value of this field and all fields of a higher magnitude are retained. The fractional millis that cannot be expressed in whole increments of this field are set to minimum.

        For example, a datetime of 2002-11-02T23:34:56.789, rounded to the lowest whole hour is 2002-11-02T23:00:00.000.

        Overrides:
        roundFloor in class DecoratedDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • roundCeiling

        public long roundCeiling​(long instant)
        Description copied from class: BaseDateTimeField
        Round to the highest whole unit of this field. The value of this field and all fields of a higher magnitude may be incremented in order to achieve this result. The fractional millis that cannot be expressed in whole increments of this field are set to minimum.

        For example, a datetime of 2002-11-02T23:34:56.789, rounded to the highest whole hour is 2002-11-03T00:00:00.000.

        The default implementation calls roundFloor, and if the instant is modified as a result, adds one field unit. Subclasses are encouraged to provide a more efficient implementation.

        Overrides:
        roundCeiling in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • roundHalfFloor

        public long roundHalfFloor​(long instant)
        Description copied from class: BaseDateTimeField
        Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor or is exactly halfway, this function behaves like roundFloor. If the millisecond value is closer to the ceiling, this function behaves like roundCeiling.
        Overrides:
        roundHalfFloor in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • roundHalfCeiling

        public long roundHalfCeiling​(long instant)
        Description copied from class: BaseDateTimeField
        Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor, this function behaves like roundFloor. If the millisecond value is closer to the ceiling or is exactly halfway, this function behaves like roundCeiling.
        Overrides:
        roundHalfCeiling in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • roundHalfEven

        public long roundHalfEven​(long instant)
        Description copied from class: BaseDateTimeField
        Round to the nearest whole unit of this field. If the given millisecond value is closer to the floor, this function behaves like roundFloor. If the millisecond value is closer to the ceiling, this function behaves like roundCeiling.

        If the millisecond value is exactly halfway between the floor and ceiling, the ceiling is chosen over the floor only if it makes this field's value even.

        Overrides:
        roundHalfEven in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • remainder

        public long remainder​(long instant)
        Description copied from class: BaseDateTimeField
        Returns the fractional duration milliseconds of this field. In other words, calling remainder returns the duration that roundFloor would subtract.

        For example, on a datetime of 2002-11-02T23:34:56.789, the remainder by hour is 34 minutes and 56.789 seconds.

        The default implementation computes instant - roundFloor(instant). Subclasses are encouraged to provide a more efficient implementation.

        Overrides:
        remainder in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to get the remainder
        Returns:
        remainder duration, in milliseconds
      • getDivisor

        public int getDivisor()
        Returns the divisor applied, in the field's units.
        Returns:
        the divisor