Calendar

Inheritance: java.lang.Object

public class Calendar

Represents a calendar used in a project.


> > How to create simple calendar from scratch. > > > // create empty calendar > Calendar calendar = new Calendar(); > // adds default working days (8 working hours from 9:00 to 17:00) > calendar.getDays().add(WeekDay.createDefaultWorkingDay(DayType.Monday)); > calendar.getDays().add(WeekDay.createDefaultWorkingDay(DayType.Tuesday)); > calendar.getDays().add(WeekDay.createDefaultWorkingDay(DayType.Wednesday)); > // create new new working day > WeekDay myWeekDay = new WeekDay(DayType.Thursday); > // Sets working time. Only time part of DateTime is important > WorkingTime wt1 = new WorkingTime(); > wt1.setFromTime(new Date(1, 1, 1, 6, 0, 0)); > wt1.setToTime(new Date(1, 1, 1, 12, 0, 0)); > WorkingTime wt2 = new WorkingTime(); > wt2.setFromTime(new Date(1, 1, 1, 14, 0, 0)); > wt2.setToTime(new Date(1, 1, 1, 18, 0, 0)); > myWeekDay.getWorkingTimes().add(wt1); > myWeekDay.getWorkingTimes().add(wt2); > myWeekDay.setDayWorking(true); > calendar.getDays().add(myWeekDay); > calendar.getDays().add(WeekDay.createDefaultWorkingDay(DayType.Friday)); > // adds weekend > calendar.getDays().add(new WeekDay(DayType.Saturday)); > calendar.getDays().add(new WeekDay(DayType.Sunday)); >
> >


Calendars are used to define standard working and non-working times. Projects must have one base calendar. Tasks and resources can have their own non-base calendars that are based on a base calendar.

Methods

MethodDescription
delete()Removes calendar from project.
equals(Object obj)Returns a value indicating whether this instance is equal to a specified object.
getBaseCalendar()Gets the base calendar on which this calendar depends.
getExceptions()Gets CalendarExceptionCollection object.
getFinishDateByStartAndWork(Date start, Duration work)Calculates the date when the specified amount of work time will pass according to the calendar.
getFinishDateByStartAndWork(Date start, double work)Calculates the date when the specified amount of work time will pass according to the calendar.
getName()Gets the name of the calendar.
getNextWorkingDayStart(Date date)Calculates next working day start from the date.
getPreviousWorkingDayEnd(Date date)Calculates previous working date end from the specified date.
getStartDateFromFinishAndDuration(Date finish, Duration duration)Returns StartDate based on specified FinishDate and Duration.
getStartDateFromFinishAndDuration(Date finish, double duration)Returns StartDate based on specified FinishDate and Duration.
getTaskFinishDateFromDuration(Task task, double duration)Calculates the task finish date and time from its start date, split parts and the duration.
getUid()Gets the unique identifier of the calendar.
getWeekDays()Gets WeekDaysCollection for this calendar.
getWorkWeeks()Gets WorkWeekCollections object.
getWorkingHours(Date dt)Returns amount of working hours at the date.
getWorkingHours(Date start, Date finish)Return working hours for the specified dates.
getWorkingTimes(Date dt)Returns WorkingTimeCollection of working times for the specified date.
hashCode()Returns a hash code for the instance of the class.
isBaseCalendar()Gets a value indicating whether the calendar is a base calendar.
isBaselineCalendar()Gets a value indicating whether the calendar is a baseline calendar.
isDayWorking(Date dt)Determines whether the day is working day.
make24HourCalendar(Calendar calendar)Makes a given Calendar to be a 24Hour Calendar.
makeNightShiftCalendar(Calendar calendar)Makes a given Calendar as Night Shift Calendar.
makeStandardCalendar(Calendar calendar)Creates default standard calendar.
setBaseCalendar(Calendar value)Sets the base calendar on which this calendar depends.
setBaselineCalendar(boolean value)Sets a value indicating whether the calendar is a baseline calendar.
setName(String value)Sets the name of the calendar.
setUid(int value)Sets the unique identifier of the calendar.

delete()

public final void delete()

Removes calendar from project.

equals(Object obj)

public boolean equals(Object obj)

Returns a value indicating whether this instance is equal to a specified object.

Parameters:

ParameterTypeDescription
objjava.lang.ObjectThe object to compare with this instance.

Returns: boolean - True if o is a Calendar that has the same Uid value as this instance; otherwise, false.

getBaseCalendar()

public final Calendar getBaseCalendar()

Gets the base calendar on which this calendar depends. Only applicable if the calendar is not a base calendar.

Returns: Calendar - the base calendar on which this calendar depends.

getExceptions()

public final CalendarExceptionCollection getExceptions()

Gets CalendarExceptionCollection object. The collection of exceptions that is associated with the calendar.

Returns: CalendarExceptionCollection - CalendarExceptionCollection object.

getFinishDateByStartAndWork(Date start, Duration work)

public final Date getFinishDateByStartAndWork(Date start, Duration work)

Calculates the date when the specified amount of work time will pass according to the calendar.

Parameters:

ParameterTypeDescription
startjava.util.DateStart date.
workDurationWork duration.

Returns: java.util.Date - Finish date.

getFinishDateByStartAndWork(Date start, double work)

public final Date getFinishDateByStartAndWork(Date start, double work)

Calculates the date when the specified amount of work time will pass according to the calendar.

Parameters:

ParameterTypeDescription
startjava.util.DateStart date.
workdoubleWork duration.

Returns: java.util.Date - Finish date.

getName()

public final String getName()

Gets the name of the calendar.

Returns: java.lang.String - the name of the calendar.

getNextWorkingDayStart(Date date)

public final Date getNextWorkingDayStart(Date date)

Calculates next working day start from the date.

Parameters:

ParameterTypeDescription
datejava.util.DateThe date to get next working day start for.

Returns: java.util.Date - Next working day start java.util.Date.

getPreviousWorkingDayEnd(Date date)

public final Date getPreviousWorkingDayEnd(Date date)

Calculates previous working date end from the specified date.

Parameters:

ParameterTypeDescription
datejava.util.Datethe specified instance of java.util.Date struct.

Returns: java.util.Date - Previous working day start java.util.Date

getStartDateFromFinishAndDuration(Date finish, Duration duration)

public final Date getStartDateFromFinishAndDuration(Date finish, Duration duration)

Returns StartDate based on specified FinishDate and Duration.

Parameters:

ParameterTypeDescription
finishjava.util.DateThe specified finish date.
durationDurationThe specified work duration.

Returns: java.util.Date - Calculated StartDate.

getStartDateFromFinishAndDuration(Date finish, double duration)

public final Date getStartDateFromFinishAndDuration(Date finish, double duration)

Returns StartDate based on specified FinishDate and Duration.

Parameters:

ParameterTypeDescription
finishjava.util.DateThe specified finish date.
durationdoubleThe specified work duration.

Returns: java.util.Date - Calculated StartDate.

getTaskFinishDateFromDuration(Task task, double duration)

public final Date getTaskFinishDateFromDuration(Task task, double duration)

Calculates the task finish date and time from its start date, split parts and the duration.

Parameters:

ParameterTypeDescription
taskTaskThe task to get finish date for.
durationdoubleThe task duration to split on.

Returns DateTime.MinValue if task is summary, null or its start date is not set. |

Returns: java.util.Date - Task’s finish date.

getUid()

public final int getUid()

Gets the unique identifier of the calendar.

Returns: int - the unique identifier of the calendar.

getWeekDays()

public final WeekDayCollection getWeekDays()

Gets WeekDaysCollection for this calendar. The collection of weekdays that defines the calendar.

Returns: WeekDayCollection - WeekDaysCollection for this calendar.

getWorkWeeks()

public final WorkWeekCollection getWorkWeeks()

Gets WorkWeekCollections object. The collection of work weeks that is associated with the calendar.

Returns: WorkWeekCollection - WorkWeekCollections object.

getWorkingHours(Date dt)

public final double getWorkingHours(Date dt)

Returns amount of working hours at the date.

Parameters:

ParameterTypeDescription
dtjava.util.DateThe date to get working hours for.

Returns: double - Working hours.

getWorkingHours(Date start, Date finish)

public final WorkUnit getWorkingHours(Date start, Date finish)

Return working hours for the specified dates.

Parameters:

ParameterTypeDescription
startjava.util.DateStart date.
finishjava.util.DateFinish date.

Returns: WorkUnit - Working hours.

getWorkingTimes(Date dt)

public final WorkingTimeCollection getWorkingTimes(Date dt)

Returns WorkingTimeCollection of working times for the specified date.

Parameters:

ParameterTypeDescription
dtjava.util.DateThe date to get working times for.

Returns: WorkingTimeCollection - List of WorkingTime.

hashCode()

public int hashCode()

Returns a hash code for the instance of the class.

Returns: int - a hash code for this object.

isBaseCalendar()

public final boolean isBaseCalendar()

Gets a value indicating whether the calendar is a base calendar.

Returns: boolean - a value indicating whether the calendar is a base calendar.

isBaselineCalendar()

public final boolean isBaselineCalendar()

Gets a value indicating whether the calendar is a baseline calendar.

Returns: boolean - a value indicating whether the calendar is a baseline calendar.

isDayWorking(Date dt)

public final boolean isDayWorking(Date dt)

Determines whether the day is working day.

Parameters:

ParameterTypeDescription
dtjava.util.DateThe date to check day is working for.

Returns: boolean - True if the day is working day.

make24HourCalendar(Calendar calendar)

public static Calendar make24HourCalendar(Calendar calendar)

Makes a given Calendar to be a 24Hour Calendar. 24Hours Calendar is a Calendar in which every day of week is working with Round-the-clock working hours.

Parameters:

ParameterTypeDescription
calendarCalendarCalendar to make 24 Hours Calendar from.

Returns: Calendar - 24Hour Calendar.

makeNightShiftCalendar(Calendar calendar)

public static Calendar makeNightShiftCalendar(Calendar calendar)

Makes a given Calendar as Night Shift Calendar.

Parameters:

ParameterTypeDescription
calendarCalendarCalendar to make Night Shift Calendar.

Returns: Calendar - Night Shift Calendar.

makeStandardCalendar(Calendar calendar)

public static Calendar makeStandardCalendar(Calendar calendar)

Creates default standard calendar.

Parameters:

ParameterTypeDescription
calendarCalendarCalendar to make standard calendar from.

Returns: Calendar - Calendar with 5 working days (Monday-Friday) with working times 8-12 and 13-17.

setBaseCalendar(Calendar value)

public final void setBaseCalendar(Calendar value)

Sets the base calendar on which this calendar depends. Only applicable if the calendar is not a base calendar.

Parameters:

ParameterTypeDescription
valueCalendarthe base calendar on which this calendar depends.

setBaselineCalendar(boolean value)

public final void setBaselineCalendar(boolean value)

Sets a value indicating whether the calendar is a baseline calendar.

Parameters:

ParameterTypeDescription
valuebooleana value indicating whether the calendar is a baseline calendar.

setName(String value)

public final void setName(String value)

Sets the name of the calendar.

Parameters:

ParameterTypeDescription
valuejava.lang.Stringthe name of the calendar.

setUid(int value)

public final void setUid(int value)

Sets the unique identifier of the calendar.

Parameters:

ParameterTypeDescription
valueintthe unique identifier of the calendar.