Table of Contents

Struct XapiDuration

Namespace
Xapi
Assembly
Xapi.Core.dll

An ISO 8601 duration as used by result.duration, for example PT1H30M or P4W.

public readonly struct XapiDuration : IEquatable<XapiDuration>
Implements
Inherited Members

Remarks

Only the format of ISO 8601:2004 4.4.3.2 is accepted (PnYnMnDTnHnMnS or PnW, a fraction only on the last component); the alternative format of 4.4.3.3 (P0001-02-03T…) is rejected, as IEEE 9274.1.1, 4.2.7 requires.

The original text is kept and written back unchanged. Equality compares component by component and ignores precision beyond 0.01 second (IEEE 9274.1.1, 4.2.7 "Duration"). Components are not converted into each other, so PT60S and PT1M are different, which matches the 1.0.3 rule that a duration is compared as a string.

Properties

Days

The days component, or zero.

public decimal Days { get; }

Property Value

decimal

Hours

The hours component, or zero.

public decimal Hours { get; }

Property Value

decimal

Minutes

The minutes component, or zero.

public decimal Minutes { get; }

Property Value

decimal

Months

The months component, or zero.

public decimal Months { get; }

Property Value

decimal

Seconds

The seconds component (with any fraction), or zero.

public decimal Seconds { get; }

Property Value

decimal

Weeks

The weeks component, or zero.

public decimal Weeks { get; }

Property Value

decimal

Years

The years component, or zero.

public decimal Years { get; }

Property Value

decimal

Methods

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Equals(XapiDuration)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(XapiDuration other)

Parameters

other XapiDuration

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

FromTimeSpan(TimeSpan)

Creates a duration from a TimeSpan, as PnDTnHnMn.nnS with zero components left out and seconds truncated to 0.01 (the precision IEEE 9274.1.1 asks Learning Record Providers to send at most).

public static XapiDuration FromTimeSpan(TimeSpan value)

Parameters

value TimeSpan

A non-negative time span.

Returns

XapiDuration

The duration.

Exceptions

ArgumentOutOfRangeException

value is negative.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Parse(string)

Parses an ISO 8601 duration.

public static XapiDuration Parse(string iso8601)

Parameters

iso8601 string

The duration text.

Returns

XapiDuration

The duration.

Exceptions

FormatException

The text is not an ISO 8601 4.4.3.2 duration.

ToString()

Returns the original duration text (PT0S for the default value).

public override string ToString()

Returns

string

The ISO 8601 text.

ToTimeSpan()

Converts to a TimeSpan using nominal lengths: a year is 365 days and a month is 30 days. The xAPI standard defines no conversion, so use this for display or rough arithmetic only.

public TimeSpan ToTimeSpan()

Returns

TimeSpan

The time span.

Exceptions

OverflowException

The duration does not fit in a TimeSpan.

TryParse(string?, out XapiDuration)

Tries to parse an ISO 8601 duration.

public static bool TryParse(string? value, out XapiDuration duration)

Parameters

value string

The duration text.

duration XapiDuration

The duration when the method returns true.

Returns

bool

true when the text is a valid duration.

Operators

operator ==(XapiDuration, XapiDuration)

Equality operator (0.01 second precision).

public static bool operator ==(XapiDuration left, XapiDuration right)

Parameters

left XapiDuration

The first duration.

right XapiDuration

The second duration.

Returns

bool

true when the durations are equal.

operator !=(XapiDuration, XapiDuration)

Inequality operator.

public static bool operator !=(XapiDuration left, XapiDuration right)

Parameters

left XapiDuration

The first duration.

right XapiDuration

The second duration.

Returns

bool

true when the durations differ.