Class DayRelativeTime

java.lang.Object
com.tccc.kos.commons.util.DayRelativeTime

public final class DayRelativeTime extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Given a Calendar , return the corresponding day relative time as seconds from midnight.
    static int
    Given a Date , 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 a Calendar that corresponds to the next occurrence of the time.
    static Date
    getNextOccurrenceDate(int secFromMidnight)
    Given a day relative time in seconds from midnight, return a Date 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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static Date getNextOccurrenceDate(int secFromMidnight)
      Given a day relative time in seconds from midnight, return a Date that corresponds to the next occurrence of the time.
      Parameters:
      secFromMidnight - day relative time in seconds from midnight
    • getNextOccurrenceCalendar

      public static Calendar getNextOccurrenceCalendar(int secFromMidnight)
      Given a day relative time in seconds from midnight, return a Calendar that corresponds to the next occurrence of the time.
      Parameters:
      secFromMidnight - day relative time in seconds from midnight
    • getDayRelativeTime

      public static int getDayRelativeTime(Date date)
      Given a Date , 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

      public static int getDayRelativeTime(Calendar cal)
      Given a Calendar , 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