Please enable JavaScript to view this site.

Altova XMLSpy 2020 Enterprise Edition

This class enables you to process XML attributes or elements of type xs:duration.

 

Constructors


Name

Description

ic_method

Duration(Duration obj)

Initializes a new instance of the Duration class to the Duration object supplied as argument.

ic_method

Duration(System.TimeSpan newvalue)

Initializes a new instance of the Duration class to the System.TimeSpan object supplied as argument.

ic_method

Duration(long ticks)

Initializes a new instance of the Duration class to the number of ticks supplied as argument.

ic_method

Duration(int newyears, int newmonths, int days, int hours, int minutes, int seconds, double partseconds, bool bnegative)

Initializes a new instance of the Duration class to a duration built from parts supplied as arguments.

 

Properties


Name

Description

ic_property

int Months

Gets or sets the number of months of the current instance of Duration.

ic_property

System.TimeSpan Value

Gets or sets the value (as System.TimeSpan) of the current instance of Duration.

ic_property

int Years

Gets or sets the number of years of the current instance of Duration.

 

Methods


Name

Description

ic_method

override bool Equals(object other)

Returns true if the specified object is equal to the current object; false otherwise.

ic_method

override int GetHashCode()

Returns the hash code of the current instance.

ic_method

bool IsNegative()

Returns true if the current instance of Duration represents a negative duration.

ic_method

static Duration Parse( string s, ParseType pt )

Returns an Altova.Types.Duration object parsed from the string supplied as argument, using the parse type supplied as argument. Valid parse type values:

DURATION

Parse duration assuming that year, month, day, as well as time duration parts exist.

YEARMONTH

Parse duration assuming that only year and month parts exist.

DAYTIME

Parse duration assuming that only the day and time parts exist.

 

Note that this method is static and can only be called on the class itself, not on an instance of the class.

ic_method

override string ToString()

Converts the current Duration instance to string. For example, a time span of 3 hours, 4 minutes, and 5 seconds would be converted to "PT3H4M5S".

ic_method

string ToYearMonthString()

Converts the current Duration instance to string, using the "Year and Month" parse type.

 

Operators

Name

Description

!=

Determines if Duration a is not equal to Duration b.

==

Determines if Duration a is equal to Duration b.

 

Examples

Before using the following code listings in your program, ensure the Altova types are imported:

 

using Altova.Types;

 

The following code listing illustrates various ways to create Duration objects:

 

protected static void DurationExample1()

{

 // Create a new time span of 3 hours, 4 minutes, and 5 seconds

 System.TimeSpan ts = new TimeSpan(3, 4, 5);

 // Create a Duration from the time span

 Duration dr = new Duration(ts);

 // The output is: PT3H4M5S

 Console.WriteLine("Duration created from TimeSpan: " + dr.ToString());

 

 // Create a negative Altova.Types.Duration from 6 years, 5 months, 4 days, 3 hours,

      // 2 minutes, 1 second, and .33 of a second

 Duration dr1 = new Duration(6, 5, 4, 3, 2, 1, .33, true);

 // The output is: -P6Y5M4DT3H2M1.33S

 Console.WriteLine("Duration created from parts: " + dr1.ToString());

 

 // Create a Duration from a string using the DAYTIME parse type

 Duration dr2 = Altova.Types.Duration.Parse("-P4DT3H2M1S", Duration.ParseType.DAYTIME);

 // The output is -P4DT3H2M1S

 Console.WriteLine("Duration created from string: " + dr2.ToString());

 

 // Create a duration from ticks                                

 Duration dr3 = new Duration(System.DateTime.UtcNow.Ticks);

 // Output the result

 Console.WriteLine("Duration created from ticks: " + dr3.ToString());

}

 

The following code listing illustrates getting values from Duration objects:

 

protected static void DurationExample2()

{

 // Create a negative Altova.Types.Duration from 6 years, 5 months, 4 days, 3 hours,

      // 2 minutes, 1 second, and .33 of a second

 Duration dr = new Duration(6, 5, 4, 3, 2, 1, .33, true);

 // The output is: -P6Y5M4DT3H2M1.33S

 Console.WriteLine("The complete duration is: " + dr.ToString());

 

 // Get only the year and month part as string

 string dr1 = dr.ToYearMonthString();

 Console.WriteLine("The YEARMONTH part is: " + dr1);

 

 // Get the number of years in duration

 Console.WriteLine("Years: " + dr.Years);

 

 // Get the number of months in duration

 Console.WriteLine("Months: " + dr.Months);

}

© 2019 Altova GmbH