Top Description Fields Constructors Methods
org.threeten.extra

public final Class YearHalf

extends Object
implements Temporal, TemporalAdjuster, Comparable<YearHalf>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, java.time.temporal.TemporalAdjuster, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor
Static Imports
java.time.temporal.ChronoField.ERA, .ChronoField.YEAR, .ChronoField.YEAR_OF_ERA, .ChronoUnit.CENTURIES, .ChronoUnit.DECADES, .ChronoUnit.ERAS, .ChronoUnit.MILLENNIA, .ChronoUnit.YEARS, org.threeten.extra.TemporalFields.DAY_OF_HALF, .TemporalFields.HALF_OF_YEAR, .TemporalFields.HALF_YEARS

A year-half in the ISO-8601 calendar system, such as 2007-H2.

YearHalf is an immutable date-time object that represents the combination of a year and a half-year. Any field that can be derived from a year and a half-year can be obtained. A half is defined by Half - H1 and H2. H1 is January to June, H2 is July to December.

This class does not store or represent a day, time or time-zone. For example, the value "2nd half 2007" can be stored in a YearHalf.

The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable. Note that the ISO-8601 standard does not define or refer to halves.

Implementation Requirements:

This class is immutable and thread-safe.

This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.

Field Summary

Modifier and TypeField and Description
private final Half
half

The half-of-year, not null.

private static final DateTimeFormatter
PARSER

Parser.

private static final long
serialVersionUID

Serialization version.

private final int
year

The year.

Constructor Summary

AccessConstructor and Description
private
YearHalf(int
the year to represent, validated from MIN_YEAR to MAX_YEAR
year
,
Half
the half-of-year to represent, validated not null
half
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public Temporal

Returns:

the adjusted object, not null
adjustInto
(Temporal
the target object to be adjusted, not null
temporal
)

Implements java.time.temporal.TemporalAdjuster.adjustInto.

Adjusts the specified temporal object to have this year-half.

public LocalDate

Returns:

the date formed from this year-half and the specified day, not null
atDay
(int
the day-of-half to use, from 1 to 184
dayOfHalf
)

Combines this year-half with a day-of-half to create a LocalDate.

public LocalDate

Returns:

the last valid date of this year-half, not null
atEndOfHalf
()

Returns a LocalDate at the end of the half.

public int

Returns:

the comparator value, negative if less, positive if greater
compareTo
(YearHalf
the other year-half to compare to, not null
other
)

Implements java.lang.Comparable.compareTo.

Compares this year-half to another

The comparison is based first on the value of the year, then on the value of the half.

public boolean

Returns:

true if this is equal to the other year-half
equals
(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Checks if this year-half is equal to another year-half.

public String

Returns:

the formatted year-half string, not null
format
(DateTimeFormatter
the formatter to use, not null
formatter
)

Formats this year-half using the specified formatter.

public static YearHalf

Returns:

the year-half, not null
from
(TemporalAccessor
the temporal object to convert, not null
temporal
)

Obtains an instance of YearHalf from a temporal object.

public int

Returns:

the value for the field
get
(TemporalField
the field to get, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.get.

Gets the value of the specified field from this year-half as an int.

public Half

Returns:

the half-of-year, not null
getHalf
()

Gets the half-of-year field using the Half enum.

public int

Returns:

the half-of-year, from 1 to 2
getHalfValue
()

Gets the half-of-year field from 1 to 2.

public long

Returns:

the value for the field
getLong
(TemporalField
the field to get, not null
field
)

Implements java.time.temporal.TemporalAccessor.getLong.

Gets the value of the specified field from this year-half as a long.

private long
public int

Returns:

the year, from MIN_YEAR to MAX_YEAR
getYear
()

Gets the year field.

public Stream<YearHalf>

Returns:

a sequential Stream for the range of YearHalf values
halvesUntil
(YearHalf
the end year-half, exclusive, not null
endExclusive
)

Returns a sequential ordered stream of year-half.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

A hash code for this year-half.

public boolean

Returns:

true if this is after the specified year-half
isAfter
(YearHalf
the other year-half to compare to, not null
other
)

Is this year-half after the specified year-half.

public boolean

Returns:

true if this point is before the specified year-half
isBefore
(YearHalf
the other year-half to compare to, not null
other
)

Is this year-half before the specified year-half.

public boolean

Returns:

true if the year is leap, false otherwise
isLeapYear
()

Checks if the year is a leap year, according to the ISO proleptic calendar system rules.

public boolean

Returns:

true if the field is supported on this year-half, false if not
isSupported
(TemporalField
the field to check, null returns false
field
)

Implements java.time.temporal.TemporalAccessor.isSupported.

Checks if the specified field is supported.

public boolean

Returns:

true if the unit can be added/subtracted, false if not
isSupported
(TemporalUnit
the unit to check, null returns false
unit
)

Implements java.time.temporal.Temporal.isSupported.

Checks if the specified unit is supported.

public boolean

Returns:

true if the day is valid for this year-half
isValidDay
(int
the day-of-half to validate, from 1 to 181, 182 or 184, invalid value returns false
dayOfHalf
)

Checks if the day-of-half is valid for this year-half.

public int

Returns:

the length of the half in days, 181, 182 or 184
lengthOfHalf
()

Returns the length of the half, taking account of the year.

public int

Returns:

366 if the year is leap, 365 otherwise
lengthOfYear
()

Returns the length of the year.

public YearHalf

Returns:

a YearHalf based on this year-half with the subtraction made, not null
minus
(TemporalAmount
the amount to subtract, not null
amountToSubtract
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this year-half with the specified amount subtracted.

public YearHalf

Returns:

a YearHalf based on this year-half with the specified amount subtracted, not null
minus
(long
the amount of the unit to subtract from the result, may be negative
amountToSubtract
,
TemporalUnit
the unit of the amount to subtract, not null
unit
)

Overrides default java.time.temporal.Temporal.minus.

Returns a copy of this year-half with the specified amount subtracted.

public YearHalf

Returns:

a YearHalf based on this year-half with the halves subtracted, not null
minusHalves
(long
the halves to subtract, may be negative
halvesToSubtract
)

Returns a copy of this year-half with the specified period in halves subtracted.

public YearHalf

Returns:

a YearHalf based on this year-half with the years subtracted, not null
minusYears
(long
the years to subtract, may be negative
yearsToSubtract
)

Returns a copy of this year-half with the specified period in years subtracted.

public static YearHalf

Returns:

the current year-half using the system clock and default time-zone, not null
now
()

Obtains the current year-half from the system clock in the default time-zone.

public static YearHalf

Returns:

the current year-half using the system clock, not null
now
(ZoneId
the zone ID to use, not null
zone
)

Obtains the current year-half from the system clock in the specified time-zone.

public static YearHalf

Returns:

the current year-half, not null
now
(Clock
the clock to use, not null
clock
)

Obtains the current year-half from the specified clock.

public static YearHalf

Returns:

the year-half, not null
of
(Year
the year to represent, not null
year
,
Half
the half-of-year to represent, not null
half
)

Obtains an instance of YearHalf from a year and half.

public static YearHalf

Returns:

the year-half, not null
of
(Year
the year to represent, not null
year
,
int
the half-of-year to represent, from 1 to 2
half
)

Obtains an instance of YearHalf from a year and half.

public static YearHalf

Returns:

the year-half, not null
of
(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
Half
the half-of-year to represent, not null
half
)

Obtains an instance of YearHalf from a year and half.

public static YearHalf

Returns:

the year-half, not null
of
(int
the year to represent, from MIN_YEAR to MAX_YEAR
year
,
int
the half-of-year to represent, from 1 to 2
half
)

Obtains an instance of YearHalf from a year and half.

public static YearHalf

Returns:

the parsed year-half, not null
parse
(CharSequence
the text to parse such as "2007-H2", not null
text
)

Obtains an instance of YearHalf from a text string such as 2007-H2.

public static YearHalf

Returns:

the parsed year-half, not null
parse
(CharSequence
the text to parse, not null
text
,
DateTimeFormatter
the formatter to use, not null
formatter
)

Obtains an instance of YearHalf from a text string using a specific formatter.

public YearHalf

Returns:

a YearHalf based on this year-half with the addition made, not null
plus
(TemporalAmount
the amount to add, not null
amountToAdd
)

Overrides default java.time.temporal.Temporal.plus.

Returns a copy of this year-half with the specified amount added.

public YearHalf

Returns:

a YearHalf based on this year-half with the specified amount added, not null
plus
(long
the amount of the unit to add to the result, may be negative
amountToAdd
,
TemporalUnit
the unit of the amount to add, not null
unit
)

Implements java.time.temporal.Temporal.plus.

Returns a copy of this year-half with the specified amount added.

public YearHalf

Returns:

a YearHalf based on this year-half with the halves added, not null
plusHalves
(long
the halves to add, may be negative
halvesToAdd
)

Returns a copy of this year-half with the specified period in halves added.

public YearHalf

Returns:

a YearHalf based on this year-half with the years added, not null
plusYears
(long
the years to add, may be negative
yearsToAdd
)

Returns a copy of this year-half with the specified period in years added.

public <
the type of the result
R
>
R

Returns:

the query result, null may be returned (defined by the query)
query
(TemporalQuery<R>
the query to invoke, not null
query
)

Overrides default java.time.temporal.TemporalAccessor.query.

Queries this year-half using the specified query.

public ValueRange

Returns:

the range of valid values for the field, not null
range
(TemporalField
the field to query the range for, not null
field
)

Overrides default java.time.temporal.TemporalAccessor.range.

Gets the range of valid values for the specified field.

private Object

Returns:

the valid object, not null
readResolve
()

Validates the input.

public String

Returns:

a string representation of this year-half, not null
toString
()

Overrides java.lang.Object.toString.

Outputs this year-half as a String, such as 2007-H2.

public long

Returns:

the amount of time between this year-half and the end year-half
until
(Temporal
the end date, exclusive, which is converted to a YearHalf, not null
endExclusive
,
TemporalUnit
the unit to measure the amount in, not null
unit
)

Implements java.time.temporal.Temporal.until.

Calculates the amount of time until another year-half in terms of the specified unit.

private YearHalf

Returns:

the year-half, not null
with
(int
the year to represent, validated from MIN_YEAR to MAX_YEAR
newYear
,
Half
the half-of-year to represent, validated not null
newHalf
)

Returns a copy of this year-half with the new year and half, checking to see if a new object is in fact required.

public YearHalf

Returns:

a YearHalf based on this with the adjustment made, not null
with
(TemporalAdjuster
the adjuster to use, not null
adjuster
)

Overrides default java.time.temporal.Temporal.with.

Returns an adjusted copy of this year-half.

public YearHalf

Returns:

a YearHalf based on this with the specified field set, not null
with
(TemporalField
the field to set in the result, not null
field
,
long
the new value of the field in the result
newValue
)

Implements java.time.temporal.Temporal.with.

Returns a copy of this year-half with the specified field set to a new value.

public YearHalf

Returns:

a YearHalf based on this year-half with the requested half, not null
withHalf
(int
the half-of-year to set in the returned year-half, from 1 to 2
half
)

Returns a copy of this YearHalf with the half-of-year altered.

public YearHalf

Returns:

a YearHalf based on this year-half with the requested year, not null
withYear
(int
the year to set in the returned year-half, from MIN_YEAR to MAX_YEAR
year
)

Returns a copy of this YearHalf with the year altered.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait