Package org.javarosa.core.model.utils
Class DateUtils
java.lang.Object
org.javarosa.core.model.utils.DateUtils
public class DateUtils extends Object
Static utility methods for Dates in j2me
- Author:
- Clayton Sims
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDateUtils.DateFields -
Field Summary
Fields Modifier and Type Field Description static longDAY_IN_MSstatic intFORMAT_HUMAN_READABLE_DAYS_FROM_TODAYstatic intFORMAT_HUMAN_READABLE_SHORTstatic intFORMAT_ISO8601static intFORMAT_TIMESTAMP_HTTPRFC 822static intFORMAT_TIMESTAMP_SUFFIX -
Constructor Summary
Constructors Constructor Description DateUtils() -
Method Summary
Modifier and Type Method Description static DatedateAdd(Date d, int n)add n days to date dstatic intdateDiff(Date a, Date b)return the number of days between a and b, positive if b is later than astatic intdaysInMonth(int month, int year)Returns the number of days in the month given for a given year.static intdaysSinceEpoch(Date date)static doubledecimalTimeOfLocalDay(Date d)Returns the fractional time within the local day.static Stringformat(Date d, String format)static Stringformat(DateUtils.DateFields f, String format)static StringformatDate(Date d, int format)static StringformatDateTime(Date d, int format)static StringformatDateToTimeStamp(Date date)static StringformatTime(Date d, int format)static DoublefractionalDaysSinceEpoch(Date a)static Stringget24HourTimeFromDate(Date d)static DategetDate(int year, int month, int day)static DategetDate(DateUtils.DateFields f)static DategetDate(DateUtils.DateFields f, String timezone)static DategetDateFromString(String value)static DategetDateTimeFromString(String value)static DateUtils.DateFieldsgetFields(Date d)static DateUtils.DateFieldsgetFields(Date d, String timezone)static intgetMonthsDifference(Date earlierDate, Date laterDate)Gets the number of months separating the two dates.static DategetPastPeriodDate(Date ref, String type, String start, boolean beginning, boolean includeToday, int nAgo)Creates a Date object representing the amount of time between the reference date, and the given parameters.static StringgetShortStringValue(Date val)static StringgetXMLStringValue(Date val)static StringintPad(int n, int pad)Converts an integer to a string, ensuring that the string contains a certain number of digitsstatic booleanisLeap(int year)Determines whether a year is a leap year in the proleptic Gregorian calendar.static DateparseDate(String str)static DateparseDateTime(String str)static DateparseTime(String str)static DateparseTimeWithFixedDate(String str, DateUtils.DateFields fields)static DateroundDate(Date d)static List<String>split(String str, String delimiter, boolean combineMultipleDelimiters)Tokenizes a string based on the given delimiter stringstatic booleanstringContains(String string, String substring)static Datetoday()
-
Field Details
-
FORMAT_ISO8601
public static final int FORMAT_ISO8601- See Also:
- Constant Field Values
-
FORMAT_HUMAN_READABLE_SHORT
public static final int FORMAT_HUMAN_READABLE_SHORT- See Also:
- Constant Field Values
-
FORMAT_HUMAN_READABLE_DAYS_FROM_TODAY
public static final int FORMAT_HUMAN_READABLE_DAYS_FROM_TODAY- See Also:
- Constant Field Values
-
FORMAT_TIMESTAMP_SUFFIX
public static final int FORMAT_TIMESTAMP_SUFFIX- See Also:
- Constant Field Values
-
FORMAT_TIMESTAMP_HTTP
public static final int FORMAT_TIMESTAMP_HTTPRFC 822- See Also:
- Constant Field Values
-
DAY_IN_MS
public static final long DAY_IN_MS- See Also:
- Constant Field Values
-
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
getFields
-
getFields
-
getDate
-
getDate
-
formatDateTime
-
formatDate
-
formatTime
-
format
-
format
-
parseDateTime
-
parseDate
-
parseTime
-
parseTimeWithFixedDate
-
getDate
-
roundDate
- Returns:
- new Date object with same date but time set to midnight (in current timezone)
-
today
-
decimalTimeOfLocalDay
Returns the fractional time within the local day.- Parameters:
d-- Returns:
-
daysInMonth
public static int daysInMonth(int month, int year)Returns the number of days in the month given for a given year.- Parameters:
month- The month to be testedyear- The year in which the month is to be tested- Returns:
- the number of days in the given month on the given year.
-
isLeap
public static boolean isLeap(int year)Determines whether a year is a leap year in the proleptic Gregorian calendar.- Parameters:
year- The year to be tested- Returns:
- True, if the year given is a leap year, false otherwise.
-
getPastPeriodDate
public static Date getPastPeriodDate(Date ref, String type, String start, boolean beginning, boolean includeToday, int nAgo)Creates a Date object representing the amount of time between the reference date, and the given parameters.- Parameters:
ref- The starting reference datetype- "week", or "month", representing the time period which is to be returned.start- "sun", "mon", ... etc. representing the start of the time period.beginning- true=return first day of period, false=return last day of periodincludeToday- Whether to include the current date in the returned calculationnAgo- How many periods ago. 1=most recent period, 0=period in progress- Returns:
- a Date object representing the amount of time between the reference date, and the given parameters.
-
getMonthsDifference
Gets the number of months separating the two dates.- Parameters:
earlierDate- The earlier date, chronologicallylaterDate- The later date, chronologically- Returns:
- the number of months separating the two dates.
-
daysSinceEpoch
- Parameters:
date- the date object to be analyzed- Returns:
- The number of days (as a double precision floating point) since the Epoch
-
fractionalDaysSinceEpoch
-
dateAdd
add n days to date d- Parameters:
d-n-- Returns:
-
dateDiff
return the number of days between a and b, positive if b is later than a- Parameters:
a-b-- Returns:
- # days difference
-
split
Tokenizes a string based on the given delimiter string- Parameters:
str- The string to be splitdelimiter- The delimeter to be used- Returns:
- An array of strings contained in original which were seperated by the delimeter
-
intPad
Converts an integer to a string, ensuring that the string contains a certain number of digits- Parameters:
n- The integer to be convertedpad- The length of the string to be returned- Returns:
- A string representing n, which has pad - #digits(n) 0's preceding the number.
-
formatDateToTimeStamp
-
getShortStringValue
-
getXMLStringValue
-
get24HourTimeFromDate
-
getDateFromString
-
getDateTimeFromString
-
stringContains
-