Class PeriodPattern
Represents a pattern for parsing and formatting Period values.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Inherited Members
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 net6.0, net8.0, 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. |
Remarks
Note that normalizing the period when formatting will cause an OverflowException
if the period contains more than 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 net6.0, net8.0, 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. |
Methods
AppendFormat(Period, StringBuilder)
Formats the given value as text according to the rules of this pattern,
appending to the given StringBuilder.
Since 2.0.x
Availability net6.0, net8.0, 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 . |
Format(Period)
Formats the given period as text according to the rules of this pattern.
Since 1.0.x
Availability net6.0, net8.0, 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. |
Parse(string)
Parses the given text value according to the rules of this pattern.
Since 1.0.x
Availability net6.0, net8.0, 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. |
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.