Class Duration
Representation of ISO 8601 Durations
Inheritance
System.Object
Duration
Assembly: Time.dll
Syntax
public class Duration : Object
Constructors
Duration()
The default constructor produces the duration Zero
Declaration
Duration(Int32, Int32, Int32, Int32, Int32, Int32)
Declaration
public Duration(int years, int months, int days, int hours, int minutes, int seconds)
Parameters
| Type |
Name |
Description |
| System.Int32 |
years |
|
| System.Int32 |
months |
|
| System.Int32 |
days |
|
| System.Int32 |
hours |
|
| System.Int32 |
minutes |
|
| System.Int32 |
seconds |
|
Properties
Days
Declaration
Property Value
| Type |
Description |
| System.Int32 |
|
Hours
Declaration
public int Hours { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Minutes
Declaration
public int Minutes { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Months
Declaration
public int Months { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Seconds
Declaration
public int Seconds { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Years
Declaration
public int Years { get; }
Property Value
| Type |
Description |
| System.Int32 |
|
Zero
The duration that makes no changes when added to or subtracted from
dates or other durations
Declaration
public static Duration Zero { get; }
Property Value
Methods
Equals(Object)
Declaration
public override bool Equals(object other)
Parameters
| Type |
Name |
Description |
| System.Object |
other |
|
Returns
| Type |
Description |
| System.Boolean |
|
FromDays(Int32)
Convenience function to produce a duration of k days
Declaration
public static Duration FromDays(int k)
Parameters
| Type |
Name |
Description |
| System.Int32 |
k |
|
Returns
FromSeconds(Double)
Convert a number of seconds to a duration
Declaration
public static Duration FromSeconds(double s)
Parameters
| Type |
Name |
Description |
| System.Double |
s |
The number of seconds to convert
|
Returns
FromTimeSpan(TimeSpan)
Convert a System.TimeSpan to a duration
Declaration
public static Duration FromTimeSpan(TimeSpan ts)
Parameters
| Type |
Name |
Description |
| System.TimeSpan |
ts |
The timespan to convert
|
Returns
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type |
Description |
| System.Int32 |
|
IsNonNegative()
Return true if every part of the duration is non-negative
Declaration
public bool IsNonNegative()
Returns
| Type |
Description |
| System.Boolean |
True if every part (seconds, minutes, hours, days, years, months)
of the duration is individually greater than or equal to zero, false
otherwise.
|
IsNonPositive()
Return true if every part of the duration is non-positive
Declaration
public bool IsNonPositive()
Returns
| Type |
Description |
| System.Boolean |
True if every part (seconds, minutes, hours, days, years, months)
of the duration is individually less than or equal to zero, false
otherwise.
|
Negate()
Return the opposite duration, e.g., P3D becomes -P3D.
Declaration
Returns
Parse(String)
Parse a duration from a string
Declaration
public static Duration Parse(string s)
Parameters
| Type |
Name |
Description |
| System.String |
s |
The string to parse. The input should either be parseable
by TimeSpan.Parse, or be on the following form:
[-]P[[-]ddddY][[-]ddM][[-]ddD][T[[-]ddH][[-]ddM][[-]ddS]]
Here d ranges over the digits 0-9, [] indicates optional
components, and remaining characters are literals.
|
Returns
Subtract(DateTimeOffset, DateTimeOffset)
Subtraction of dates, producing a duration
Declaration
public static Duration Subtract(DateTimeOffset u, DateTimeOffset v)
Parameters
| Type |
Name |
Description |
| System.DateTimeOffset |
u |
|
| System.DateTimeOffset |
v |
|
Returns
| Type |
Description |
| Duration |
The difference between the dates u and v.
The resulting duration is partially normalised to seconds, minutes less
than 60; hours less than 24. Days are not normalised.
|
Declaration
public string ToInformalString()
Returns
| Type |
Description |
| System.String |
|
ToString()
Declaration
public override string ToString()
Returns
| Type |
Description |
| System.String |
|
TryParse(String)
Like DCR.Time.Duration.Parse, but returns None rather
than throwing if the input is on the wrong form.
Declaration
public static FSharpOption<Duration> TryParse(string s)
Parameters
| Type |
Name |
Description |
| System.String |
s |
|
Returns
| Type |
Description |
| Microsoft.FSharp.Core.FSharpOption<Duration> |
|
Operators
Addition(Duration, Duration)
Declaration
public static Duration operator +(Duration u, Duration v)
Parameters
Returns
Addition(Duration, DateTimeOffset)
Addition of durations and dates; equivalent to addition of date and duration
Declaration
public static DateTimeOffset operator +(Duration u, DateTimeOffset v)
Parameters
| Type |
Name |
Description |
| Duration |
u |
|
| System.DateTimeOffset |
v |
|
Returns
| Type |
Description |
| System.DateTimeOffset |
|
Addition(DateTimeOffset, Duration)
Addition of dates and durations
Declaration
public static DateTimeOffset operator +(DateTimeOffset u, Duration v)
Parameters
| Type |
Name |
Description |
| System.DateTimeOffset |
u |
|
| Duration |
v |
|
Returns
| Type |
Description |
| System.DateTimeOffset |
|
Subtraction(Duration, Duration)
Declaration
public static Duration operator -(Duration u, Duration v)
Parameters
Returns
Subtraction(DateTimeOffset, Duration)
Subtraction of dates and durations
Declaration
public static DateTimeOffset operator -(DateTimeOffset u, Duration v)
Parameters
| Type |
Name |
Description |
| System.DateTimeOffset |
u |
|
| Duration |
v |
|
Returns
| Type |
Description |
| System.DateTimeOffset |
|