public final class IlvCalendarUtil extends Object
IlvCalendarUtil
class consists of static methods that
are of general use when working with Calendar
and Date
objects.
This class is a singleton and instances of this class cannot be created.Modifier and Type | Method and Description |
---|---|
static int |
compareDay(Calendar cal1,
Calendar cal2)
Compares the day of two
Calendar s for order. |
static int |
compareEra(Calendar cal1,
Calendar cal2)
Compares the era (e.g.
|
static int |
compareMonth(Calendar cal1,
Calendar cal2)
Compares the month of two
Calendar s for order. |
static int |
compareYear(Calendar cal1,
Calendar cal2)
Compares the year of two
Calendar s for order. |
static void |
dayFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest day
boundary. |
static void |
dayFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest day
boundary. |
static int |
elapsedDays(Calendar cal1,
Calendar cal2)
Returns the number of days that have elapsed from one calendar to another.
|
static void |
halfDayFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest half-day
or AM-PM boundary. |
static void |
halfDayFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest half-day
or AM-PM boundary. |
static void |
hourFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest hour
boundary. |
static void |
hourFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest hour
boundary. |
static int |
julianDay(Calendar calendar)
Returns the Julian day number of a date in the given calendar.
|
static int |
julianDay(GregorianCalendar calendar)
Returns the Julian day number of a date in the given
GregorianCalendar . |
static Date |
max(Date a,
Date b)
Returns the latest time of the 2 values.
|
static Date |
min(Date a,
Date b)
Returns the earliest time of the 2 values.
|
static void |
minuteFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest minute
boundary. |
static void |
minuteFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest minute
boundary. |
static void |
monthFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest month
boundary. |
static void |
monthFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest month
boundary. |
static void |
secondFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest second
boundary. |
static void |
secondFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest second
boundary. |
static void |
weekFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest week
boundary. |
static void |
weekFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest week
boundary. |
static void |
yearFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest year
boundary. |
static void |
yearFloor(Calendar calendar)
Truncates the given
Calendar downwards to the nearest year
boundary. |
public static Date min(Date a, Date b)
a
- A Date
value.b
- A Date
value.a
and b
.public static Date max(Date a, Date b)
a
- A Date
value.b
- A Date
value.a
and b
.public static int compareEra(Calendar cal1, Calendar cal2)
Calendar
s for order. This method returns a negative integer,
zero, or a positive integer if the era of the first calendar is before,
equal to, or after the era of the second calendar. Both calendars must be
of the same class or an IllegalArgumentException
will be thrown.cal1
- The first calendar to be compared.cal2
- The second calendar to be compared.cal1
is less than, equal to, or greater than the era of cal2
.IllegalArgumentException
- if the calendars are of different classes.public static int compareYear(Calendar cal1, Calendar cal2)
Calendar
s for order. This method
returns a negative integer, zero, or a positive integer if the year of the
first calendar is before, equal to, or after the year of the second calendar.
Both calendars must be of the same class or an IllegalArgumentException
will be thrown.cal1
- The first calendar to be compared.cal2
- The second calendar to be compared.cal1
is less than, equal to, or greater than the year of cal2
.IllegalArgumentException
- if the calendars are of different classes.public static int compareMonth(Calendar cal1, Calendar cal2)
Calendar
s for order. This method
returns a negative integer, zero, or a positive integer if the month of the
first calendar is before, equal to, or after the month of the second calendar.
Both calendars must be of the same class or an IllegalArgumentException
will be thrown.cal1
- The first calendar to be compared.cal2
- The second calendar to be compared.cal1
is less than, equal to, or greater than the month of cal2
.IllegalArgumentException
- if the calendars are of different classes.public static int compareDay(Calendar cal1, Calendar cal2)
Calendar
s for order. This method
returns a negative integer, zero, or a positive integer if the day of the
first calendar is before, equal to, or after the day of the second calendar.
Both calendars must be of the same class or an IllegalArgumentException
will be thrown.cal1
- The first calendar to be compared.cal2
- The second calendar to be compared.cal1
is less than, equal to, or greater than the day of cal2
.IllegalArgumentException
- if the calendars are of different classes.public static int julianDay(GregorianCalendar calendar)
Returns the Julian day number of a date in the given GregorianCalendar
.
The Julian day numbering system operates on a 7980 year cycle that considers
Jan 1, 4713 B.C. (i.e. -4712-01-01) as its zero point.
It is important to note that a Julian day number is not the same as the
Julian calendar. It is also important to note that the
GregorianCalendar
class is a hybrid calendar that supports both the
Julian and Gregorian calendar systems with the support of a single discontinuity.
By default, the GregorianCalendar
class considers this discontinuity to
be October 15, 1582 which is the generally accepted date that changeover was made
from the Julian to the Gregorian calendar systems. This method uses the same
changeover date in its calculations. This method makes no attempt to take account
if the supplied calendar has a non-default changeover date set on it.
calendar
- The calendar.public static int julianDay(Calendar calendar)
Returns the Julian day number of a date in the given calendar. Julian day numbering
only makes sense when using an instance of GregorianCalendar
. If the
supplied calendar is a different type, this method first converts it to a
GregorianCalendar
using the default timezone and locale.
The Julian day numbering system operates on a 7980 year cycle that considers
Jan 1, 4713 B.C. (i.e. -4712-01-01) as its zero point.
It is important to note that a Julian day number is not the same as the
Julian calendar. It is also important to note that the
GregorianCalendar
class is a hybrid calendar that supports both the
Julian and Gregorian calendar systems with the support of a single discontinuity.
By default, the GregorianCalendar
class considers this discontinuity to
be October 15, 1582 which is the generally accepted date that changeover was made
from the Julian to the Gregorian calendar systems. This method uses the same
changeover date in its calculations. This method makes no attempt to take account
if the supplied calendar has a non-default changeover date set on it.
calendar
- The calendar.julianDay(GregorianCalendar)
public static int elapsedDays(Calendar cal1, Calendar cal2)
IllegalArgumentException
will be thrown.cal1
- The first calendar.cal2
- The second calendar.cal1
to
cal2
. Zero is returned if the calendars represent the same day.IllegalArgumentException
- if the calendars are of different classes.public static void secondFloor(Calendar calendar)
Calendar
downwards to the nearest second
boundary.calendar
- The calendar.public static void secondFloor(Calendar calendar)
Calendar
downwards to the nearest second
boundary.calendar
- The calendar.public static void minuteFloor(Calendar calendar)
Calendar
downwards to the nearest minute
boundary.calendar
- The calendar.public static void minuteFloor(Calendar calendar)
Calendar
downwards to the nearest minute
boundary.calendar
- The calendar.public static void hourFloor(Calendar calendar)
Calendar
downwards to the nearest hour
boundary.calendar
- The calendar.public static void hourFloor(Calendar calendar)
Calendar
downwards to the nearest hour
boundary.calendar
- The calendar.public static void halfDayFloor(Calendar calendar)
Calendar
downwards to the nearest half-day
or AM-PM boundary.calendar
- The calendar.public static void halfDayFloor(Calendar calendar)
Calendar
downwards to the nearest half-day
or AM-PM boundary.calendar
- The calendar.public static void dayFloor(Calendar calendar)
Calendar
downwards to the nearest day
boundary.calendar
- The calendar.public static void dayFloor(Calendar calendar)
Calendar
downwards to the nearest day
boundary.calendar
- The calendar.public static void weekFloor(Calendar calendar)
Calendar
downwards to the nearest week
boundary.calendar
- The calendar.public static void weekFloor(Calendar calendar)
Calendar
downwards to the nearest week
boundary.calendar
- The calendar.public static void monthFloor(Calendar calendar)
Calendar
downwards to the nearest month
boundary.calendar
- The calendar.public static void monthFloor(Calendar calendar)
Calendar
downwards to the nearest month
boundary.calendar
- The calendar.public static void yearFloor(Calendar calendar)
Calendar
downwards to the nearest year
boundary.calendar
- The calendar.public static void yearFloor(Calendar calendar)
Calendar
downwards to the nearest year
boundary.calendar
- The calendar.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.