Class PeriodPattern
Represents a pattern for parsing and formatting Period values.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Inheritance
Object
PeriodPattern
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 PeriodPattern : IPattern<Period>
Properties
NormalizingIso
A "normalizing" pattern which abides by the ISO-8601 duration format as far as possible.
Weeks are added to the number of days (after multiplying by 7). Time units are normalized
(extending into days where necessary), and fractions of seconds are represented within the
seconds part. Unlike ISO-8601, which pattern allows for negative values within a period.
Since 1.4.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public static PeriodPattern NormalizingIso { get; }
Property Value
Type | Description |
---|---|
PeriodPattern | A "normalizing" pattern which abides by the ISO-8601 duration format as far as possible. (The value returned is never null.) |
Remarks
Note that normalizing the period when formatting will cause an System.OverflowException
if the period contains more than System.Int64.MaxValue ticks when the
combined weeks/days/time portions are considered. Such a period could never
be useful anyway, however.
Roundtrip
Pattern which uses the normal ISO format for all the supported ISO
fields, but extends the time part with "s" for milliseconds, "t" for ticks and "n" for nanoseconds.
No normalization is carried out, and a period may contain weeks as well as years, months and days.
Each element may also be negative, independently of other elements. This pattern round-trips its
values: a parse/format cycle will produce an identical period, including units.
Since 1.4.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public static PeriodPattern Roundtrip { get; }
Property Value
Type | Description |
---|---|
PeriodPattern | Pattern which uses the normal ISO format for all the supported ISO fields, but extends the time part with "s" for milliseconds, "t" for ticks and "n" for nanoseconds. (The value returned is never null.) |
Methods
AppendFormat(Period, 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, netstandard2.0
Declaration
public StringBuilder AppendFormat(Period value, StringBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
Period | value | The value to format. |
StringBuilder | builder | The StringBuilder to append to. |
Returns
Type | Description |
---|---|
StringBuilder | The builder passed in as builder . (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | value or builder is null |
Format(Period)
Formats the given period as text according to the rules of this pattern.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public string Format(Period value)
Parameters
Type | Name | Description |
---|---|---|
Period | value | The period to format. |
Returns
Type | Description |
---|---|
String | The period formatted according to this pattern. (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | value is null. |
Parse(String)
Parses the given text value according to the rules of this pattern.
Since 1.0.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public ParseResult<Period> Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text value to parse. |
Returns
Type | Description |
---|---|
ParseResult<Period> | 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.