Add Calendar Exception Introduction
This example allows you to add a new calendar exception to a calendar, using Aspose.Tasks Cloud. Aspose.Tasks Cloud is a REST API which can be used with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
API
Type
Description
Resource Link
/tasks/{name}/calendars/{calendarUid}/calendarExceptions
POST
Add a Calendar Exception
PostCalendarException
cUL Example
Request
Copy
curl - X POST "https://api.aspose.cloud/v3.0/tasks/Home%20move%20plan.mpp/calendars/1/calendarExceptions" - H "accept: application/json" - H "Content-Type: application/json" - d "{ \"Index\": 0, \"EnteredByOccurrences\": true, \"FromDate\": \"2019-08-13T23:16:59.908Z\", \"ToDate\": \"2019-08-13T23:16:59.908Z\", \"Occurrences\": 0, \"Name\": \"New Test\", \"Period\": 0, \"DaysOfWeek\": [ 0 ], \"MonthDay\": 0, \"DayWorking\": true, \"WorkingTimes\": [ { \"FromTime\": \"2019-08-13T23:16:59.909Z\", \"ToTime\": \"2019-08-13T23:16:59.909Z\" } ]}"
Response
Copy
{
"Code" : "200" ,
"Status" : "OK"
}
SDKs
The Aspose.Tasks Cloud SDKs can be downloaded from the following page: Available SDKs
SDK Examples
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-dotnet/
var remoteName = await UploadFileToStorageAsync("New project 2013.mpp");
var calendarException = new CalendarException
{
Name = "Non-working day exception",
DayWorking = false,
FromDate = new DateTime(2014, 10, 28),
ToDate = new DateTime(2015, 08, 5),
Occurrences = 10,
Type = CalendarExceptionType.MonthlyByDay,
EnteredByOccurrences = true,
MonthDay = 5,
Period = 1
};
var response = await TasksApi.PostCalendarExceptionAsync(new PostCalendarExceptionRequest
{
CalendarUid = 1,
CalendarException = calendarException,
Name = remoteName,
Folder = this.DataFolder
});
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-php/
$remoteName = "AddCalendarException.mpp";
$folder = $this->uploadFile("New project 2013.mpp", $remoteName, '');
$calendarException = new CalendarException();
$calendarException->setName("Non-working day exception");
$calendarException->setDayWorking(false);
$calendarException->setFromDate(new DateTime("2014-10-28"));
$calendarException->setToDate(new DateTime("2015-08-05"));
$calendarException->setOccurrences(10);
$calendarException->setType(CalendarExceptionType::MONTHLY_BY_DAY);
$calendarException->setEnteredByOccurrences(true);
$calendarException->setMonthDay(5);
$calendarException->setPeriod(1);
$response = $this->tasks->postCalendarException(
new Requests\PostCalendarExceptionRequest($remoteName, 1, $calendarException, null, self::$storageName, $folder));
Assert::assertEquals(201, $response->getCode());
$response = $this->tasks->getCalendarExceptions(new Requests\GetCalendarExceptionsRequest($remoteName, 1, self::$storageName, $folder));
Assert::assertEquals(200, $response->getCode());
Assert::assertNotNull($response->getCalendarExceptions());
Assert::assertEquals(1, count($response->getCalendarExceptions()));
$this->assertCalendarExceptionsAreEqual($calendarException, $response->getCalendarExceptions()[0]);
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-python
filename = 'New_project_2013.mpp'
self.upload_file(filename)
exception = CalendarException()
exception.working_times = []
exception.days_of_week = []
exception.name = "Non-working day exception"
exception.day_working = False
exception.from_date = datetime(2014, 9, 27, 8)
exception.to_date = datetime(2015, 7, 5, 8)
exception.occurrences = 10
exception.type = CalendarExceptionType.MONTHLYBYDAY
exception.entered_by_occurrences = True
exception.month_day = 5
exception.period = 1
post_request = PostCalendarExceptionRequest(filename, 1, exception)
post_result = self.tasks_api.post_calendar_exception(post_request)
self.assertIsNotNone(post_result)
self.assertIsInstance(post_result, AsposeResponse)
get_request = GetCalendarExceptionsRequest(filename, 1)
get_result = self.tasks_api.get_calendar_exceptions(get_request)
self.assertIsNotNone(get_result)
self.assertIsInstance(get_result, CalendarExceptionsResponse)
self.assertEqual(1, len(get_result.calendar_exceptions))
self.__assert_calendar_exceptions_are_equal(exception, get_result.calendar_exceptions[0])
Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-node
const fileName = "New_project_2013.mpp";
const localPath = "./Data/" + fileName;
const remotePath = "Temp/Data";
const remoteFullPath = remotePath + "/" + fileName;
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
const exception = new CalendarException();
exception.workingTimes = [];
exception.daysOfWeek = [];
exception.name = "Non-working day exception";
exception.dayWorking = false;
exception.fromDate = new Date(Date.UTC(2014, 9, 27, 8));
exception.toDate = new Date(Date.UTC(2015, 7, 5, 8));
exception.occurrences = 10;
exception.type = CalendarExceptionType.MonthlyByDay;
exception.enteredByOccurrences = true;
exception.monthDay = 5;
exception.period = 1;
const request = new PostCalendarExceptionRequest();
request.name = fileName;
request.folder = remotePath;
request.calendarUid = 1;
request.calendarException = exception;
const result = await tasksApi.postCalendarException(request);
expect(result.body.code).to.equal(201);
Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/
client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName)
newExceptionType := models.MONTHLY_BY_DAY_CalendarExceptionType
newMonthItemType := models.UNDEFINED_MonthItemType
newMonthPosition := models.UNDEFINED_MonthPosition
newMonth := models.UNDEFINED_Month
newException := models.CalendarException{
Name: "Non-working day exception",
DayWorking: false,
FromDate: CreateTime(2014, 10, 27, 0, 0, 0),
ToDate: CreateTime(2015, 8, 5, 23, 59, 0),
Occurrences: 10,
Type_: &newExceptionType,
MonthItem: &newMonthItemType,
MonthPosition: &newMonthPosition,
Month: &newMonth,
EnteredByOccurrences: true,
MonthDay: 5,
Period: 1,
}
postResult, _, err := client.TasksApi.PostCalendarException(ctx, &requests.PostCalendarExceptionOpts{
CalendarUid: 1,
CalendarException: newException,
Name: remoteFileName,
Folder: optional.NewString(remoteBaseTestDataFolder),
})
if err != nil {
t.Error(err)
}
assert.Equal(t, int32(201), postResult.Code)
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-tasks-cloud/aspose-tasks-cloud-java/
String localFileName = "New_project_2013.mpp";
String remoteFileName = TestInitializer.UploadFile(localFileName);
CalendarException exception = new CalendarException();
exception.setName("Non-working day exception");
exception.setDayWorking(false);
exception.setFromDate(OffsetDateTime.of(2014, 10, 27, 0, 0, 0, 0, ZoneOffset.UTC));
exception.setToDate(OffsetDateTime.of(2015, 8, 5, 23, 59, 0, 0, ZoneOffset.UTC));
exception.setOccurrences(10);
exception.setType(CalendarExceptionType.MONTHLYBYDAY);
exception.setEnteredByOccurrences(true);
exception.setMonthDay(5);
exception.setPeriod(1);
exception.setWorkingTimes(Collections.emptyList());
exception.setDaysOfWeek(Collections.emptyList());
PostCalendarExceptionRequest request1 = new PostCalendarExceptionRequest(remoteFileName, 1, exception, null, null, null);
AsposeResponse result1 = TestInitializer.tasksApi.postCalendarException(request1);
assertNotNull(result1);
assertEquals(201, (int) result1.getCode());
GetCalendarExceptionsRequest request2 = new GetCalendarExceptionsRequest(remoteFileName, 1, null, null);
CalendarExceptionsResponse result2 = TestInitializer.tasksApi.getCalendarExceptions(request2);
assertNotNull(result2.getCalendarExceptions());
assertEquals(1, result2.getCalendarExceptions().size());