Altova XMLSpy 2024 Enterprise Edition

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

 

Constructors

Name

Description

Duration()

Initializes a new instance of the Duration class to an empty value.

Duration(const DayTimeDuration& dt)

Initializes a new instance of the Duration class to a duration defined by the dt argument (see altova::DayTimeDuration ).

Duration(const YearMonthDuration& ym)

Initializes a new instance of the Duration class to the duration defined by the ym argument (see altova::YearMonthDuration ).

Duration(const YearMonthDuration& ym, const DayTimeDuration& dt)

Initializes a new instance of the Duration class to the duration defined by both the dt and the ym arguments (see altova::YearMonthDuration and altova::DayTimeDuration ).

 

Methods

Name

Description

int Days() const

Returns the number of days in the current Duration instance.

DayTimeDuration DayTime() const

Returns the day and time duration in the current Duration instance, expressed as a DayTimeDuration object (see altova::DayTimeDuration ).

int Hours() const

Returns the number of hours in the current Duration instance.

bool IsNegative() const

Returns Boolean true if the current Duration instance is negative.

bool IsPositive() const

Returns Boolean true if the current Duration instance is positive.

int Minutes() const

Returns the number of minutes in the current Duration instance.

int Months() const

Returns the number of months in the current Duration instance.

double Seconds() const

Returns the number of seconds in the current Duration instance.

YearMonthDuration YearMonth() const

Returns the year and month duration in the current Duration instance, expressed as a YearMonthDuration object (see altova::YearMonthDuration ).

int Years() const

Returns the number of years in the current Duration instance.

 

Example

The following code listing illustrates creating a new Duration object, as well as reading values from it.

 

void ExampleDuration()
{
  // Create an empty Duration object
  altova::Duration empty_duration = altova::Duration();
 
  // Create a Duration object using an existing duration value
  altova::Duration duration1 = altova::Duration(empty_duration);
 
  // Create a YearMonth duration of six years and five months
  altova::YearMonthDuration yrduration = altova::YearMonthDuration(6, 5);
 
  // Create a DayTime duration of four days, three hours, two minutes, and one second
  altova::DayTimeDuration dtduration = altova::DayTimeDuration(4, 3, 2, 1);
 
  // Create a Duration object by combining the two previously created durations
  altova::Duration duration = altova::Duration(yrduration, dtduration);
 
  // Get the number of years in this Duration instance
  cout << "Years:  " << duration.Years() << endl;
 
  // Get the number of months in this Duration instance
  cout << "Months: " << duration.Months() << endl;
 
  // Get the number of days in this Duration instance
  cout << "Days:   " << duration.Days() << endl;
 
  // Get the number of hours in this Duration instance
  cout << "Hours:  " << duration.Hours() << endl;
 
  // Get the number of hours in this Duration instance
  cout << "Minutes: " << duration.Minutes() << endl;
 
  // Get the number of seconds in this Duration instance
  cout << "Seconds: " << duration.Seconds() << endl;
}

© 2018-2024 Altova GmbH