Class BasicYearDateTimeField


  • class BasicYearDateTimeField
    extends ImpreciseDateTimeField
    A year field suitable for many calendars.
    Since:
    1.1, refactored from GJYearDateTimeField
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Serialization version.
        See Also:
        Constant Field Values
      • iChronology

        protected final BasicChronology iChronology
        The underlying basic chronology.
    • Constructor Detail

      • BasicYearDateTimeField

        BasicYearDateTimeField​(BasicChronology chronology)
        Restricted constructor.
        Parameters:
        chronology - the chronology this field belongs to
    • Method Detail

      • isLenient

        public boolean isLenient()
        Description copied from class: DateTimeField
        Returns true if the set method is lenient. If so, it accepts values that are out of bounds. For example, a lenient day of month field accepts 32 for January, converting it to February 1.
        Specified by:
        isLenient in class DateTimeField
        Returns:
        true if this field is lenient
      • get

        public int get​(long instant)
        Description copied from class: BaseDateTimeField
        Get the value of this field from the milliseconds.
        Specified by:
        get in class ImpreciseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to query
        Returns:
        the value of the field, in the units of the field
      • add

        public long add​(long instant,
                        int years)
        Description copied from class: BaseDateTimeField
        Adds a value (which may be negative) to the instant value, overflowing into larger fields if necessary.

        The value will be added to this field. If the value is too large to be added solely to this field, larger fields will increase as required. Smaller fields should be unaffected, except where the result would be an invalid value for a smaller field. In this case the smaller field is adjusted to be in range.

        For example, in the ISO chronology:
        2000-08-20 add six months is 2001-02-20
        2000-08-20 add twenty months is 2002-04-20
        2000-08-20 add minus nine months is 1999-11-20
        2001-01-31 add one month is 2001-02-28
        2001-01-31 add two months is 2001-03-31

        Specified by:
        add in class ImpreciseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to add to
        years - the value to add, in the units of the field
        Returns:
        the updated milliseconds
      • add

        public long add​(long instant,
                        long years)
        Description copied from class: BaseDateTimeField
        Adds a value (which may be negative) to the instant value, overflowing into larger fields if necessary.
        Specified by:
        add in class ImpreciseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to add to
        years - the long value to add, in the units of the field
        Returns:
        the updated milliseconds
        See Also:
        BaseDateTimeField.add(long,int)
      • addWrapField

        public long addWrapField​(long instant,
                                 int years)
        Description copied from class: BaseDateTimeField
        Adds a value (which may be negative) to the instant value, wrapping within this field.

        The value will be added to this field. If the value is too large to be added solely to this field then it wraps. Larger fields are always unaffected. Smaller fields should be unaffected, except where the result would be an invalid value for a smaller field. In this case the smaller field is adjusted to be in range.

        For example, in the ISO chronology:
        2000-08-20 addWrapField six months is 2000-02-20
        2000-08-20 addWrapField twenty months is 2000-04-20
        2000-08-20 addWrapField minus nine months is 2000-11-20
        2001-01-31 addWrapField one month is 2001-02-28
        2001-01-31 addWrapField two months is 2001-03-31

        The default implementation internally calls set. Subclasses are encouraged to provide a more efficient implementation.

        Overrides:
        addWrapField in class BaseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to add to
        years - the value to add, in the units of the field
        Returns:
        the updated milliseconds
      • set

        public long set​(long instant,
                        int year)
        Description copied from class: BaseDateTimeField
        Sets a value in the milliseconds supplied.

        The value of this field will be set. If the value is invalid, an exception if thrown.

        If setting this field would make other fields invalid, then those fields may be changed. For example if the current date is the 31st January, and the month is set to February, the day would be invalid. Instead, the day would be changed to the closest value - the 28th/29th February as appropriate.

        Specified by:
        set in class ImpreciseDateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to set in
        year - the value to set, in the units of the field
        Returns:
        the updated milliseconds
      • setExtended

        public long setExtended​(long instant,
                                int year)
        Description copied from class: DateTimeField
        Sets a value in the milliseconds supplied, allowing a little leniency at the margins.

        This is primarily an internal method used by parsing.

        Overrides:
        setExtended in class DateTimeField
        Parameters:
        instant - the milliseconds from 1970-01-01T00:00:00Z to set in
        year - the value to set, in the units of the field
        Returns:
        the updated milliseconds
      • getDifferenceAsLong

        public long getDifferenceAsLong​(long minuendInstant,
                                        long subtrahendInstant)
        Description copied from class: ImpreciseDateTimeField
        Computes the difference between two instants, as measured in the units of this field. Any fractional units are dropped from the result. Calling getDifference reverses the effect of calling add. In the following code:
         long instant = ...
         long v = ...
         long age = getDifferenceAsLong(add(instant, v), instant);
         
        The value 'age' is the same as the value 'v'.

        The default implementation performs a guess-and-check algorithm using getDurationField().getUnitMillis() and the add() method. Subclasses are encouraged to provide a more efficient implementation.

        Overrides:
        getDifferenceAsLong in class ImpreciseDateTimeField
        Parameters:
        minuendInstant - the milliseconds from 1970-01-01T00:00:00Z to subtract from
        subtrahendInstant - the milliseconds from 1970-01-01T00:00:00Z to subtract off the minuend
        Returns:
        the difference in the units of this field
      • getRangeDurationField

        public DurationField getRangeDurationField()
        Description copied from class: BaseDateTimeField
        Returns the range duration of this field. For example, if this field represents "hour of day", then the range duration is a day.
        Specified by:
        getRangeDurationField in class ImpreciseDateTimeField
        Returns:
        the range duration of this field, or null if field has no range
      • isLeap

        public boolean isLeap​(long instant)
        Description copied from class: BaseDateTimeField
        Returns whether this field is 'leap' for the specified instant.

        For example, a leap year would return true, a non leap year would return false.

        This implementation returns false.

        Overrides:
        isLeap in class BaseDateTimeField
        Parameters:
        instant - the instant to check for leap status
        Returns:
        true if the field is 'leap'
      • getLeapAmount

        public int getLeapAmount​(long instant)
        Description copied from class: BaseDateTimeField
        Gets the amount by which this field is 'leap' for the specified instant.

        For example, a leap year would return one, a non leap year would return zero.

        This implementation returns zero.

        Overrides:
        getLeapAmount in class BaseDateTimeField
        Parameters:
        instant - the instant to check for leap status
        Returns:
        the amount, in units of the leap duration field, that the field is leap
      • getLeapDurationField

        public DurationField getLeapDurationField()
        Description copied from class: BaseDateTimeField
        If this field were to leap, then it would be in units described by the returned duration. If this field doesn't ever leap, null is returned.

        This implementation returns null.

        Overrides:
        getLeapDurationField in class BaseDateTimeField
        Returns:
        the leap duration field if field can be leap, null if it can't
      • getMinimumValue

        public int getMinimumValue()
        Description copied from class: BaseDateTimeField
        Get the minimum allowable value for this field.
        Specified by:
        getMinimumValue in class BaseDateTimeField
        Returns:
        the minimum valid value for this field, in the units of the field
      • getMaximumValue

        public int getMaximumValue()
        Description copied from class: BaseDateTimeField
        Get the maximum allowable value for this field.
        Specified by:
        getMaximumValue in class BaseDateTimeField
        Returns:
        the maximum valid value for this field, in the units of the field
      • 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.

        Specified by:
        roundFloor in class ImpreciseDateTimeField
        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
      • 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
      • readResolve

        private java.lang.Object readResolve()
        Serialization singleton