public final class DayTime extends java.lang.Object implements java.lang.Comparable<DayTime>, java.io.Serializable
Note that, internally, this class, like all the other date-related classes in this package, uses the modern Gregorian calendar for all validation and calculations. The Gregorian calendar was introduced in 1582 but this class applies it to earlier dates as well (so using what is known as the "proleptic Gregorian calendar"). This fits with the ISO 8601 standard and is how the java.time
package works by default, but it's not how java.util.Calendar
works by default, so bear this in mind if you are working with dates from 1582 or before. You are of course unlikely to find good weather data from that far back, but we mention this just in case you find yourself using this class for other purposes as well!
Instances of this class are immutable. You can safely reuse them and call them from multiple threads at once.
Constructor and Description |
---|
DayTime(Day day,
Time time)
Constructs a
DayTime object with the specified
Day and Time . |
DayTime(int year,
int monthOfYearWithJanAs1,
int dayOfMonth,
int hour,
int minute)
Constructs a
DayTime object with the specified year, month,
day, hour, and minute. |
Modifier and Type | Method and Description |
---|---|
boolean |
after(DayTime comparisonDayTime)
Returns
true if this DayTime is chronologically
after comparisonDayTime ; false otherwise. |
boolean |
before(DayTime comparisonDayTime)
Returns
true if this DayTime is chronologically
before comparisonDayTime ; false otherwise. |
int |
compareTo(DayTime comparisonDayTime)
Compares two
DayTime objects for chronological ordering. |
Day |
day()
Returns a non-null
Day object representing the YYYY-MM-DD
component of this DayTime . |
int |
dayOfMonth()
Returns a number between 1 and 31 (inclusive) indicating the
day-of-the-month component of this
DayTime . |
DayOfWeek |
dayOfWeek()
Returns a non-null
DayOfWeek object indicating the
day of the week of this DayTime . |
int |
dayOfYear()
Returns a number between 1 and 366 inclusive (365 for non-leap years)
indicating the day of the year of this
DayTime . |
boolean |
equals(java.lang.Object o)
Returns
true if o is a DayTime
representing the same date-time as this DayTime ;
false otherwise. |
static DayTime |
fromCalendar(java.util.Calendar c)
Returns the non-null
DayTime object represented by the
YEAR , MONTH , DAY_OF_MONTH ,
HOUR_OF_DAY , and MINUTE fields of
calendar . |
static DayTime |
fromString(java.lang.String dateTimeString)
Parses a string date-time in ISO
YYYY-MM-DDThh:mm format
(the format used by XML schema's dateTime type),
YYYYMMDDThhmm format, or YYYYMMDDhhmm
all-numeric format. |
int |
hashCode()
Overridden to ensure consistency with
equals . |
int |
hour()
Returns a number between 0 and 23 (inclusive) representing the hour
component of this
DayTime . |
int |
minute()
Returns a number between 0 and 59 (inclusive) representing the minute
component of this
DayTime . |
long |
minutesAfter(DayTime comparisonDayTime)
Returns the number of minutes that this
DayTime is after
comparisonDayTime , which will be negative if this
DayTime comes first chronologically. |
long |
minutesBefore(DayTime comparisonDayTime)
Returns the number of minutes that this
DayTime is before
comparisonDayTime , which will be negative if
comparisonDayTime comes first chronologically. |
int |
monthOfYear()
Returns a number between 1 (January) and 12 (December) representing the
month-of-the-year component of this
DayTime . |
static DayTime |
of(Day day,
Time time)
Returns a non-null
DayTime object with the specified
Day and Time . |
static DayTime |
of(int year,
int monthOfYearWithJanAs1,
int dayOfMonth,
int hour,
int minute)
Returns a non-null
DayTime object with the specified year,
month, day, hour, and minute. |
Time |
time()
Returns a non-null
Time object representing the hh:mm
component of this DayTime . |
java.lang.String |
toNumericString()
Returns a non-null, non-empty string representation of this
DayTime in YYYYMMDDHHMM format. |
java.lang.String |
toString()
Returns a non-null, non-empty string representation of this
DayTime in YYYY-MM-DDThh:mm format. |
int |
year()
Returns a number indicating the year component of this
DayTime . |
public DayTime(Day day, Time time)
DayTime
object with the specified
Day
and Time
.day
- representing the YYYY-MM-DD part of the date-time.time
- representing the hh:mm part of the date-time.java.lang.NullPointerException
- if either parameter is null
.public DayTime(int year, int monthOfYearWithJanAs1, int dayOfMonth, int hour, int minute)
DayTime
object with the specified year, month,
day, hour, and minute.year
- the year - a number greater than 0 and less than or equal to
9999.monthOfYearWithJanAs1
- the month of the year - a number between 1
and 12 (inclusive), January being 1 and December being 12.dayOfMonth
- the day of the month - a number between 1 and 31,
although the upper limit depends on the month (since different
months have different numbers of days), and the year (since
February has 29 days on leap years and 28 otherwise).hour
- the hour - a number between 0 and 23 (inclusive).minute
- the minute - a number between 0 and 59 (inclusive).java.lang.IllegalArgumentException
- if any of the parameters are outside of
their allowed ranges, or if the year/month/day combination
doesn't correspond to a real calendar date, or if it is outside
the range allowed by Day
(0001-01-01 to 9999-12-31
inclusive).public static DayTime of(Day day, Time time)
DayTime
object with the specified
Day
and Time
.day
- representing the YYYY-MM-DD part of the date-time.time
- representing the hh:mm part of the date-time.java.lang.NullPointerException
- if either parameter is null
.public static DayTime of(int year, int monthOfYearWithJanAs1, int dayOfMonth, int hour, int minute)
DayTime
object with the specified year,
month, day, hour, and minute.year
- the year - a number greater than 0 and less than or equal to
9999.monthOfYearWithJanAs1
- the month of the year - a number between 1
and 12 (inclusive), January being 1 and December being 12.dayOfMonth
- the day of the month - a number between 1 and 31,
although the upper limit depends on the month (since different
months have different numbers of days), and the year (since
February has 29 days on leap years and 28 otherwise).hour
- the hour - a number between 0 and 23 (inclusive).minute
- the minute - a number between 0 and 59 (inclusive).java.lang.IllegalArgumentException
- if any of the parameters are outside of
their allowed ranges, or if the year/month/day combination
doesn't correspond to a real calendar date, or if it is outside
the range allowed by Day
(0001-01-01 to 9999-12-31
inclusive).public Day day()
Day
object representing the YYYY-MM-DD
component of this DayTime
.public Time time()
Time
object representing the hh:mm
component of this DayTime
.public int year()
DayTime
.public int monthOfYear()
DayTime
.public int dayOfMonth()
DayTime
.public DayOfWeek dayOfWeek()
DayOfWeek
object indicating the
day of the week of this DayTime
.public int dayOfYear()
DayTime
.public int hour()
DayTime
.public int minute()
DayTime
.public static DayTime fromString(java.lang.String dateTimeString)
YYYY-MM-DDThh:mm
format
(the format used by XML schema's dateTime type),
YYYYMMDDThhmm
format, or YYYYMMDDhhmm
all-numeric format. The T
character can optionally be a
space instead.DayTime
object corresponding to the
date-time represented by dateTimeString
.java.lang.NullPointerException
- if dateTimeString
is
null
.java.lang.NumberFormatException
- if dateTimeString
has an
invalid format, or represents a non-existent date-time or one
that is outside the range allowed by Day
(0001-01-01 to
9999-12-31 inclusive).toString()
,
toNumericString()
public static DayTime fromCalendar(java.util.Calendar c)
DayTime
object represented by the
YEAR
, MONTH
, DAY_OF_MONTH
,
HOUR_OF_DAY
, and MINUTE
fields of
calendar
. (We correct for the fact that
Calendar.MONTH
is zero-based.)java.lang.NullPointerException
- if calendar
is
null
.java.lang.IllegalArgumentException
- if the fields of calendar
represent a date-time that is outside the range allowed by
Day
(0001-01-01 to 9999-12-31 inclusive).public java.lang.String toString()
DayTime
in YYYY-MM-DDThh:mm
format.toString
in class java.lang.Object
toNumericString()
,
fromString(java.lang.String)
public java.lang.String toNumericString()
DayTime
in YYYYMMDDHHMM
format.toString()
,
fromString(java.lang.String)
public boolean equals(java.lang.Object o)
true
if o
is a DayTime
representing the same date-time as this DayTime
;
false
otherwise.equals
in class java.lang.Object
public int hashCode()
equals
.hashCode
in class java.lang.Object
public int compareTo(DayTime comparisonDayTime)
DayTime
objects for chronological ordering.compareTo
in interface java.lang.Comparable<DayTime>
comparisonDayTime
- the DayTime
to be compared. Cannot
be null
.DayTime
is before
comparisonDayTime
; zero if this DayTime
is equal to comparisonDayTime
; or a positive integer
if this DayTime
is after
comparisonDayTime
.java.lang.NullPointerException
- if comparisonDayTime
is
null
.before(net.degreedays.time.DayTime)
,
after(net.degreedays.time.DayTime)
public boolean before(DayTime comparisonDayTime)
true
if this DayTime
is chronologically
before comparisonDayTime
; false
otherwise.comparisonDayTime
- the DayTime
to compare with this
DayTime
. Cannot be null
.java.lang.NullPointerException
- if comparisonDayTime
is
null
.after(net.degreedays.time.DayTime)
,
compareTo(net.degreedays.time.DayTime)
public boolean after(DayTime comparisonDayTime)
true
if this DayTime
is chronologically
after comparisonDayTime
; false
otherwise.comparisonDayTime
- the DayTime
to compare with this
DayTime
. Cannot be null
.java.lang.NullPointerException
- if comparisonDayTime
is
null
.before(net.degreedays.time.DayTime)
,
compareTo(net.degreedays.time.DayTime)
public long minutesAfter(DayTime comparisonDayTime)
DayTime
is after
comparisonDayTime
, which will be negative if this
DayTime
comes first chronologically.java.lang.NullPointerException
- if comparisonDayTime
is
null
.minutesBefore(net.degreedays.time.DayTime)
public long minutesBefore(DayTime comparisonDayTime)
DayTime
is before
comparisonDayTime
, which will be negative if
comparisonDayTime
comes first chronologically.java.lang.NullPointerException
- if comparisonDayTime
is
null
.minutesAfter(net.degreedays.time.DayTime)
See www.degreedays.net/api/ for more about the Degree Days.net API.
You can sign up for a Degree Days.net API account and read the integration guide that is useful and applicable whether you are using Java or not.