Package net.fortuna.ical4j.util
Class Dates
- java.lang.Object
-
- net.fortuna.ical4j.util.Dates
-
public final class Dates extends Object
$Id$ Created on 26/06/2005 Implements a collection of utility methods relevant to date processing.
-
-
Field Summary
Fields Modifier and Type Field Description static intDAYS_PER_WEEKNumber of days in one week.static intMAX_DAYS_PER_MONTHMaximum number of days per month.static intMAX_DAYS_PER_YEARMaximum number of days per year.static intMAX_WEEKS_PER_YEARMaximum number of weeks per year.static longMILLIS_PER_DAYNumber of milliseconds in one day.static longMILLIS_PER_HOURNumber of milliseconds in one hour.static longMILLIS_PER_MINUTENumber of milliseconds in one minute.static longMILLIS_PER_SECONDNumber of milliseconds in one second.static longMILLIS_PER_WEEKNumber of milliseconds in one week.static intPRECISION_DAYConstant indicating precision to the day.static intPRECISION_SECONDConstant indicating precision to the second.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intgetAbsMonthDay(Date date, int monthDay)Returns the absolute month day for the month specified by the supplied date.static intgetAbsWeekNo(Date date, int weekNo)Returns the absolute week number for the year specified by the supplied date.static intgetAbsYearDay(Date date, int yearDay)Returns the absolute year day for the year specified by the supplied date.static CalendargetCalendarInstance(Date date)Returns an instance ofjava.util.Calendarthat is suitably initialised for working with the specified date.static longgetCurrentTimeRounded()Returns theSystem.currentTimeMillis(), rounded to the second.static DateListgetDateListInstance(DateList origList)Instantiate a new datelist with the same type, timezone and utc settings as the origList.static DategetInstance(Date date, Value type)Returns a new date instance of the specified type.static longround(long time, int precision)Deprecated.It is not all that useful to perform rounding without specifying an explicit timezone.static longround(long time, int precision, TimeZone tz)Rounds a time value to remove any precision smaller than specified.
-
-
-
Field Detail
-
MILLIS_PER_SECOND
public static final long MILLIS_PER_SECOND
Number of milliseconds in one second.- See Also:
- Constant Field Values
-
MILLIS_PER_MINUTE
public static final long MILLIS_PER_MINUTE
Number of milliseconds in one minute.- See Also:
- Constant Field Values
-
MILLIS_PER_HOUR
public static final long MILLIS_PER_HOUR
Number of milliseconds in one hour.- See Also:
- Constant Field Values
-
MILLIS_PER_DAY
public static final long MILLIS_PER_DAY
Number of milliseconds in one day.- See Also:
- Constant Field Values
-
MILLIS_PER_WEEK
public static final long MILLIS_PER_WEEK
Number of milliseconds in one week.- See Also:
- Constant Field Values
-
DAYS_PER_WEEK
public static final int DAYS_PER_WEEK
Number of days in one week.- See Also:
- Constant Field Values
-
PRECISION_SECOND
public static final int PRECISION_SECOND
Constant indicating precision to the second.- See Also:
- Constant Field Values
-
PRECISION_DAY
public static final int PRECISION_DAY
Constant indicating precision to the day.- See Also:
- Constant Field Values
-
MAX_WEEKS_PER_YEAR
public static final int MAX_WEEKS_PER_YEAR
Maximum number of weeks per year.- See Also:
- Constant Field Values
-
MAX_DAYS_PER_YEAR
public static final int MAX_DAYS_PER_YEAR
Maximum number of days per year.- See Also:
- Constant Field Values
-
MAX_DAYS_PER_MONTH
public static final int MAX_DAYS_PER_MONTH
Maximum number of days per month.- See Also:
- Constant Field Values
-
-
Method Detail
-
getAbsWeekNo
public static int getAbsWeekNo(Date date, int weekNo)
Returns the absolute week number for the year specified by the supplied date. Note that a value of zero (0) is invalid for the weekNo parameter and anIllegalArgumentExceptionwill be thrown.- Parameters:
date- a date instance representing a week of the yearweekNo- a week number offset- Returns:
- the absolute week of the year for the specified offset
-
getAbsYearDay
public static int getAbsYearDay(Date date, int yearDay)
Returns the absolute year day for the year specified by the supplied date. Note that a value of zero (0) is invalid for the yearDay parameter and anIllegalArgumentExceptionwill be thrown.- Parameters:
date- a date instance representing a day of the yearyearDay- a day of year offset- Returns:
- the absolute day of month for the specified offset
-
getAbsMonthDay
public static int getAbsMonthDay(Date date, int monthDay)
Returns the absolute month day for the month specified by the supplied date. Note that a value of zero (0) is invalid for the monthDay parameter and anIllegalArgumentExceptionwill be thrown.- Parameters:
date- a date instance representing a day of the monthmonthDay- a day of month offset- Returns:
- the absolute day of month for the specified offset
-
getInstance
public static Date getInstance(Date date, Value type)
Returns a new date instance of the specified type. If no type is specified a DateTime instance is returned.- Parameters:
date- a seed Java date instancetype- the type of date instance- Returns:
- an instance of
net.fortuna.ical4j.model.Date
-
getCalendarInstance
public static Calendar getCalendarInstance(Date date)
Returns an instance ofjava.util.Calendarthat is suitably initialised for working with the specified date.- Parameters:
date- a date instance- Returns:
- a
java.util.Calendar
-
getDateListInstance
public static DateList getDateListInstance(DateList origList)
Instantiate a new datelist with the same type, timezone and utc settings as the origList.- Parameters:
origList-- Returns:
- a new empty list.
-
round
public static long round(long time, int precision)Deprecated.It is not all that useful to perform rounding without specifying an explicit timezone.- Parameters:
time- the time value to roundprecision- the rounding precision- Returns:
- a round time value
-
round
public static long round(long time, int precision, TimeZone tz)Rounds a time value to remove any precision smaller than specified.- Parameters:
time- the time value to roundprecision- the rounding precisiontz- the timezone of the rounded value- Returns:
- a round time value
-
getCurrentTimeRounded
public static long getCurrentTimeRounded()
Returns theSystem.currentTimeMillis(), rounded to the second.By doing a rough rounding here, we avoid an expensive java.util.Calendar based rounding later on.
- Returns:
- the current time in millisec.
-
-