Class Calendar
- java.lang.Object
-
- com.aspose.tasks.Calendar
-
- All Implemented Interfaces:
ICalendar
public class Calendar extends Object implements ICalendar
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Removes calendar from project.booleanequals(Object obj)Returns a value indicating whether this instance is equal to a specified object.CalendargetBaseCalendar()Gets the base calendar on which this calendar depends.CalendarExceptionCollectiongetExceptions()Gets CalendarExceptionCollection object.DategetFinishDateByStartAndWork(Date start, double work)Calculates the date when the specified amount of work time will pass according to the calendar.DategetFinishDateByStartAndWork(Date start, Duration work)Calculates the date when the specified amount of work time will pass according to the calendar.StringgetGuid()Gets calendar's Guid.static ICalendargetIntersectionCalendar(Calendar calendar1, Calendar calendar2)GetsICalendarinstance which can be used to perform calculations on the intersection of work schedules of 2 calendars.StringgetName()Gets the name of the calendar.DategetNextWorkingDayStart(Date date)Calculates next working day start for the specified date.DategetPreviousWorkingDayEnd(Date date)Calculates the end of the previous working date from the specified date.DategetStartDateFromFinishAndDuration(Date finish, double duration)Returns start date based on specified finish date and duration.DategetStartDateFromFinishAndDuration(Date finish, Duration duration)Returns start date based on the specified finish date and duration.DategetTaskFinishDateFromDuration(Task task, double duration)Calculates the task finish date and time from its start date, split parts and the work duration.intgetUid()Gets the unique identifier of the calendar.WeekDayCollectiongetWeekDays()Gets WeekDaysCollection for this calendar.doublegetWorkingHours(Date dt)Returns the amount of working hours at the specified date.WorkUnitgetWorkingHours(Date start, Date finish)Return WorkUnit - Start, Finish and Duration of working hours for the specified date time interval.doublegetWorkingHoursTimeSpan(Date start, Date finish)Returns amount of working hours between the specified dates.WorkingTimeCollectiongetWorkingTimes(Date dt)ReturnsWorkingTimeCollectionof working times for the specified date.DategetWorkStart(Date date)Calculates next working time start beginning from the specified date and time.WorkWeekCollectiongetWorkWeeks()Gets WorkWeekCollections object.inthashCode()Returns a hash code for the instance of the class.booleanisBaseCalendar()Gets a value indicating whether the calendar is a base calendar.booleanisBaselineCalendar()Gets a value indicating whether the calendar is a baseline calendar.booleanisDayWorking(Date dt)Determines whether the specified day is a working day according to the calendar.booleanisEmpty()Returns whether the calendar doesn't have working hours defined.static Calendarmake24HourCalendar(Calendar calendar)Makes a given Calendar to be a 24Hour Calendar.static CalendarmakeNightShiftCalendar(Calendar calendar)Makes a given Calendar as Night Shift Calendar.static CalendarmakeStandardCalendar(Calendar calendar)Creates default standard calendar.voidsetBaseCalendar(Calendar value)Sets the base calendar on which this calendar depends.voidsetBaselineCalendar(boolean value)Sets a value indicating whether the calendar is a baseline calendar.voidsetName(String value)Sets the name of the calendar.voidsetUid(int value)Sets the unique identifier of the calendar.
-
-
-
Method Detail
-
delete
public final void delete()
Removes calendar from project.
-
equals
public boolean equals(Object obj)
Returns a value indicating whether this instance is equal to a specified object.
-
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:
- the base calendar on which this calendar depends.
-
setBaseCalendar
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:
value- 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 object.
-
getFinishDateByStartAndWork
public final Date getFinishDateByStartAndWork(Date start, Duration work)
Calculates the date when the specified amount of work time will pass according to the calendar.
- Specified by:
getFinishDateByStartAndWorkin interfaceICalendar- Parameters:
start- Start date.work- Work duration.- Returns:
- Finish date.
-
getFinishDateByStartAndWork
public final Date getFinishDateByStartAndWork(Date start, double work)
Calculates the date when the specified amount of work time will pass according to the calendar.
- Specified by:
getFinishDateByStartAndWorkin interfaceICalendar- Parameters:
start- Start date.work- Work duration.- Returns:
- Finish date.
-
getGuid
public final String getGuid()
Gets calendar's Guid.
- Returns:
- calendar's Guid.
-
getIntersectionCalendar
public static ICalendar getIntersectionCalendar(Calendar calendar1, Calendar calendar2)
Gets
ICalendarinstance which can be used to perform calculations on the intersection of work schedules of 2 calendars.- Parameters:
calendar1- First calendar.calendar2- Second calendar.- Returns:
- Implementation of ICalendar interface.
- Throws:
com.aspose.ms.System.ArgumentNullException- When any of the arguments is null.
-
getName
public final String getName()
Gets the name of the calendar.
- Returns:
- the name of the calendar.
-
setName
public final void setName(String value)
Sets the name of the calendar.
- Parameters:
value- the name of the calendar.
-
getNextWorkingDayStart
public final Date getNextWorkingDayStart(Date date)
Calculates next working day start for the specified date.
- Specified by:
getNextWorkingDayStartin interfaceICalendar- Parameters:
date- The date to get next working day start for.- Returns:
- Next working day start
Date.
-
getPreviousWorkingDayEnd
public final Date getPreviousWorkingDayEnd(Date date)
Calculates the end of the previous working date from the specified date.
- Specified by:
getPreviousWorkingDayEndin interfaceICalendar- Parameters:
date- the specified instance ofDatestruct.- Returns:
- The end of the previous working day end
Date
-
getStartDateFromFinishAndDuration
public final Date getStartDateFromFinishAndDuration(Date finish, Duration duration)
Returns start date based on the specified finish date and duration.
- Specified by:
getStartDateFromFinishAndDurationin interfaceICalendar- Parameters:
finish- The specified finish date.duration- The specified duration.- Returns:
- Calculated start date.
-
getStartDateFromFinishAndDuration
public final Date getStartDateFromFinishAndDuration(Date finish, double duration)
Returns start date based on specified finish date and duration.
- Specified by:
getStartDateFromFinishAndDurationin interfaceICalendar- Parameters:
finish- The specified finish date.duration- The specified duration.- Returns:
- Calculated start date.
-
getTaskFinishDateFromDuration
public final Date getTaskFinishDateFromDuration(Task task, double duration)
Calculates the task finish date and time from its start date, split parts and the work duration.
- Specified by:
getTaskFinishDateFromDurationin interfaceICalendar- Parameters:
task- The task to calculate finish date for.duration- The duration to calculate.Returns DateTime.MinValue if task is summary, null or its start date is not set.
- Returns:
- Task's finish date for the given start date and duration.
-
getUid
public final int getUid()
Gets the unique identifier of the calendar.
- Returns:
- the unique identifier of the calendar.
-
setUid
public final void setUid(int value)
Sets the unique identifier of the calendar.
- Parameters:
value- 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:
- WeekDaysCollection for this calendar.
-
getWorkStart
public final Date getWorkStart(Date date)
Calculates next working time start beginning from the specified date and time.
- Specified by:
getWorkStartin interfaceICalendar- Parameters:
date- The date and time.- Returns:
- The nearest working time start.
-
getWorkWeeks
public final WorkWeekCollection getWorkWeeks()
Gets WorkWeekCollections object. The collection of work weeks that is associated with the calendar.
- Returns:
- WorkWeekCollections object.
-
getWorkingHours
public final WorkUnit getWorkingHours(Date start, Date finish)
Return WorkUnit - Start, Finish and Duration of working hours for the specified date time interval.
- Specified by:
getWorkingHoursin interfaceICalendar- Parameters:
start- Start date of the interval.finish- Finish date of the interval.- Returns:
- Instance of
WorkUnitclass containing Start, Finish and Duration of working hours.
-
getWorkingHours
public final double getWorkingHours(Date dt)
Returns the amount of working hours at the specified date.
- Specified by:
getWorkingHoursin interfaceICalendar- Parameters:
dt- The date to get working hours for.- Returns:
- Working hours at the specified date.
-
getWorkingHoursTimeSpan
public final double getWorkingHoursTimeSpan(Date start, Date finish)
Returns amount of working hours between the specified dates.
- Specified by:
getWorkingHoursTimeSpanin interfaceICalendar- Parameters:
start- Start date of the interval.finish- Finish date of the interval.- Returns:
- Amount of working hours according to the calendar instance.
-
getWorkingTimes
public final WorkingTimeCollection getWorkingTimes(Date dt)
Returns
WorkingTimeCollectionof working times for the specified date.- Specified by:
getWorkingTimesin interfaceICalendar- Parameters:
dt- The date to get working times for.- Returns:
- Collection of
WorkingTimeinstances.
-
hashCode
public int hashCode()
Returns a hash code for the instance of the class.
-
isBaseCalendar
public final boolean isBaseCalendar()
Gets a value indicating whether the calendar is a base calendar.
- Returns:
- 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:
- a value indicating whether the calendar is a baseline calendar.
-
setBaselineCalendar
public final void setBaselineCalendar(boolean value)
Sets a value indicating whether the calendar is a baseline calendar.
- Parameters:
value- a value indicating whether the calendar is a baseline calendar.
-
isDayWorking
public final boolean isDayWorking(Date dt)
Determines whether the specified day is a working day according to the calendar.
- Specified by:
isDayWorkingin interfaceICalendar- Parameters:
dt- The date to check whether the day is working.- Returns:
- True if the day is a working day.
-
isEmpty
public boolean isEmpty()
Returns whether the calendar doesn't have working hours defined.
-
make24HourCalendar
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:
calendar- Calendar to make 24 Hours Calendar from.- Returns:
- 24Hour Calendar.
-
makeNightShiftCalendar
public static Calendar makeNightShiftCalendar(Calendar calendar)
Makes a given Calendar as Night Shift Calendar.
- Parameters:
calendar- Calendar to make Night Shift Calendar.- Returns:
- Night Shift Calendar.
-
-