Package com.tccc.kos.commons.util
Class DayRelativeTime
java.lang.Object
com.tccc.kos.commons.util.DayRelativeTime
Utility class for day relative time operations. A day relative time is one
that is recorded as seconds from midnight. This format is simple to encode
and transfer and is timezone independent.
There are many processes that trigger at a given time of day. Day relative time can be used to determine the start time for such processes. If local time is before a day relative time, the next occurrence is in the current day, while if after the time in local time, the next occurrence is tomorrow.
As with all time related operations, this should be used in conjunction with
TimeChangeListener
so times can be re-evaluated when time / date or
timezone changes are made.
- Since:
- 1.0
- Version:
- 2023-03-06
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
Given aCalendar
, return the corresponding day relative time as seconds from midnight.static int
getDayRelativeTime
(Date date) Given aDate
, return the corresponding day relative time as seconds from midnight.static Calendar
getNextOccurrenceCalendar
(int secFromMidnight) Given a day relative time in seconds from midnight, return aCalendar
that corresponds to the next occurrence of the time.static Date
getNextOccurrenceDate
(int secFromMidnight) Given a day relative time in seconds from midnight, return aDate
that corresponds to the next occurrence of the time.static long
getNextOccurrenceMs
(int secFromMidnight) Given a day relative time in seconds from midnight, return the number of milliseconds to the next occurrence of the time.
-
Constructor Details
-
DayRelativeTime
public DayRelativeTime()
-
-
Method Details
-
getNextOccurrenceMs
public static long getNextOccurrenceMs(int secFromMidnight) Given a day relative time in seconds from midnight, return the number of milliseconds to the next occurrence of the time.- Parameters:
secFromMidnight
- day relative time in seconds from midnight
-
getNextOccurrenceDate
Given a day relative time in seconds from midnight, return aDate
that corresponds to the next occurrence of the time.- Parameters:
secFromMidnight
- day relative time in seconds from midnight
-
getNextOccurrenceCalendar
Given a day relative time in seconds from midnight, return aCalendar
that corresponds to the next occurrence of the time.- Parameters:
secFromMidnight
- day relative time in seconds from midnight
-
getDayRelativeTime
Given aDate
, return the corresponding day relative time as seconds from midnight. This only uses the hour / min / sec portion of the date.- Parameters:
date
- the date to compute day relative time from
-
getDayRelativeTime
Given aCalendar
, return the corresponding day relative time as seconds from midnight. This only uses the hour / min / sec portion of the calendar.- Parameters:
cal
- the calendar to compute day relative time from
-