Class PreciseDurationDateTimeField

  • Direct Known Subclasses:
    PreciseDateTimeField

    public abstract class PreciseDurationDateTimeField
    extends BaseDateTimeField
    Precise datetime field, which has a precise unit duration field.

    PreciseDurationDateTimeField is thread-safe and immutable, and its subclasses must be as well.

    Since:
    1.0
    • Constructor Detail

      • PreciseDurationDateTimeField

        public PreciseDurationDateTimeField​(DateTimeFieldType type,
                                            DurationField unit)
        Constructor.
        Parameters:
        type - the field type
        unit - precise unit duration, like "days()".
        Throws:
        java.lang.IllegalArgumentException - if duration field is imprecise
        java.lang.IllegalArgumentException - if unit milliseconds is less than one
    • Method Detail

      • isLenient

        public boolean isLenient()
        Returns false by default.
        Specified by:
        isLenient in class DateTimeField
        Returns:
        true if this field is lenient
      • set

        public long set​(long instant,
                        int value)
        Set the specified amount of units to the specified time instant.
        Specified by:
        set in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to set in
        value - value of units to set.
        Returns:
        the updated time instant.
        Throws:
        java.lang.IllegalArgumentException - if value is too large or too small.
      • roundFloor

        public long roundFloor​(long instant)
        This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows:
         return super.roundFloor(instant + ALIGNMENT_MILLIS) - ALIGNMENT_MILLIS;
         
        Specified by:
        roundFloor in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • roundCeiling

        public long roundCeiling​(long instant)
        This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows:
         return super.roundCeiling(instant + ALIGNMENT_MILLIS) - ALIGNMENT_MILLIS;
         
        Overrides:
        roundCeiling in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to round
        Returns:
        rounded milliseconds
      • remainder

        public long remainder​(long instant)
        This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows:
         return super.remainder(instant + ALIGNMENT_MILLIS);
         
        Overrides:
        remainder in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to get the remainder
        Returns:
        remainder duration, in milliseconds
      • getDurationField

        public DurationField getDurationField()
        Returns the duration per unit value of this field. For example, if this field represents "minute of hour", then the duration field is minutes.
        Specified by:
        getDurationField in class BaseDateTimeField
        Returns:
        the duration of this field, or UnsupportedDurationField if field has no duration
      • getMinimumValue

        public int getMinimumValue()
        Get the minimum value for the field.
        Specified by:
        getMinimumValue in class BaseDateTimeField
        Returns:
        the minimum value
      • getUnitMillis

        public final long getUnitMillis()