작업 기간으로 작업합니다

작업에는 시간이 걸리고 지속 시간이 있습니다. 현실적인 작업 기간은 현실적인 프로젝트 종료 날짜를 제공하는 데 도움이됩니다. C ++ API 용 작업을 통해 개발자는 프로젝트에서 작업 시간을 설정할 수 있습니다.

지속 시간 작업

TSK 클래스에 의해 노출 된 지속 시간 및 지속성 특성은 작업 기간의 계획된 지속 시간과 형식을 결정하는 데 사용됩니다.

Microsoft 프로젝트의 기간

Microsoft Project에서 작업의 지속 시간을 보려면 더 많은보기를 선택한 다음 view 메뉴에서 작업 항목를 선택할 수 있습니다.

Aspose.Tasks 사용 작업 시간 설정

아래에 주어진 코드 예제는 작업 기간을 각각 1 주 반으로 늘리고 줄이는 방법을 보여줍니다.

 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.