Package overit.geocall.util
Class DateUtils
java.lang.Object
overit.geocall.util.DateUtils
Auxiliary class to manage dates.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static ConcurrentHashMap<String, Date> protected static ConcurrentHashMap<String, Date> static final StringDefault date format:"dd/MM/yyyy".static final StringDefault date and time format:"dd/MM/yyyy HH:mm".static final StringDefault date and time format with seconds:"dd/MM/yyyy HH:mm:ss".static final StringDefault day/month date format:"dd/MM".static final StringDefault time format:"HH:mm".static final StringDefault time format with seconds:"HH:mm:ss".static final DateConstantMaximum date supported by the system:"01/01/2999"(formatCODING_DATE).static final DateConstantMaximum date supported by MySQL:"01/01/2038"(formatCODING_DATE).static final DateConstantMinimum date supported by the system:"01/01/1800"(formatCODING_DATE).static final intType of unit to use in the parameter of the methodgetDateDifference()to set the days.static final intType of unit to use in the parameter of the methodgetDateDifference()to set the hours.protected LogChannelstatic final intType of unit to use in the parameter of the methodgetDateDifference()to set the milliseconds.static final intType of unit to use in the parameter of the methodgetDateDifference()to set the minutes.static final intType of unit to use in the parameter of the methodgetDateDifference()to set the seconds.static final DateConstantMaximum time of the system based on JVM time zone:"02 00:00"(format"dd HH:mm").static final DateConstantMinimum time of the system based on JVM time zone:"00:00"(format"HH:mm"). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DategetCombinedDateTime(Date hours, Date date) This method take an hour and a date (both in Date format) and create a combination of themstatic intgetDateDifference(Date from, Date to, int unit) Deprecated.static DategetDateFromInstant(Instant instant) Convert an instant into a Date instancestatic DategetDayFromDate(Date date) Get only the day from the input date and create a new date containing the union of this day with the time"00:00:00".static InstantgetInstantFromDate(Date date) Convert a date into an Instant instancestatic intgetInterval(TimeZone tz, Date from, Date to, int unit) Calculate the difference between two dates, keeping in mind the daylight savings time.static intgetLocalInterval(Date from, Date to, int unit) Calculate the difference between two dates, keeping in mind the daylight savings time.static StringgetRegexpFromDateFormat(String pattern) This method extracts the regular expression related to the format of the date passed in input.static DategetTimeFromDate(Date date) Get only the time from the input date and create a new date containing the union of this time with the day"01 January 1970".static DatemergeDateToTime(Date time, String sdfDate, String sDate, TimeZone tz) Create and return a new date merging the time passed as first parameter with the day built with the combination of the other three parameters.static DatemergeTimeToDate(Date date, String sdfTime, String sTime, TimeZone tz) Create and return a new date merging the date passed as first parameter with the time built with the combination of the other three parameters.static DatemergeTimeToDate(Date day, Date hour) Create and return a new date merging the two date inputs: day and hour.static final SimpleDateFormatsdfData()Return the default format to apply on the date string.static final SimpleDateFormatReturn the default format to apply on the date and time string.static final SimpleDateFormatReturn the default format to apply on the date and time string containing the seconds.static final SimpleDateFormatsdfOra()Return the default format to apply on the time string.static DatesumDayToDate(Date date, int days) Add the number of days passed as second input to the date passed as first input and return the new date.static DatesumHourToDate(Date date, int hours) Add the number of hours passed as second input to the date passed as first input and return the new date.static DatesumMinuteToDate(Date date, int minutes) Add the number of minutes passed as second input to the date passed as first input and return the new date.static DatesumMonthToDate(Date date, int months) Add the number of months passed as second input to the date passed as first input and return the new date.static DatesumSecondToDate(Date date, int seconds) Add the number of seconds passed as second input to the date passed as first input and return the new date.static DatesumYearToDate(Date date, int years) Add the number of years passed as second input to the date passed as first input and return the new date.static DateReturn theTIME_MAXconverted to the input time zone.static DateReturn theTIME_MINconverted to the input time zone.static DateReturns a copy of the passed date truncated to the specified unit.
-
Field Details
-
LOG
-
CODING_TIME
Default time format:"HH:mm".- See Also:
-
CODING_TIMESEC
Default time format with seconds:"HH:mm:ss".- See Also:
-
CODING_DATE
Default date format:"dd/MM/yyyy".- See Also:
-
CODING_DAYMONTH
Default day/month date format:"dd/MM".- See Also:
-
CODING_DATETIME
Default date and time format:"dd/MM/yyyy HH:mm".- See Also:
-
CODING_DATETIMESECS
Default date and time format with seconds:"dd/MM/yyyy HH:mm:ss".- See Also:
-
TIME_MIN
Minimum time of the system based on JVM time zone:"00:00"(format"HH:mm"). -
TIME_MAX
Maximum time of the system based on JVM time zone:"02 00:00"(format"dd HH:mm"). -
DATE_MIN
Minimum date supported by the system:"01/01/1800"(formatCODING_DATE). -
DATE_MAX
Maximum date supported by the system:"01/01/2999"(formatCODING_DATE). -
DATE_MAX_FOR_MYSQL
Maximum date supported by MySQL:"01/01/2038"(formatCODING_DATE). -
_timeMins
-
_timeMaxs
-
MILLISECOND
public static final int MILLISECONDType of unit to use in the parameter of the methodgetDateDifference()to set the milliseconds.- See Also:
-
SECOND
public static final int SECONDType of unit to use in the parameter of the methodgetDateDifference()to set the seconds.- See Also:
-
MINUTE
public static final int MINUTEType of unit to use in the parameter of the methodgetDateDifference()to set the minutes.- See Also:
-
HOUR
public static final int HOURType of unit to use in the parameter of the methodgetDateDifference()to set the hours.- See Also:
-
DAY
public static final int DAYType of unit to use in the parameter of the methodgetDateDifference()to set the days.- See Also:
-
-
Constructor Details
-
DateUtils
protected DateUtils()
-
-
Method Details
-
timeMin
Return theTIME_MINconverted to the input time zone. The time to convert is based on the time zone of the JVM.- Parameters:
tz- Time zone to use for the conversion.- Returns:
- The date containing the converted time.
-
timeMax
Return theTIME_MAXconverted to the input time zone. The time to convert is based on the time zone of the JVM.- Parameters:
tz- Time zone to use for the conversion.- Returns:
- The date containing the converted time.
-
sdfOra
Return the default format to apply on the time string.- Returns:
- The
SimpleDateFormatfor the time.
-
sdfData
Return the default format to apply on the date string.- Returns:
- The
SimpleDateFormatfor the date.
-
sdfDataOra
Return the default format to apply on the date and time string.- Returns:
- The
SimpleDateFormatfor the date and time.
-
sdfDataOraSecondi
Return the default format to apply on the date and time string containing the seconds.- Returns:
- The
SimpleDateFormatfor the date and time with seconds.
-
mergeTimeToDate
Create and return a new date merging the two date inputs: day and hour. The formats used aresdfData()for the day,sdfOra()for the time andsdfDataOra()for the merge.- Parameters:
day- The day to use in the merge.hour- The time to use in the merge.- Returns:
- The new date resulting from the union of the two inputs.
-
mergeTimeToDate
Create and return a new date merging the date passed as first parameter with the time built with the combination of the other three parameters.
If the format of the time or the string containing the time are null, the date passed in input will be returned.- Parameters:
date- The day to use in the merge.sdfTime- The string containing the format to use to parse the time string (seeSimpleDateFormat).sTime- The string containing the value of the time to use in the merge.tz- TheTimeZoneof the time passed as parameter.- Returns:
- The new date resulting from the merge of the day with the time.
-
mergeDateToTime
Create and return a new date merging the time passed as first parameter with the day built with the combination of the other three parameters.
If the format of the day or the string containing the day are null, the time passed in input will be returned.- Parameters:
time- The time to use in the merge.sdfDate- The string containing the format to use to parse the string of the day (seeSimpleDateFormat).sDate- The string containing the value of the day to use in the merge.tz- TheTimeZoneof the day passed as parameter.- Returns:
- The new date resulting from the merge of the time with the day.
-
getTimeFromDate
Get only the time from the input date and create a new date containing the union of this time with the day"01 January 1970". The format is determinated bysdfOra().- Parameters:
date- The date from which to extract the time.- Returns:
- The date containing the union of the time extract from the input
with the day
"01 January 1970".
-
getDayFromDate
Get only the day from the input date and create a new date containing the union of this day with the time"00:00:00". The format is determinated bysdfData().- Parameters:
date- The date from which to extract the day.- Returns:
- The date containing the union of the day extract from the input
with the time
"00:00:00".
-
sumSecondToDate
Add the number of seconds passed as second input to the date passed as first input and return the new date.- Parameters:
date- The date to add the seconds.seconds- Number of seconds to add to the date.- Returns:
- The date generated by adding the seconds.
-
sumMinuteToDate
Add the number of minutes passed as second input to the date passed as first input and return the new date.- Parameters:
date- The date to add the minutes.minutes- Number of minutes to add to the date.- Returns:
- The date generated by adding the minutes.
-
sumHourToDate
Add the number of hours passed as second input to the date passed as first input and return the new date.- Parameters:
date- The date to add the hours.hours- Number of hours to add to the date.- Returns:
- The date generated by adding the hours.
-
sumDayToDate
Add the number of days passed as second input to the date passed as first input and return the new date.- Parameters:
date- The date to add the days.days- Number of days to add to the date.- Returns:
- The date generated by adding the days.
-
sumYearToDate
Add the number of years passed as second input to the date passed as first input and return the new date.- Parameters:
date- The date to add the years.years- Number of years to add to the date.- Returns:
- The date generated by adding the years.
-
sumMonthToDate
Add the number of months passed as second input to the date passed as first input and return the new date.- Parameters:
date- The date to add the months.months- Number of months to add to the date.- Returns:
- The date generated by adding the months.
-
getDateDifference
Deprecated.Calculate the difference between two dates, keeping in mind the daylight savings time. Return a number that rappresents the amount of time expressed with the unit of measure passed in theunitparameter. -
getInterval
Calculate the difference between two dates, keeping in mind the daylight savings time. Return a number that rappresents the amount of time expressed with the unit of measure passed in theunitparameter. -
getLocalInterval
Calculate the difference between two dates, keeping in mind the daylight savings time. Return a number that rappresents the amount of time expressed with the unit of measure passed in theunitparameter. -
getCombinedDateTime
This method take an hour and a date (both in Date format) and create a combination of them- Parameters:
hours- The published values's HashGetterdate- Actual InputDate's value- Returns:
- A Date which is the combination of date and hours
- Throws:
ParseException- If an error has been reached unexpectedly while parsing
-
getRegexpFromDateFormat
This method extracts the regular expression related to the format of the date passed in input. Date format must respect the java Date and Time Patterns- Parameters:
pattern- the pattern describing the date format- Returns:
- the regexp matches the passed date pattern
-
trunc
Returns a copy of the passed date truncated to the specified unit. Truncate the given date at the specified time unit. The supported units are:- Calendar.MILLISECOND: to round down to the nearest millisecond
- Calendar.SECOND: to round down to the nearest second, setting the millis to 0
- Calendar.MINUTE: to round down to the nearest minute, setting the seconds and millis to 0
- Calendar.HOUR_OF_DAY: to round down to the nearest hour, setting the minute, seconds and millis to 0
- Calendar.DAY_OF_WEEK: to round down to the nearest day, setting the hours, minutes, seconds and millis to 0
- Calendar.DAY_OF_MONTH: to round down to the nearest first day of week, setting the hours, minutes, seconds and millis to 0
- Calendar.MONTH: to round down to the nearest first month, setting the first day and the hours, minutes, seconds and millis to 0
- Parameters:
d- the date that will be truncatedunit- the time unit- Returns:
- the truncated date
-
getInstantFromDate
Convert a date into an Instant instance- Parameters:
date- the date to convert- Returns:
- the instant instance or null if the passed date is null
-
getDateFromInstant
Convert an instant into a Date instance- Parameters:
instant- the instant to convert- Returns:
- the date instance or null if the passed instant is null
-
getLocalInterval(java.util.Date, java.util.Date, int)instead