Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class WorkCalendar

  1. Object
  2. WorkCalendar

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.

Constructors

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

Methods

public static WorkCalendar continuous(ZoneId zone)A calendar in which every minute of every day is working time, for durations that are elapsed time.
public ZoneId getZone()
public WorkCalendar setWorkingDay(int isoDay, boolean working)Whether a day of the week is worked.
public boolean isWorkingWeekday(int isoDay)
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.
public WorkCalendar setWorkingHours(int isoDay, int[] startEndMinutes)The hours of one day of the week, which also makes it a working day.
public WorkCalendar addHoliday(long epochDay)Makes one date a day off, whatever the week says.
public WorkCalendar setException(long epochDay, int... startEndMinutes)Gives one date hours of its own, whatever the week says.
public WorkCalendar removeException(long epochDay)Returns a date to the weekly pattern.
public int[] getWorkingHours(long epochDay)The working hours of a date, as pairs of minutes since midnight.
public boolean isWorkingDay(long epochDay)
public boolean isWorkingTime(long millis)Whether millis is inside working hours.
public long nextWorkingTime(long millis)The first working instant at or after millis.
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.
public long addWorkingTime(long from, long duration)The instant duration milliseconds of working time after from.
public long subtractWorkingTime(long from, long duration)The instant duration milliseconds of working time before from.
public long workingTimeBetween(long from, long to)The working time between two instants, negative when to is before from.
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.

Inherited methods

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.