Class DurationPattern
Represents a pattern for parsing and formatting Duration values.
Since 1.2.x
Availability net45, netstandard1.3
Inheritance
Object
DurationPattern
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public sealed class DurationPattern : IPattern<Duration>
Properties
PatternText
Gets the pattern text for this pattern, as supplied on creation.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public string PatternText { get; }
Property Value
Type | Description |
---|---|
String | The pattern text for this pattern, as supplied on creation. (The value returned is never null.) |
Roundtrip
Gets the general pattern for durations using the invariant culture, with a format string of "-D:hh:mm:ss.FFFFFFFFF".
This pattern round-trips.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public static DurationPattern Roundtrip { get; }
Property Value
Type | Description |
---|---|
Duration |
The general pattern for durations using the invariant culture. (The value returned is never null.) |
Methods
AppendFormat(Duration, StringBuilder)
Formats the given value as text according to the rules of this pattern,
appending to the given System.Text.StringBuilder .
Since 2.0.x
Availability net45, netstandard1.3
Declaration
public StringBuilder AppendFormat(Duration value, StringBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
Duration | value | The value to format. |
String |
builder | The StringBuilder to append to. |
Returns
Type | Description |
---|---|
String |
The builder passed in as builder . (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
Argument |
builder is null. |
Create(String, CultureInfo)
Creates a pattern for the given pattern text and culture.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public static DurationPattern Create(string patternText, CultureInfo cultureInfo)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Culture |
cultureInfo | The culture to use in the pattern |
Returns
Type | Description |
---|---|
Duration |
A pattern for parsing and formatting offsets. (The value returned is never null.) |
Remarks
See the user guide for the available pattern text options.
Exceptions
Type | Condition |
---|---|
Invalid |
The pattern text was invalid. |
Argument |
patternText or cultureInfo is null |
CreateWithCurrentCulture(String)
Creates a pattern for the given pattern text in the current thread's current culture.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public static DurationPattern CreateWithCurrentCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
Duration |
A pattern for parsing and formatting offsets. (The value returned is never null.) |
Remarks
See the user guide for the available pattern text options. Note that the current culture
is captured at the time this method is called - it is not captured at the point of parsing
or formatting values.
Exceptions
Type | Condition |
---|---|
Invalid |
The pattern text was invalid. |
Argument |
patternText is null. |
CreateWithInvariantCulture(String)
Creates a pattern for the given pattern text in the invariant culture.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public static DurationPattern CreateWithInvariantCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
Duration |
A pattern for parsing and formatting offsets. (The value returned is never null.) |
Remarks
See the user guide for the available pattern text options. Note that the current culture
is captured at the time this method is called - it is not captured at the point of parsing
or formatting values.
Exceptions
Type | Condition |
---|---|
Invalid |
The pattern text was invalid. |
Argument |
patternText is null. |
Format(Duration)
Formats the given duration as text according to the rules of this pattern.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public string Format(Duration value)
Parameters
Type | Name | Description |
---|---|---|
Duration | value | The duration to format. |
Returns
Type | Description |
---|---|
String | The duration formatted according to this pattern. (The value returned is never null.) |
Parse(String)
Parses the given text value according to the rules of this pattern.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public ParseResult<Duration> Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text value to parse. |
Returns
Type | Description |
---|---|
Parse |
The result of parsing, which may be successful or unsuccessful. (The value returned is never null.) |
Remarks
This method never throws an exception (barring a bug in Noda Time itself). Even errors such as
the argument being null are wrapped in a parse result.
WithCulture(CultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Since 1.2.x
Availability net45, netstandard1.3
Declaration
public DurationPattern WithCulture(CultureInfo cultureInfo)
Parameters
Type | Name | Description |
---|---|---|
Culture |
cultureInfo | The culture to use in the new pattern. |
Returns
Type | Description |
---|---|
Duration |
A new pattern with the given culture. (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
Argument |
cultureInfo is null. |