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
Hours
The hours component, or zero.
public decimal Hours { get; }
Property Value
Minutes
The minutes component, or zero.
public decimal Minutes { get; }
Property Value
Months
The months component, or zero.
public decimal Months { get; }
Property Value
Seconds
The seconds component (with any fraction), or zero.
public decimal Seconds { get; }
Property Value
Weeks
The weeks component, or zero.
public decimal Weeks { get; }
Property Value
Years
The years component, or zero.
public decimal Years { get; }
Property Value
Methods
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
otherXapiDurationAn object to compare with this object.
Returns
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
valueTimeSpanA non-negative time span.
Returns
- XapiDuration
The duration.
Exceptions
- ArgumentOutOfRangeException
valueis 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
iso8601stringThe 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
valuestringThe duration text.
durationXapiDurationThe duration when the method returns true.
Returns
Operators
operator ==(XapiDuration, XapiDuration)
Equality operator (0.01 second precision).
public static bool operator ==(XapiDuration left, XapiDuration right)
Parameters
leftXapiDurationThe first duration.
rightXapiDurationThe second duration.
Returns
operator !=(XapiDuration, XapiDuration)
Inequality operator.
public static bool operator !=(XapiDuration left, XapiDuration right)
Parameters
leftXapiDurationThe first duration.
rightXapiDurationThe second duration.