Class WorkCalendar

java.lang.Object
com.codename1.scheduling.WorkCalendar

public final class WorkCalendar extends Object

The hours work happens in: a weekly pattern, and the days that differ from it.

A duration in a project is working time. Two days of work that start on a Friday afternoon end on Tuesday, and this is the class that says so. A Scheduler reads the same object to shade the hours nobody works.

The default is Monday to Friday, 09:00 to 17:00, in the device's zone.

  • Constructor Summary

    Constructors
    Constructor
    Description
    A Monday to Friday, 09:00 to 17:00 calendar in the device's zone.
    A Monday to Friday, 09:00 to 17:00 calendar in zone.
  • Method Summary

    Modifier and Type
    Method
    Description
    addHoliday(long epochDay)
    Makes one date a day off, whatever the week says.
    long
    addWorkingTime(long from, long duration)
    The instant duration milliseconds of working time after from.
    A calendar in which every minute of every day is working time, for durations that are elapsed time.
    long
    The working time in a full day of the weekly pattern, which is what "a day" of duration means in this calendar.
    int[]
    getWorkingHours(long epochDay)
    The working hours of a date, as pairs of minutes since midnight.
     
    boolean
    isWorkingDay(long epochDay)
     
    boolean
    isWorkingTime(long millis)
    Whether millis is inside working hours.
    boolean
    isWorkingWeekday(int isoDay)
     
    long
    nextWorkingTime(long millis)
    The first working instant at or after millis.
    long
    previousWorkingTime(long millis)
    The last instant at or before millis that work can end at: millis itself when it is inside working hours or closes them.
    removeException(long epochDay)
    Returns a date to the weekly pattern.
    setException(long epochDay, int... startEndMinutes)
    Gives one date hours of its own, whatever the week says.
    setWorkingDay(int isoDay, boolean working)
    Whether a day of the week is worked.
    setWorkingHours(int... startEndMinutes)
    The hours of every working day that has none of its own, as pairs of minutes since midnight: setWorkingHours(8 * 60, 12 * 60, 13 * 60, 17 * 60) is a day with a lunch break.
    setWorkingHours(int isoDay, int[] startEndMinutes)
    The hours of one day of the week, which also makes it a working day.
    long
    subtractWorkingTime(long from, long duration)
    The instant duration milliseconds of working time before from.
    long
    workingTimeBetween(long from, long to)
    The working time between two instants, negative when to is before from.

    Methods inherited from class Object

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

    • WorkCalendar

      public WorkCalendar()
      A Monday to Friday, 09:00 to 17:00 calendar in the device's zone.
    • WorkCalendar

      public WorkCalendar(ZoneId zone)
      A Monday to Friday, 09:00 to 17:00 calendar in zone.
  • Method Details

    • continuous

      public static WorkCalendar continuous(ZoneId zone)
      A calendar in which every minute of every day is working time, for durations that are elapsed time.
    • getZone

      public ZoneId getZone()
    • setWorkingDay

      public WorkCalendar setWorkingDay(int isoDay, boolean working)
      Whether a day of the week is worked. isoDay is 1 for Monday to 7 for Sunday.
    • isWorkingWeekday

      public boolean isWorkingWeekday(int isoDay)
    • setWorkingHours

      public WorkCalendar setWorkingHours(int... startEndMinutes)
      The hours of every working day that has none of its own, as pairs of minutes since midnight: setWorkingHours(8 * 60, 12 * 60, 13 * 60, 17 * 60) is a day with a lunch break. An end of 1440 is midnight.
    • setWorkingHours

      public WorkCalendar setWorkingHours(int isoDay, int[] startEndMinutes)
      The hours of one day of the week, which also makes it a working day.
    • addHoliday

      public WorkCalendar addHoliday(long epochDay)
      Makes one date a day off, whatever the week says.
    • setException

      public WorkCalendar setException(long epochDay, int... startEndMinutes)
      Gives one date hours of its own, whatever the week says.
    • removeException

      public WorkCalendar removeException(long epochDay)
      Returns a date to the weekly pattern.
    • getWorkingHours

      public int[] getWorkingHours(long epochDay)
      The working hours of a date, as pairs of minutes since midnight. Empty for a day off. The array is the calendar's own: read it, do not change it.
    • isWorkingDay

      public boolean isWorkingDay(long epochDay)
    • isWorkingTime

      public boolean isWorkingTime(long millis)
      Whether millis is inside working hours.
    • nextWorkingTime

      public long nextWorkingTime(long millis)
      The first working instant at or after millis.
    • previousWorkingTime

      public long previousWorkingTime(long millis)
      The last instant at or before millis that work can end at: millis itself when it is inside working hours or closes them.
    • addWorkingTime

      public long addWorkingTime(long from, long duration)
      The instant duration milliseconds of working time after from. A duration that ends exactly as a working period closes ends there, not at the opening of the next one. A negative duration goes backwards.
    • subtractWorkingTime

      public long subtractWorkingTime(long from, long duration)
      The instant duration milliseconds of working time before from.
    • workingTimeBetween

      public long workingTimeBetween(long from, long to)
      The working time between two instants, negative when to is before from.
    • getMillisPerDay

      public long getMillisPerDay()
      The working time in a full day of the weekly pattern, which is what "a day" of duration means in this calendar.