DateUtil¶
-
public final class
DateUtil
¶ Utility class for various classes from
org.joda.time
package. Using this class for retrieving the current date and time will allow mocking time, so should be always used throughout the platform instead of calling the underlying date-time API directly.
Methods¶
datesToDateTimes¶
daysPast¶
-
public static int
daysPast
(LocalDate localDate, DayOfWeek dayOfWeek)¶ Counts the days passed between given date and given day of week.
Parameters: - localDate – the given date
- dayOfWeek – the given day of week
Returns: the number of days passed between
localDate
and aorg.motechproject.commons.date.model.DayOfWeek
daysStarting¶
daysToCalendarWeekEnd¶
endOfDay¶
getDifferenceOfDatesInYears¶
greaterThanOrEqualTo¶
-
public static List<DateTime>
greaterThanOrEqualTo
(DateTime date, List<DateTime> dates)¶ Filters given dates and returns only those that are past or at the given date.
Parameters: - date – the date to be used as filter
- dates – dates to be filtered
Returns: list of date that are equal or greater than given date
inRange¶
-
public static boolean
inRange
(DateTime reference, DateTime start, DateTime end)¶ Checks if first date is in period between second and third.
Parameters: - reference – the date to be checked
- start – the start of the period
- end – the end of the period
Returns: true if first date is in range, false otherwise
isOnOrAfter¶
isOnOrBefore¶
lessThan¶
newDate¶
-
public static LocalDate
newDate
(int year, int month, int day)¶ Creates new instance of
LocalDate
.Parameters: - year – the year to be stored in created instance
- month – the month to be stored in created instance
- day – the day to be stored in created instance
Returns: the instance of
LocalDate
with given year, month and day
newDate¶
newDate¶
newDateTime¶
-
public static DateTime
newDateTime
(LocalDate localDate, int hour, int minute, int second)¶ Creates new instance of
DateTime
.Parameters: - localDate – the date to be stored in created instance
- hour – the hour to be stored in created instance
- minute – the minute to be stored in created instance
- second – the second to be stored in created instance
Returns: the instance of
DateTime
with given date and time
newDateTime¶
newDateTime¶
newDateTime¶
newDateTime¶
newDateTime¶
newDateTime¶
-
public static DateTime
newDateTime
(int year, int month, int day, int hour, int minute, int second)¶ Creates new
DateTime
from given information.Parameters: - year – the year to be stored
- month – the month to be stored
- day – the day to be stored
- hour – the hour to be stored
- minute – the minute to be stored
- second – the second to be stored
Returns: the new
DateTime
instance
nextApplicableWeekDay¶
nextApplicableWeekDayIncludingFromDate¶
-
public static DateTime
nextApplicableWeekDayIncludingFromDate
(DateTime fromDate, List<DayOfWeek> applicableDays)¶ Returns first next applicable week day(including current day).
Parameters: - fromDate – the date from which next day should be searched
- applicableDays – list of applicable days
Returns: next applicable week day
now¶
nowUTC¶
setTimeZone¶
setTimeZoneUTC¶
time¶
toDate¶
-
public static Date
toDate
(DateTime dateTime)¶ Converts the provided
DateTime
to aDate
using theDateTime.toDate()
method. This method is null safe and will return null for a null datetime.Parameters: - dateTime – the datetime to convert
Returns: the datetime converted to a date, or null if null was passed
toDateTimeAtStartOfDay¶
-
public static DateTime
toDateTimeAtStartOfDay
(LocalDate localDate)¶ Converts the provided
LocalDate
to aDateTime
using theLocalDate.toDateTimeAtStartOfDay()
method. This method is null safe and will return null for a null datetime.Parameters: - localDate – the local date to convert
Returns: the local date converted to a datetime, or null if null was passed