Class TimeUtils
java.lang.Object
ru.bgcrm.util.TimeUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckDateIntervalsIntersection(Calendar date1, Calendar date2, Calendar dateFrom, Calendar dateTo) Checks the intersection of two date intervalsstatic final CalendarDeprecated.static final Dateclear_HOUR_MIN_MIL_SEC(Date time) Deprecated.static final DateconvertCalendarToDate(Calendar calendar) static final TimestampconvertCalendarToTimestamp(Calendar calendar) static final CalendarconvertDateToCalendar(Date date) static final DateconvertDateToSqlDate(Date date) static final TimestampconvertLongToTimestamp(long millis) ConvertslongtoTimestampstatic final DateconvertSqlDateToDate(Date date) static final Calendarstatic booleandateBefore(Date date1, Date date2) Checksdate1 < date2(day precision)static booleandateBeforeOrEq(Calendar date1, Calendar date2) Checksdate1 <= date2(day precision)static booleandateBeforeOrEq(Date date1, Date date2) Checksdate1 <= date2(day precision)static booleanChecksdate1 == date2(day precision)static final booleandateInRange(Calendar checking, Calendar date1, Calendar date2) Checks whether the checked date falls within the given periodstatic final booleandateInRange(Date checking, Date date1, Date date2) Checks whether the checked date falls within the given periodstatic final int24h days difference between two dates.static final StringFormats a duration object to a human-readable string like5h 15mstatic final StringFormats a string with the date by the given patternstatic final StringformatPeriod(Date date1, Date date2) Formats a period stringstatic final StringformatPeriod(Date dateFrom, Date dateTo, String patternType) static final StringformatSqlDate(Date date) Formats a date as 'yyyy-MM-dd' for substitution into an SQL query, already wrapped in quotesstatic final intgetDayOfWeekPosition(Date date) Day of week starting from Monday = 1static final DategetEndMonth(Date date) Last day of a monthstatic final CalendargetNextDay(Calendar date) The next day from the datestatic final DategetNextDay(Date date) The next day from the datestatic final CalendargetPrevDay(Calendar date) The previous day from the datestatic final DategetPrevDay(Date date) The previous day from the datestatic final Datestatic StringgetShortDateName(Date date) Deprecated.static StringgetTypeFormat(String type) Date and time format string compatible withSimpleDateFormatstatic final voidmoveToEndOfMonth(Calendar date) Sets the date to the last day of the monthstatic final voidmoveToStartNextDay(Calendar date) Increases date by 1 day and resets the time to 00:00:00.0static final Datestatic final Datestatic final voidparsePeriod(String period, String patternType, PeriodSet periodSet) static final voidparsePeriod(String period, PeriodSet periodSet) static final booleanperiodInRange(Calendar checkingDate1, Calendar checkingDate2, Calendar date1, Calendar date2) Checks whether the checked period falls within the given onestatic DatetimezoneChange(Date time, TimeZone fromTz, TimeZone toTz) Adjusts aDateobject so that the same local time results in a different timezone
-
Field Details
-
CONF_KEY_FORMAT_YMD
- See Also:
-
CONF_KEY_FORMAT_YMDH
- See Also:
-
CONF_KEY_FORMAT_YMDHM
- See Also:
-
CONF_KEY_FORMAT_YMDHMS
- See Also:
-
PATTERN_DDMMYYYY
- See Also:
-
PATTERN_YYYYMMDD
- See Also:
-
PATTERN_YYYYMMDDHHMMSS
- See Also:
-
PATTERN_DDMMYYYYHHMMSS
- See Also:
-
FORMAT_TYPE_YMD
- See Also:
-
FORMAT_TYPE_YMDH
- See Also:
-
FORMAT_TYPE_YMDHM
- See Also:
-
FORMAT_TYPE_YMDHMS
- See Also:
-
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
getTypeFormat
Date and time format string compatible withSimpleDateFormat- Parameters:
type- type of date-time:FORMAT_TYPE_YMD,FORMAT_TYPE_YMDH,FORMAT_TYPE_YMDHM,FORMAT_TYPE_YMDHMS- Returns:
- matching date format or
typeitself
-
format
Formats a string with the date by the given pattern- Parameters:
date- the input datepatternType- the date pattern:FORMAT_TYPE_YMD,FORMAT_TYPE_YMDH,FORMAT_TYPE_YMDHM,FORMAT_TYPE_YMDHMS- Returns:
- the string if the input date is not
nulland the pattern is correct, otherwisenull
-
formatSqlDate
-
format
-
formatPeriod
-
formatPeriod
Formats a period string- Parameters:
date1- the period startdate2- the period end- Returns:
- the string "dd.MM.yyyy-dd.MM.yyyy"; if one of the parameters is
null, an empty string is printed instead of the corresponding date, e.g. "-dd.MM.yyyy", "dd.MM.yyyy-", "-"
-
parse
-
parse
-
parsePeriod
-
parsePeriod
-
convertCalendarToDate
-
convertSqlDateToDate
-
convertDateToCalendar
-
convertTimestampToCalendar
-
convertDateToSqlDate
-
convertCalendarToTimestamp
-
convertLongToTimestamp
-
daysDelta
24h days difference between two dates. The method is time-proven, but since Java 8 there is also available:ChronoUnit.DAYS.between(Temporal, Temporal)- Parameters:
dayFrom- the first daydayTo- the second day- Returns:
- the difference in days
-
getDayOfWeekPosition
Day of week starting from Monday = 1- Parameters:
date- the date- Returns:
- the day of week position
-
dateBefore
-
dateEqual
-
dateBeforeOrEq
-
dateBeforeOrEq
-
dateInRange
-
dateInRange
-
periodInRange
public static final boolean periodInRange(Calendar checkingDate1, Calendar checkingDate2, Calendar date1, Calendar date2) Checks whether the checked period falls within the given one- Parameters:
checkingDate1- the checked period startcheckingDate2- the checked period enddate1- the given period startdate2- the given period end- Returns:
trueif it falls within,falseotherwise
-
checkDateIntervalsIntersection
public static boolean checkDateIntervalsIntersection(Calendar date1, Calendar date2, Calendar dateFrom, Calendar dateTo) Checks the intersection of two date intervals- Parameters:
date1- the left bound of the first intervaldate2- the right bound of the first intervaldateFrom- the left bound of the second intervaldateTo- the right bound of the second interval- Returns:
trueif the intervals intersect, or one of them has both boundsnull
-
moveToEndOfMonth
Sets the date to the last day of the month- Parameters:
date- the input date
-
moveToStartNextDay
Increases date by 1 day and resets the time to 00:00:00.0- Parameters:
date- the input date
-
clear_HOUR_MIN_MIL_SEC
Deprecated.Resets the time to the start of the day- Parameters:
time- the input date- Returns:
- the reset date (hours=minutes=seconds=millis=0)
-
clear_HOUR_MIN_MIL_SEC
Deprecated.Resets the time to the start of the day- Parameters:
time- the input date- Returns:
- the reset date (hours=minutes=seconds=millis=0)
-
getEndMonth
-
getNextDay
-
getPrevDay
-
getNextDay
-
getPrevDay
-
getPrevMonth
- Returns:
- first day in the previous month from the current time
-
getShortDateName
Deprecated.Returns the abbreviated day-of-week name ("пн" - Monday, "вт" - Tuesday, etc.)- Parameters:
date- the date used to determine the day of week- Returns:
- the abbreviated day-of-week name
-
timezoneChange
-