Free Support Forum - aspose.com

"Stuck" while setting duration for a task

Hi, I'm trying to create an project with a 24hour Calendar. But I have a problem that the program gets stuck in the setter for task1.Set(Tsk.Duration, ....). However, this do not happen when no startdate and FinishDate for the project is set.

What I want to achieve is a calendar where the worktime is from 00:00 -> 00:00 and saturday and sunday is "nonworking" days. However, I also want to be able to have the project to start at a certain date, and not at the date of creation.

I have used Apose.Task version 8.3 and 8.5. Same problem.

Code:

DateTime startTime = new DateTime(2015,7,27,0,0,0);
double duration = 8;
DateTime finishTime = startTime.AddDays(duration);

var asposeProject = new Project();
asposeProject.Set(Prj.Name, "Project1");
asposeProject.Set(Prj.StartDate, startTime);
asposeProject.Set(Prj.FinishDate, finishTime);
asposeProject.Set(Prj.WeekStartDay, DayType.Monday);

var asposeCalendar = Calendar.Make24HourCalendar();
foreach (var weekDay in asposeCalendar.WeekDays)
{
if (weekDay.DayType.Equals(DayType.Saturday) || weekDay.DayType.Equals(DayType.Sunday))
{
weekDay.DayWorking = false;
}
else
{
weekDay.DayWorking = true;
}
}

asposeProject.Set(Prj.Calendar, asposeCalendar);

var task1 = asposeProject.RootTask.Children.Add("Task1");
task1.Set(Tsk.Calendar, asposeCalendar);
task1.Set(Tsk.ManualStart, startTime);
task1.Set(Tsk.ManualFinish, finishTime);
task1.Set(Tsk.Duration, Duration.Parse(asposeProject, duration + ""));

asposeProject.Save("C:\\path....\\Project1.xml", SaveFileFormat.XML);

Hi Lars,

Thank you for writing to Aspose Support team.

Since you are setting the manual parameters of task such as ManualStart, ManualFinish, etc., you need to set the ManualDuration instead of Duration. Please replace the following line of your code:

task1.Set(Tsk.Duration, Duration.Parse(asposeProject, duration + “”));

with this one:

task1.Set(Tsk.ManualDuration, Duration.Parse(asposeProject, duration + “”));

This will solve your issue. Please let us know if we can be of any additional help to you in this regard.

Hi,


It solved the first problem, but it still doesn’t seem to set the correct duration. And it is also changing the start and finish datetime.

How should I use the settings to be able to create a 24hour calendar where I can set the starttime, duration and finishtime without it being changed in the generated xml?

Here is the xml generated for the task:
(The whole xml file is added as an attachment)
1
1
Task1
0
0
2015-07-22T08:45:30
1
1
1
500
2015-07-27T08:00:00
2015-07-27T16:00:00
PT8H0M0S
2015-07-27T08:00:00
2015-07-27T16:00:00
PT8H0M0S
7
PT0H0M0S
0
0
0
0
0
0
0
1
0
0
0
2015-07-27T08:00:00
2015-07-27T16:00:00
2015-07-27T08:00:00
2015-07-27T16:00:00
0
0
0
0
0
0
0
0
3
0
0
0
0
PT0H0M0S
PT0H0M0S
0
0
PT0H0M0S
PT0H0M0S
PT0H0M0S
PT8H0M0S
0
PT0H0M0S
0
PT0H0M0S
0
0
0
0
1
1
0
8
0
0
0
0
0
0
0
1
0

Hi Lars,


Thank you for providing the sample XML file. I have observed the hanging while setting task duration and have logged it in our bug reporting system under id:TASKS-34103 for further investigation by the product team. I shall write back here as soon as some feedback is received in this regard.

Regarding the wrong calculation of duration and changing of start/finish date, we are further investigation this issue and will write back here soon to share our findings.


Hi Lars,


We have further discussed the issue of wrong start/finish dates calculation for a task. This issue is logged as TASKS-34104 in our bug reporting system for further analysis by the product team. I shall write here as soon as some feedback is received in this regard.

Hi, I tried some other settings and ran into another problem.


I manually created a 24hour (worktime each day) calendar and compared that with using a 23 hour and 59 minutes calendar. For the 23 hour (59 minutes) Calendar it worked fine, but for the 24 hour calendar the startdates and duration became incorrect.

I don’t know if this is caused by the same error as discovered earlier, or if it is another one (Or if I’m doing something wrong). Nevertheless, I wanted to check with you guys.

I attached both the generated xml files for the two cases.

Here is the code:

double task1Duration = 5; //Monday to friday
double weekend = 2; // saturday and sunday
double task2Duration = 3; //Monday to wednesday

DateTime projectStartDateTime = new DateTime(2015, 7, 27, 0, 0, 0);
DateTime projectFinishDateTime = projectStartDateTime.AddDays(task1Duration + weekend + task2Duration);

DateTime task1StarDateTime = projectStartDateTime; //Monday
DateTime task2StarDateTime = new DateTime(2015, 8, 3, 0, 0, 0); //Next Monday

var asposeProject = new Project();
asposeProject.Set(Prj.Name, “Project1”);
asposeProject.Set(Prj.StartDate, projectStartDateTime);
asposeProject.Set(Prj.FinishDate, projectFinishDateTime);
asposeProject.Set(Prj.WeekStartDay, DayType.Monday);
asposeProject.Set(Prj.DurationFormat, TimeUnitType.Day);

var startTimeMorning = new DateTime(2015, 1, 14, 0, 0, 0);

//var finishTimeEvening = new DateTime(2015, 1, 14, 23, 59, 0); //23 hour 59 minutes
var finishTimeEvening = new DateTime(2015, 1, 15, 0, 0, 0); //24 hour calendar

var minutesPerDay = (int)finishTimeEvening.Subtract(startTimeMorning).TotalMinutes;
asposeProject.Set(Prj.MinutesPerDay, minutesPerDay);
asposeProject.Set(Prj.DefaultStartTime, startTimeMorning);
asposeProject.Set(Prj.DefaultFinishTime, finishTimeEvening);

var asposeCalendar = asposeProject.Calendars.Add(“24hourCal”);

foreach (var weekDay in asposeCalendar.WeekDays)
{
//Remove default
List asposeWorkingTimesRemove = weekDay.WorkingTimes.ToList();
foreach (var workingTime in asposeWorkingTimesRemove)
{
weekDay.WorkingTimes.Remove(workingTime);
}
//Add worktimes
weekDay.WorkingTimes.Add(new WorkingTime() { FromTime = startTimeMorning, ToTime = finishTimeEvening });

if (weekDay.DayType.Equals(DayType.Saturday) || weekDay.DayType.Equals(DayType.Sunday))
{
weekDay.DayWorking = false;
}
else
{
weekDay.DayWorking = true;
}
}

var task1 = asposeProject.RootTask.Children.Add(“Task1”);
task1.Set(Tsk.Calendar, asposeCalendar);
task1.Set(Tsk.IsManual, true);
task1.Set(Tsk.DurationFormat, TimeUnitType.Day);
task1.Set(Tsk.Duration, asposeProject.GetDuration(task1Duration));
task1.Set(Tsk.Start, task1StarDateTime); //Monday


var task2 = asposeProject.RootTask.Children.Add(“Task2”);
task2.Set(Tsk.Calendar, asposeCalendar);
task2.Set(Tsk.IsManual, true);
task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
task2.Set(Tsk.Duration, asposeProject.GetDuration(task2Duration));
task2.Set(Tsk.Start, task2StarDateTime); //Monday

asposeProject.Save(“C:\…\Project1.xml”, SaveFileFormat.XML);

Hi Lars,


Thank you for providing the additional information. I have attached this information to ticket id: TASKS-34104 for product team consideration. I shall write here in case of any update in this regard.


The issues you have found earlier (filed as TASKS-34103) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.