net.degreedays.time
Class DayTime

java.lang.Object
  extended by net.degreedays.time.DayTime
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public final class DayTime
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

Represents a date-time without a time-zone, such as 2020-04-10T14:55.

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!

Since:
1.2

Instances of this class are immutable. You can safely reuse them and call them from multiple threads at once.


Constructor Summary
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.
 
Method Summary
 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(java.lang.Object 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.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DayTime

public DayTime(Day day,
               Time time)
Constructs a DayTime object with the specified Day and Time.

Parameters:
day - representing the YYYY-MM-DD part of the date-time.
time - representing the hh:mm part of the date-time.
Throws:
java.lang.NullPointerException - if either parameter is null.

DayTime

public DayTime(int year,
               int monthOfYearWithJanAs1,
               int dayOfMonth,
               int hour,
               int minute)
Constructs a DayTime object with the specified year, month, day, hour, and minute.

Parameters:
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).
Throws:
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).
Method Detail

of

public static DayTime of(Day day,
                         Time time)
Returns a non-null DayTime object with the specified Day and Time.

Parameters:
day - representing the YYYY-MM-DD part of the date-time.
time - representing the hh:mm part of the date-time.
Throws:
java.lang.NullPointerException - if either parameter is null.

of

public 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.

Parameters:
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).
Throws:
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).

day

public Day day()
Returns a non-null Day object representing the YYYY-MM-DD component of this DayTime.


time

public Time time()
Returns a non-null Time object representing the hh:mm component of this DayTime.


year

public int year()
Returns a number indicating the year component of this DayTime.


monthOfYear

public int monthOfYear()
Returns a number between 1 (January) and 12 (December) representing the month-of-the-year component of this DayTime.


dayOfMonth

public int dayOfMonth()
Returns a number between 1 and 31 (inclusive) indicating the day-of-the-month component of this DayTime.


dayOfWeek

public DayOfWeek dayOfWeek()
Returns a non-null DayOfWeek object indicating the day of the week of this DayTime.


dayOfYear

public int dayOfYear()
Returns a number between 1 and 366 inclusive (365 for non-leap years) indicating the day of the year of this DayTime.


hour

public int hour()
Returns a number between 0 and 23 (inclusive) representing the hour component of this DayTime.


minute

public int minute()
Returns a number between 0 and 59 (inclusive) representing the minute component of this DayTime.


fromString

public 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. The T character can optionally be a space instead.

Returns:
a non-null DayTime object corresponding to the date-time represented by dateTimeString.
Throws:
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).
See Also:
toString(), toNumericString()

fromCalendar

public 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. (We correct for the fact that Calendar.MONTH is zero-based.)

Throws:
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).

toString

public java.lang.String toString()
Returns a non-null, non-empty string representation of this DayTime in YYYY-MM-DDThh:mm format.

Overrides:
toString in class java.lang.Object
See Also:
toNumericString(), fromString(java.lang.String)

toNumericString

public java.lang.String toNumericString()
Returns a non-null, non-empty string representation of this DayTime in YYYYMMDDHHMM format.

See Also:
toString(), fromString(java.lang.String)

equals

public boolean equals(java.lang.Object o)
Returns true if o is a DayTime representing the same date-time as this DayTime; false otherwise.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overridden to ensure consistency with equals.

Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(java.lang.Object comparisonDayTime)
Compares two DayTime objects for chronological ordering.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
comparisonDayTime - the DayTime to be compared (the declared type is Object but it must be an object that can be cast to DayTime). Cannot be null.
Returns:
a negative integer if this DayTime is before comparisonDayTime; zero if this DayTime is equal to comparisonDayTime; or a positive integer if this DayTime is after comparisonDayTime.
Throws:
java.lang.NullPointerException - if comparisonDayTime is null.
java.lang.ClassCastException - if comparisonDayTime is not a DayTime object.
See Also:
before(net.degreedays.time.DayTime), after(net.degreedays.time.DayTime)

before

public boolean before(DayTime comparisonDayTime)
Returns true if this DayTime is chronologically before comparisonDayTime; false otherwise.

Parameters:
comparisonDayTime - the DayTime to compare with this DayTime. Cannot be null.
Throws:
java.lang.NullPointerException - if comparisonDayTime is null.
See Also:
after(net.degreedays.time.DayTime), compareTo(java.lang.Object)

after

public boolean after(DayTime comparisonDayTime)
Returns true if this DayTime is chronologically after comparisonDayTime; false otherwise.

Parameters:
comparisonDayTime - the DayTime to compare with this DayTime. Cannot be null.
Throws:
java.lang.NullPointerException - if comparisonDayTime is null.
See Also:
before(net.degreedays.time.DayTime), compareTo(java.lang.Object)

minutesAfter

public 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.

Throws:
java.lang.NullPointerException - if comparisonDayTime is null.
See Also:
minutesBefore(net.degreedays.time.DayTime)

minutesBefore

public long minutesBefore(DayTime comparisonDayTime)
Returns the number of minutes that this DayTime is before comparisonDayTime, which will be negative if comparisonDayTime comes first chronologically.

Throws:
java.lang.NullPointerException - if comparisonDayTime is null.
See Also:
minutesAfter(net.degreedays.time.DayTime)


www.degreedays.net/api/