Class TimeMath

java.lang.Object
com.codename1.scheduling.TimeMath

public final class TimeMath extends Object

Calendar arithmetic on epoch milliseconds in a time zone.

The scheduling model keeps every instant as epoch milliseconds, because a view compares and subtracts them for every item it paints. These are the few places where an instant has to become a calendar day and back, and they go through java.time so a day that is 23 or 25 hours long is handled by the zone rules and not by adding 24 * 60 * 60 * 1000.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Milliseconds in a day that has no zone transition in it.
    static final long
    Milliseconds in an hour.
    static final long
    Milliseconds in a minute.
    static final int
    Minutes in a day.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    at(long epochDay, int minuteOfDay, ZoneId zone)
    The instant of a wall-clock minute on a day.
    static int
    dayOfWeek(long epochDay)
    The ISO day of the week of a day: 1 is Monday, 7 is Sunday.
    static long
    epochDay(long millis, ZoneId zone)
    The day millis falls on in zone, as a count of days since 1970-01-01.
    static int
    minuteOfDay(long millis, ZoneId zone)
    The wall-clock minute of the day at millis.
    static long
    plusMonths(long epochDay, int months)
    The first day of the month months after the one epochDay is in.
    static long
    startOfDay(long millis, ZoneId zone)
    The start of the day millis falls on.
    static long
    startOfEpochDay(long epochDay, ZoneId zone)
    The instant the day epochDay starts at in zone.
    static long
    startOfMonth(long epochDay)
    The first day of the month epochDay is in.
    static long
    startOfWeek(long epochDay, int firstDayOfWeek)
    The first day of the week epochDay is in, when weeks start on firstDayOfWeek (ISO, 1 is Monday).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MINUTE

      public static final long MINUTE
      Milliseconds in a minute.
      See Also:
    • HOUR

      public static final long HOUR
      Milliseconds in an hour.
      See Also:
    • DAY

      public static final long DAY
      Milliseconds in a day that has no zone transition in it.
      See Also:
    • MINUTES_PER_DAY

      public static final int MINUTES_PER_DAY
      Minutes in a day.
      See Also:
  • Method Details

    • epochDay

      public static long epochDay(long millis, ZoneId zone)
      The day millis falls on in zone, as a count of days since 1970-01-01.
    • startOfEpochDay

      public static long startOfEpochDay(long epochDay, ZoneId zone)
      The instant the day epochDay starts at in zone.
    • startOfDay

      public static long startOfDay(long millis, ZoneId zone)
      The start of the day millis falls on.
    • at

      public static long at(long epochDay, int minuteOfDay, ZoneId zone)
      The instant of a wall-clock minute on a day. minuteOfDay may be 1440, which is the start of the following day.
    • minuteOfDay

      public static int minuteOfDay(long millis, ZoneId zone)
      The wall-clock minute of the day at millis.
    • dayOfWeek

      public static int dayOfWeek(long epochDay)
      The ISO day of the week of a day: 1 is Monday, 7 is Sunday.
    • startOfWeek

      public static long startOfWeek(long epochDay, int firstDayOfWeek)
      The first day of the week epochDay is in, when weeks start on firstDayOfWeek (ISO, 1 is Monday).
    • startOfMonth

      public static long startOfMonth(long epochDay)
      The first day of the month epochDay is in.
    • plusMonths

      public static long plusMonths(long epochDay, int months)
      The first day of the month months after the one epochDay is in.