-
- All Implemented Interfaces:
public class DateHelper
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interfaceDateHelper.TimeUnit
-
Field Summary
Fields Modifier and Type Field Description private final IntegerONE_HOUR_IN_SECONDSprivate final IntegerONE_DAY_IN_SECONDSprivate final StringUNIT_YEARprivate final StringUNIT_MONTHprivate final StringUNIT_DAYprivate final StringUNIT_HOURprivate final StringUNIT_MINUTEprivate final StringUNIT_SECONDprivate Calendarcalendarpublic final static DateHelperINSTANCE
-
Method Summary
Modifier and Type Method Description final DategetCurrentDate()Method used to get the current date object. final LonggetCurrentTimestamp()Get the current timestamp final StringtoISOString(Date date)Convert a date to an ISO string in UTC final SimpleDateFormatgetDateFormatForISOString()Create a DateFormat ready to format Date objects to ISO strings final BooleanisDateInThePast(Date date)Check whether a date is in the past final DatefromISOString(String date)Get a date from an ISO string with fixed timezone (Z) final StringgetGMTTimestamp(Long timeInMs)Convert a timestamp that can be used in request headers final IntegergetNumberOfDaysBetweenTodayAndDate(Date date)Get the number of days between the specified date and today final IntegergetNumberOfSecondsBetweenNowAndDate(Date date)Get the number of seconds between the specified date and now final StringgetDurationLabel(LanguagesHelper languagesHelper, Long unitCount, String unitKey, Boolean formatBigNumber)Displays duration of time units in human readable format. final StringgetDurationLabelWithSecondsIfNeeded(LanguagesHelper languagesHelper, Long durationInSeconds)Convert duration in seconds into a displayable, human readable approximation of the duration, together with the exact value in seconds if duration is more than 1 minute final IntegergetONE_HOUR_IN_SECONDS()final IntegergetONE_DAY_IN_SECONDS()final StringgetUNIT_YEAR()final StringgetUNIT_MONTH()final StringgetUNIT_DAY()final StringgetUNIT_HOUR()final StringgetUNIT_MINUTE()final StringgetUNIT_SECOND()final CalendargetCalendar()final UnitsetCalendar(Calendar calendar)-
-
Method Detail
-
getCurrentDate
final Date getCurrentDate()
Method used to get the current date object.
-
getCurrentTimestamp
final Long getCurrentTimestamp()
Get the current timestamp
-
toISOString
final String toISOString(Date date)
Convert a date to an ISO string in UTC
- Parameters:
date- to format as Date - nullable
-
getDateFormatForISOString
final SimpleDateFormat getDateFormatForISOString()
Create a DateFormat ready to format Date objects to ISO strings
-
isDateInThePast
final Boolean isDateInThePast(Date date)
Check whether a date is in the past
- Parameters:
date- to compare as Date - nullable
-
fromISOString
final Date fromISOString(String date)
Get a date from an ISO string with fixed timezone (Z)
- Parameters:
date- to parse as String - nullable
-
getGMTTimestamp
final String getGMTTimestamp(Long timeInMs)
Convert a timestamp that can be used in request headers
- Parameters:
timeInMs- the timestamp to format
-
getNumberOfDaysBetweenTodayAndDate
final Integer getNumberOfDaysBetweenTodayAndDate(Date date)
Get the number of days between the specified date and today
- Parameters:
date- to compare as Date
-
getNumberOfSecondsBetweenNowAndDate
final Integer getNumberOfSecondsBetweenNowAndDate(Date date)
Get the number of seconds between the specified date and now
- Parameters:
date- to compare as Date
-
getDurationLabel
final String getDurationLabel(LanguagesHelper languagesHelper, Long unitCount, String unitKey, Boolean formatBigNumber)
Displays duration of time units in human readable format. Unit keys are "year", "month", "day", "hour", "minute", "second".
- Parameters:
languagesHelper- languagesHelper used to get locale-dependant resourcesunitCount- count of to displayunitKey- key for this unitformatBigNumber- whether big number should be formatted according to user language
-
getDurationLabelWithSecondsIfNeeded
final String getDurationLabelWithSecondsIfNeeded(LanguagesHelper languagesHelper, Long durationInSeconds)
Convert duration in seconds into a displayable, human readable approximation of the duration, together with the exact value in seconds if duration is more than 1 minute
- Parameters:
languagesHelper- languagesHelper used to get locale-dependant resourcesdurationInSeconds- the duration in seconds
-
getONE_HOUR_IN_SECONDS
final Integer getONE_HOUR_IN_SECONDS()
-
getONE_DAY_IN_SECONDS
final Integer getONE_DAY_IN_SECONDS()
-
getUNIT_YEAR
final String getUNIT_YEAR()
-
getUNIT_MONTH
final String getUNIT_MONTH()
-
getUNIT_DAY
final String getUNIT_DAY()
-
getUNIT_HOUR
final String getUNIT_HOUR()
-
getUNIT_MINUTE
final String getUNIT_MINUTE()
-
getUNIT_SECOND
final String getUNIT_SECOND()
-
getCalendar
final Calendar getCalendar()
-
setCalendar
final Unit setCalendar(Calendar calendar)
-
-
-
-