public class CalendarTools
extends java.lang.Object
CalendarTools provides methods useful for determining
public holidays and calculating dates.| Modifier and Type | Class and Description |
|---|---|
static class |
CalendarTools.DayOfYear
Represents a day of an unspecific year, that is just a month and a day.
|
| Constructor and Description |
|---|
CalendarTools() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.Calendar |
addDays(java.util.Calendar day,
int daysToAdd)
Adds (or subtracts) the designated amount of days to the designated day.
|
static java.util.Calendar |
createUtcCalendar(boolean setMidnight)
Returns a new
Calendar with UTC as its time zone, the current date and either the
current time or midnight. |
static boolean |
equals(java.util.Calendar c1,
java.util.Calendar c2,
int field)
Compares two calendars and returns whether they are equal with respect to
the designated field.
|
static java.util.Calendar |
getEasterSunday(java.util.Calendar year)
Returns the day of the easter sunday in the designated year, determined by the algorithm in
Butchers "Ecclesiastical Calendar".
|
static long |
setDateInMillis(long time,
int year,
int month,
int day)
Sets the designated year, month and day in the designated time (of long)
and returns the new date/time.
|
static long |
setDateInMillis(long time,
int year,
int month,
int day,
java.util.Locale locale)
Sets the designated year, month and day in the designated time (of long)
and returns the new date/time.
|
static long |
setTimeInMillis(long date,
int hours,
int minutes,
int seconds)
Sets the designated hours, minutes and seconds in the designated date (of
long) and returns the new date/time.
|
static long |
setTimeInMillis(long date,
int hours,
int minutes,
int seconds,
java.util.Locale locale)
Sets the designated hours, minutes and seconds in the designated date (of
long) and returns the new date/time.
|
static java.util.Calendar |
weekdayRelativeTo(int weekday,
java.util.Calendar day,
boolean before)
Gets the day which represents the first weekday relative the designated
day, for instance, a wednesday before a specific date.
|
public static boolean equals(java.util.Calendar c1,
java.util.Calendar c2,
int field)
Calendar.YEAR,
Calendar.MONTH, Calendar.WEEK_OF_YEAR,
Calendar.DATE, Calendar.HOUR_OF_DAY,
Calendar.MINUTE, Calendar.SECOND and
Calendar.MILLISECOND. Smaller units include the bigger units, for
instance when respecting minutes, day (date), month, year and era are also
considered while seconds (and milliseconds) are ignored. No other
information is considered, for instance time zones and calendar style.
Calendar,
one can also use units between the ones listed above. For instance,
specifying Calendar.DAY_OF_WEEK yields the same result as
Calendar.DATE.c1 - The calendars to compare with.c2 - The other calendar to compare.field - The field which is the least unit to be considered in the
comparison.public static java.util.Calendar addDays(java.util.Calendar day,
int daysToAdd)
day - The day to add the designated amount of days to.daysToAdd - The number of days to add (or subtract) to (or from) the
designated day.public static java.util.Calendar weekdayRelativeTo(int weekday,
java.util.Calendar day,
boolean before)
weekday - The day of week of the desired
day.day - The day determining the desired day.before - Whether the desired day is before the designated day.public static java.util.Calendar getEasterSunday(java.util.Calendar year)
year - The year of which to retrieve the easter sunday.public static long setDateInMillis(long time,
int year,
int month,
int day)
time contains time
information (hours, minutes, seconds, milliseconds), this will be retained.
If you want to set a completely new date, use 0 for time. time - The time for which to set the year, month and day.year - The year which to set.month - The month which to set (0-based, that is 0-11 are valid
months).day - The day which to set.public static long setDateInMillis(long time,
int year,
int month,
int day,
java.util.Locale locale)
time contains time
information (hours, minutes, seconds, milliseconds), this will be retained.
If you want to set a completely new date, use 0 for time. time - The time for which to set the year, month and day.year - The year which to set.month - The month which to set (0-based, that is 0-11 are valid
months).day - The day which to set.locale - The locale for the calendar to adapt the date.public static long setTimeInMillis(long date,
int hours,
int minutes,
int seconds)
date contains date
information (year, month, day), this will be retained. If you want to set a
completely new time, use 0 for date. date - The time for which to set the hours, minutes and seconds.hours - The hours which to set (0-based, 24-hour clock, 0-23 are valid
hours).minutes - The minutes which to set (0-based, that is 0-59 are valid
minutes).seconds - The minutes which to set (0-based, that is 0-59 are valid
seconds).public static long setTimeInMillis(long date,
int hours,
int minutes,
int seconds,
java.util.Locale locale)
date contains date
information (year, month, day), this will be retained. If you want to set a
completely new time, use 0 for date. date - The time for which to set the hours, minutes and seconds.hours - The hours which to set (0-based, 24-hour clock, 0-23 are valid
hours).minutes - The minutes which to set (0-based, that is 0-59 are valid
minutes).seconds - The minutes which to set (0-based, that is 0-59 are valid
seconds).locale - The locale for the calendar to adapt the time.public static java.util.Calendar createUtcCalendar(boolean setMidnight)
Calendar with UTC as its time zone, the current date and either the
current time or midnight.setMidnight - Whether to set the time to midnight of the current date.Calendar with UTC as its time zone, the current date and either the
current time or midnight.