Arbeiten mit Aufgabendauer

Aufgaben brauchen Zeit, sie haben eine Dauer. Realistische Aufgabendauer tragen dazu bei, ein realistisches Projekt Enddatum zu verleihen. Mit ASSOSH.

Mit Dauern arbeiten

Die Dauer- und DurationFormat -Eigenschaften, die von der TSK -Klasse ausgesetzt sind, werden verwendet, um die geplante Dauer und das Format der Dauer einer Aufgabe zu bestimmen:

Dauer im Microsoft -Projekt

Um die Dauer einer Aufgabe in Microsoft Project zu sehen, kann man Weitere Ansichten und dann Taskeintrag Aus dem Menü View auswählen.

Aufgabendauer mit Aspose.Tasks

Das nachstehend angegebene Codebeispiel zeigt, wie die Aufgabendauer auf 1 und halbe Woche erhöht und verringert werden kann.

 1// Create a new project and add a new task
 2System::SharedPtr<Project> project = System::MakeObject<Project>();
 3System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task");
 4    
 5// Task duration in days (default time unit)
 6Duration duration = task->Get<Duration>(Tsk::Duration());
 7System::Console::WriteLine(u"Duration equals 1 day: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(duration), u"1 day")));
 8    
 9// Convert to hours time unit
10duration = duration.Convert(Aspose::Tasks::TimeUnitType::Hour);
11System::Console::WriteLine(u"Duration equals 8 hrs: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(duration), u"8 hrs")));
12    
13// Get wrapped TimeSpan instance
14System::Console::WriteLine(u"Duration TimeSpan equals to TimeSpan of 8 hrs: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(duration.get_TimeSpan(), System::TimeSpan::FromHours(8))));
15    
16// Increase task duration to 1 week and display if duration is updated successfully
17task->Set<Duration>(Tsk::Duration(), project->GetDuration(1, Aspose::Tasks::TimeUnitType::Week));
18System::Console::WriteLine(u"Duration equals 1 wk: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(task->Get<Duration>(Tsk::Duration())), u"1 wk")));
19    
20// Decrease task duration and display if duration is updated successfully
21task->Set<Duration>(Tsk::Duration(), task->Get<Duration>(Tsk::Duration()).Subtract(0.5));
22System::Console::WriteLine(u"Duration equals 0.5 wks: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(System::ObjectExt::ToString(task->Get<Duration>(Tsk::Duration())), u"0.5 wks")));

Calculating Durations

It can be useful to calculate the duration of a task in different units such as minutes, hours, etc.

The Tsk class provides the Duration property for accessing task duration, which returns the Duration class object. The Convert method exposed as part of Duration class can then be used to calculate task durations in different units. This method takes TimeUnitType as the input argument and returns the duration as a double value.

The following code example demonstrates how to use this method to retrieve a task’s duration in different units: minute, day, hour, week and month.

 1// Create project instance
 2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
 3System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"TaskDurations.mpp");
 4    
 5// Get a task to calculate its duration in different formats
 6System::SharedPtr<Task> task = project1->get_RootTask()->get_Children()->GetById(1);
 7    
 8// Get the duration in Minutes, Days, Hours, Weeks and Months
 9double mins = task->Get<Duration>(Tsk::Duration()).Convert(Aspose::Tasks::TimeUnitType::Minute).ToDouble();
10System::Console::WriteLine(u"Duration in Mins: {0}", System::ObjectExt::Box<double>(mins));
11double days = task->Get<Duration>(Tsk::Duration()).Convert(Aspose::Tasks::TimeUnitType::Day).ToDouble();
12System::Console::WriteLine(u"Duration in Days: {0}", System::ObjectExt::Box<double>(days));
13double hours = task->Get<Duration>(Tsk::Duration()).Convert(Aspose::Tasks::TimeUnitType::Hour).ToDouble();
14System::Console::WriteLine(u"Duration in Hours: {0}", System::ObjectExt::Box<double>(hours));
15double weeks = task->Get<Duration>(Tsk::Duration()).Convert(Aspose::Tasks::TimeUnitType::Week).ToDouble();
16System::Console::WriteLine(u"Duration in Weeks: {0}", System::ObjectExt::Box<double>(weeks));
17double months = task->Get<Duration>(Tsk::Duration()).Convert(Aspose::Tasks::TimeUnitType::Month).ToDouble();
18System::Console::WriteLine(u"Duration in Months: {0}", System::ObjectExt::Box<double>(months));
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.