Class YearMonthPattern
Represents a pattern for parsing and formatting YearMonth values.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public class YearMonthPattern : IPattern<YearMonth>
Properties
Iso
Gets an invariant year/month pattern which is ISO-8601 compatible.
This corresponds to the text pattern "uuuu'-'MM".
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static YearMonthPattern Iso { get; }
Property Value
| Type | Description |
|---|---|
| YearMonthPattern | An invariant year/month pattern which is ISO-8601 compatible. |
Remarks
This pattern corresponds to the 'g' standard pattern.
PatternText
Gets the pattern text for this pattern, as supplied on creation.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string PatternText { get; }
Property Value
| Type | Description |
|---|---|
| string | The pattern text for this pattern, as supplied on creation. |
TemplateValue
Gets the value used as a template for parsing: any field values unspecified
in the pattern are taken from the template.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public YearMonth TemplateValue { get; }
Property Value
| Type | Description |
|---|---|
| YearMonth | The value used as a template for parsing. |
TwoDigitYearMax
Maximum two-digit-year in the template to treat as the current century.
If the value parsed is higher than this, the result is adjusted to the previous century.
This value defaults to 30. To create a pattern with a different value, use WithTwoDigitYearMax(int).
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int TwoDigitYearMax { get; }
Property Value
| Type | Description |
|---|---|
| int | The value used for the maximum two-digit-year, in the range 0-99 inclusive. |
Methods
AppendFormat(YearMonth, StringBuilder)
Formats the given value as text according to the rules of this pattern,
appending to the given StringBuilder.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public StringBuilder AppendFormat(YearMonth value, StringBuilder builder)
Parameters
| Type | Name | Description |
|---|---|---|
| YearMonth | value | The value to format. |
| StringBuilder | builder | The StringBuilder to append to. |
Returns
| Type | Description |
|---|---|
| StringBuilder | The builder passed in as builder. |
Create(string, CultureInfo)
Creates a pattern for the given pattern text and culture, with a template value of 2000-01.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static YearMonthPattern Create(string patternText, CultureInfo cultureInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
| CultureInfo | cultureInfo | The culture to use in the pattern |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A pattern for parsing and formatting year/months. |
Remarks
See the user guide for the available pattern text options.
Exceptions
| Type | Condition |
|---|---|
| InvalidPatternException | The pattern text was invalid. |
Create(string, CultureInfo, YearMonth)
Creates a pattern for the given pattern text, culture, and template value.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static YearMonthPattern Create(string patternText, CultureInfo cultureInfo, YearMonth templateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
| CultureInfo | cultureInfo | The culture to use in the pattern |
| YearMonth | templateValue | Template value to use for unspecified fields |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A pattern for parsing and formatting year/months. |
Remarks
See the user guide for the available pattern text options.
Exceptions
| Type | Condition |
|---|---|
| InvalidPatternException | The pattern text was invalid. |
CreateWithCurrentCulture(string)
Creates a pattern for the given pattern text in the current thread's current culture.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static YearMonthPattern CreateWithCurrentCulture(string patternText)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A pattern for parsing and formatting year/month values. |
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 |
|---|---|
| InvalidPatternException | The pattern text was invalid. |
CreateWithInvariantCulture(string)
Creates a pattern for the given pattern text in the invariant culture.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static YearMonthPattern CreateWithInvariantCulture(string patternText)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A pattern for parsing and formatting year/month values. |
Remarks
See the user guide for the available pattern text options.
Exceptions
| Type | Condition |
|---|---|
| InvalidPatternException | The pattern text was invalid. |
Format(YearMonth)
Formats the given year/month as text according to the rules of this pattern.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string Format(YearMonth value)
Parameters
| Type | Name | Description |
|---|---|---|
| YearMonth | value | The value to format. |
Returns
| Type | Description |
|---|---|
| string | The year/month formatted according to this pattern. |
Parse(string)
Parses the given text value according to the rules of this pattern.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ParseResult<YearMonth> Parse(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text value to parse. |
Returns
| Type | Description |
|---|---|
| ParseResult<YearMonth> | 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.
WithCulture(CultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public YearMonthPattern WithCulture(CultureInfo cultureInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| CultureInfo | cultureInfo | The culture to use in the new pattern. |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A new pattern with the given culture. |
WithTemplateValue(YearMonth)
Creates a pattern like this one, but with the specified template value.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public YearMonthPattern WithTemplateValue(YearMonth newTemplateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| YearMonth | newTemplateValue | The template value for the new pattern, used to fill in unspecified fields. |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A new pattern with the given template value. |
WithTwoDigitYearMax(int)
Creates a pattern like this one, but with a different TwoDigitYearMax value.
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public YearMonthPattern WithTwoDigitYearMax(int twoDigitYearMax)
Parameters
| Type | Name | Description |
|---|---|---|
| int | twoDigitYearMax | The value to use for TwoDigitYearMax in the new pattern, in the range 0-99 inclusive. |
Returns
| Type | Description |
|---|---|
| YearMonthPattern | A new pattern with the specified maximum two-digit-year. |