Class OffsetDate
- java.lang.Object
-
- com.addicticks.texttime.OffsetDate
-
- All Implemented Interfaces:
Serializable,Comparable<OffsetDate>
public final class OffsetDate extends Object implements Serializable, Comparable<OffsetDate>
A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as2007-12-03+01:00.The class is merely a thin wrapper around
OffsetDateTimebecause a date-only class is missing from JDK. The class exist mainly for the purpose of JAXB mapping to/from XML Schema typexs:date.This is a value-based class; use of identity-sensitive operations (including reference equality (
==), identity hash code, or synchronization) on instances ofOffsetDatemay have unpredictable results and should be avoided. Theequalsmethod should be used for comparisons.This class is immutable and thread-safe.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(OffsetDate other)Compares this date to another date.booleanequals(Object obj)Checks if this date is equal to another date.static OffsetDatefrom(TemporalAccessor temporal)Obtains an instance ofOffsetDatefrom a temporal object.OffsetDateTimegetDate()Gets the date value.inthashCode()A hash code for this date.static OffsetDateof(int year, int month, int dayOfMonth, ZoneOffset offset)Obtains an instance ofOffsetDatefrom a year, month, day, and offset.static OffsetDateof(LocalDate date, ZoneOffset offset)Obtains an instance ofOffsetDatefrom aLocalDateand an offset.static OffsetDateof(OffsetDateTime datetime)Obtains an instance ofOffsetDatefrom anOffsetDateTimeThe time part of the input value will beremoved.
-
-
-
Method Detail
-
of
public static OffsetDate of(int year, int month, int dayOfMonth, ZoneOffset offset)
Obtains an instance ofOffsetDatefrom a year, month, day, and offset.- Parameters:
year- the year to represent, for example 2018.month- the month-of-year to represent, from 1 (January) to 12 (December)dayOfMonth- the day-of-month to represent, from 1 to 31offset- the zone offset, not null- Returns:
- a date, not null
- See Also:
OffsetDateTime.of(int, int, int, int, int, int, int, java.time.ZoneOffset)
-
of
public static OffsetDate of(LocalDate date, ZoneOffset offset)
Obtains an instance ofOffsetDatefrom aLocalDateand an offset.- Parameters:
date- local date, not nulloffset- the zone offset, not null- Returns:
- a date, not null
- See Also:
OffsetDateTime.of(java.time.LocalDate, java.time.LocalTime, java.time.ZoneOffset)
-
of
public static OffsetDate of(OffsetDateTime datetime)
Obtains an instance ofOffsetDatefrom anOffsetDateTimeThe time part of the input value will beremoved.- Parameters:
datetime- datetime value, not null- Returns:
- a date, not null
-
getDate
public OffsetDateTime getDate()
Gets the date value.- Returns:
- datetime value with time part set to midnight, never null
-
hashCode
public int hashCode()
A hash code for this date.
-
equals
public boolean equals(Object obj)
Checks if this date is equal to another date.The comparison is delegated to the wrapped
OffsetDateTime. To compare for the same instant on the time-line, usegetDate().isEqual(). Only objects of typeOffsetDateare compared, other types return false.- Overrides:
equalsin classObject- Parameters:
obj- the object to check, null returns false- Returns:
- true if this is equal to the other date
- See Also:
OffsetDateTime.equals(java.lang.Object)
-
compareTo
public int compareTo(OffsetDate other)
Compares this date to another date.The comparison is delegated to the wrapped
OffsetDateTime.- Specified by:
compareToin interfaceComparable<OffsetDate>- Parameters:
other- the other date to compare to, not null- Returns:
- the comparator value, negative if less, positive if greater
- See Also:
OffsetDateTime.compareTo(java.time.OffsetDateTime)
-
from
public static OffsetDate from(TemporalAccessor temporal)
Obtains an instance ofOffsetDatefrom a temporal object.This obtains an offset date based on the specified temporal. A
TemporalAccessorrepresents an arbitrary set of date and time information, which this factory converts to an instance ofOffsetDate. Any time information in thetemporalwill be ignored.The conversion will first obtain a
ZoneOffsetfrom the temporal object. It will then try to obtain aLocalDate, falling back to anInstantif necessary. The result will be the combination ofZoneOffsetwith either withLocalDateorInstant.This method matches the signature of the functional interface
TemporalQueryallowing it to be used as a query via method reference,OffsetDate::from.- Parameters:
temporal- the temporal object to convert, not null- Returns:
- the offset date, not null
- Throws:
DateTimeException- if unable to convert to anOffsetDate
-
-