public final class YearMonthDay extends Object implements Comparable<YearMonthDay>, IEquatable<YearMonthDay>, ImmutableValueType
Constructor and Description |
---|
YearMonthDay()
Initializes a new instance.
|
YearMonthDay(int astronomicalJulianDayNumber)
Initializes a
YearMonthDay in the Gregorian calendar from the
provided astronomical Julian day number, assuming the beginning of the Julian
day (noon). |
YearMonthDay(int year,
int dayOfYear)
Initializes a
YearMonthDay from the provided values. |
YearMonthDay(int year,
int month,
int day)
Initializes a
YearMonthDay from the provided values. |
YearMonthDay(JulianDate date)
Initializes a new instance from a
JulianDate . |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(YearMonthDay other)
Compares this instance with another instance of the same type.
|
static int |
daysInMonth(int year,
int month)
Provides the number of days in the month of the indicated year.
|
static int |
daysInYear(int year)
Provides the number of days in the indicated year.
|
boolean |
equals(Object obj)
Indicates whether another object is exactly equal to this instance.
|
static boolean |
equals(YearMonthDay left,
YearMonthDay right)
Returns
true if the two instances are exactly equal. |
boolean |
equalsType(YearMonthDay other)
Indicates whether another instance of this type is exactly equal to this instance.
|
int |
getDay()
Gets the day of the month (in the range 1 through the number of days in the
month).
|
DayOfWeek |
getDayOfWeek()
Gets the day of the week represented by this instance.
|
int |
getDayOfYear()
Gets the day of the year (in the range 1 through the number of days in the year).
|
int |
getJulianDayNumber()
Gets the Julian day number for this
YearMonthDay instance,
assuming noon on this day. |
int |
getMonth()
Gets the month of the year (in the range 1 through 12).
|
int |
getYear()
Gets the year.
|
static boolean |
greaterThan(YearMonthDay left,
YearMonthDay right)
Returns
true if left is greater than right . |
static boolean |
greaterThanOrEqual(YearMonthDay left,
YearMonthDay right)
Returns
true if left is greater than or equal to right . |
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
static boolean |
isLeapYear(int year)
Indicates whether the year in question is a leap year.
|
static boolean |
isValidDate(int year,
int month,
int day)
Indicates whether the year, month, and day are a valid representation.
|
static boolean |
lessThan(YearMonthDay left,
YearMonthDay right)
Returns
true if left is less than right . |
static boolean |
lessThanOrEqual(YearMonthDay left,
YearMonthDay right)
Returns
true if left is less than or equal to right . |
static boolean |
notEquals(YearMonthDay left,
YearMonthDay right)
Returns
true if the two instances are not exactly equal. |
String |
toString()
Returns a string formatted as Year:Month:Day
|
public YearMonthDay()
public YearMonthDay(int year, int month, int day)
YearMonthDay
from the provided values.year
- The year.month
- The month of the year (in the range 1 through 12)day
- The day of the month (in the range 1 through the number of
days in month
)ArgumentException
- Thrown when the year
, month
, or
day
is outside of its acceptable range.public YearMonthDay(int year, int dayOfYear)
YearMonthDay
from the provided values.year
- The year.dayOfYear
- The day of the year
(in the range 1 through the number of days in the year).public YearMonthDay(int astronomicalJulianDayNumber)
YearMonthDay
in the Gregorian calendar from the
provided astronomical Julian day number, assuming the beginning of the Julian
day (noon).astronomicalJulianDayNumber
- The astronomical Julian day number.public YearMonthDay(@Nonnull JulianDate date)
JulianDate
.date
- The date.public final int getYear()
public final int getMonth()
public final int getDay()
public final int getDayOfYear()
@Nonnull public final DayOfWeek getDayOfWeek()
DayOfWeek
(get
) enumerated constant that indicates the day
of the week. This property value ranges from zero, indicating Sunday, to six,
indicating Saturday.public final int getJulianDayNumber()
YearMonthDay
instance,
assuming noon on this day.public static boolean isLeapYear(int year)
year
- The year.true
if year
is a leap year and
false
if it is not.public static int daysInMonth(int year, int month)
year
- The year.month
- The month of the year.public static int daysInYear(int year)
year
- The year.public static boolean isValidDate(int year, int month, int day)
year
- The year.month
- The month of the year (in the range 1 through 12)day
- The day of the month (in the range 1 through the number of days in
month
)true
if the representation is valid and
false
if it is not.public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public final boolean equalsType(@Nonnull YearMonthDay other)
equalsType
in interface IEquatable<YearMonthDay>
other
- The instance to compare to this instance.true
if other
represents the same value as this instance; otherwise false
.public boolean equals(Object obj)
equals
in class Object
obj
- The object to compare to this instance.true
if obj
is an instance of this type and represents the same value as this instance; otherwise false
.Object.hashCode()
,
HashMap
public String toString()
public final int compareTo(@Nonnull YearMonthDay other)
compareTo
in interface Comparable<YearMonthDay>
other
- An object to compare with this instance.Value | Meaning |
---|---|
Less than zero |
This instance is less than other .
|
Zero |
This instance is equal to other .
|
Greater than zero |
This instance is greater than other .
|
public static boolean equals(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right)
true
if the two instances are exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
represents the same value as right
; otherwise false
.public static boolean notEquals(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right)
true
if the two instances are not exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
does not represent the same value as right
; otherwise false
.public static boolean lessThan(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right)
true
if left
is less than right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is less than right
; otherwise false
.public static boolean greaterThan(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right)
true
if left
is greater than right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is greater than right
; otherwise false
.public static boolean lessThanOrEqual(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right)
true
if left
is less than or equal to right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is less than or equal to right
; otherwise false
.public static boolean greaterThanOrEqual(@Nonnull YearMonthDay left, @Nonnull YearMonthDay right)
true
if left
is greater than or equal to right
.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
is greater than or equal to right
; otherwise false
.