Duration Structure

Represents duration in a project.

Namespace:  Aspose.Tasks
Assembly:  Aspose.Tasks (in Aspose.Tasks.dll) Version: 21.10
Syntax
public struct Duration : IEquatable<Duration>

The Duration type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleIsElapsed
Gets a value indicating whether time unit is elapsed.

Field Value

Type: 
The flag which determines whether this Duration instance is elapsed.
Public propertyCode exampleIsEstimated
Gets a value indicating whether time unit is estimated.

Field Value

Type: 
The flag which determines whether this Duration instance is estimated.
Public propertyCode exampleTimeSpan
Gets TimeSpan instance of this Duration object.

Field Value

Type: 
The TimeSpan instance of this Duration object.
Public propertyCode exampleTimeUnit
Gets time unit type for this object.

Field Value

Type: 
The time unit type of this Duration instance.
Methods
  NameDescription
Public methodCode exampleAdd(Double)
Adds specified double value to this duration.
Public methodCode exampleAdd(Duration)
Adds specified duration to this duration.
Public methodCode exampleConvert
Converts Duration object to another duration with specified time units.
Public methodCode exampleEquals(Object)
Returns a value indicating whether this instance is equal to a specified object.
(Overrides ValueTypeEquals(Object).)
Public methodCode exampleEquals(Duration)
Returns a value indicating whether this instance is equal to a specified object.
Public methodCode exampleGetHashCode
Returns a hash code value for this object.
(Overrides ValueTypeGetHashCode.)
Public methodGetType (Inherited from Object.)
Public methodStatic memberCode exampleParse
Converts the specified string to the instance of Duration struct.
Public methodStatic memberCode exampleParseTimeSpan
Parses duration string in format "PT--H--M--S--".
Public methodCode exampleSubtract(Double)
Subtracts specified double value from this duration instance.
Public methodCode exampleSubtract(Duration)
Subtracts specified duration from this duration instance.
Public methodCode exampleToDouble
Converts Duration object to Double value.
Public methodCode exampleToString
Returns a string representation of this instance.
(Overrides ValueTypeToString.)
Operators
  NameDescription
Public operatorStatic memberCode exampleEquality
Returns a value indicating whether this instance is equal to a specified object.
Public operatorStatic memberCode exampleInequality
Returns a value indicating whether this instance is not equal to a specified object.
Examples
Shows how to update a duration of tasks.
var project = new Project(DataDir + "TaskDurations.mpp");

// get a task
var task1 = project.RootTask.Children.GetById(1);

// update the task duration
var duration1 = task1.Get(Tsk.Duration);

// add one day to the task 1
duration1 = duration1.Add(project.GetDuration(1, TimeUnitType.Day));

// set a new duration to the task
task1.Set(Tsk.Duration, duration1);
Console.WriteLine("The duration of task 1: " + task1.Get(Tsk.Duration));

// get another task
var task2 = project.RootTask.Children.GetById(2);
var duration2 = task2.Get(Tsk.Duration);

// change the duration by using actual time unit type
Console.WriteLine("The time unit of duration: " + duration2.TimeUnit);
duration2 = duration2.Add(1d /* the time unit type of duration2 will be used */);

// set a new duration to the task
task2.Set(Tsk.Duration, duration2);
Console.WriteLine("The duration of task 2: " + task1.Get(Tsk.Duration));
See Also