Class OffsetDatePattern
Represents a pattern for parsing and formatting OffsetDate values.
Since 2.3.x
Availability netstandard2.0
Inheritance
Object
OffsetDatePattern
Implements
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public sealed class OffsetDatePattern : IPattern<OffsetDate>
Properties
FullRoundtrip
Gets an invariant offset date pattern based on ISO-8601
including offset from UTC and calendar ID.
Since 2.3.x
Availability netstandard2.0
Declaration
public static OffsetDatePattern FullRoundtrip { get; }
Property Value
Type | Description |
---|---|
OffsetDatePattern | An invariant offset date pattern based on ISO-8601 (down to the nanosecond) including offset from UTC and calendar ID. |
Remarks
The returned pattern corresponds to a custom pattern of
"uuuu'-'MM'-'dd'o<G> '('c')'". This will round-trip any value in any calendar,
and is available as the "r" standard pattern.
GeneralIso
Gets an invariant offset date pattern based on ISO-8601, including offset from UTC.
Since 2.3.x
Availability netstandard2.0
Declaration
public static OffsetDatePattern GeneralIso { get; }
Property Value
Type | Description |
---|---|
OffsetDatePattern | An invariant offset date pattern based on ISO-8601 (down to the second), including offset from UTC. |
Remarks
The calendar system is not parsed or formatted as part of this pattern. It corresponds to a custom pattern of
"uuuu'-'MM'-'ddo<G>". This pattern is available as the "G" standard pattern (even though it is invariant).
PatternText
Gets the pattern text for this pattern, as supplied on creation.
Since 2.3.x
Availability 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 2.3.x
Availability netstandard2.0
Declaration
public OffsetDate TemplateValue { get; }
Property Value
Type | Description |
---|---|
OffsetDate | The value used as a template for parsing. |
Methods
AppendFormat(OffsetDate, StringBuilder)
Formats the given value as text according to the rules of this pattern,
appending to the given System.Text.StringBuilder.
Since 2.3.x
Availability netstandard2.0
Declaration
public StringBuilder AppendFormat(OffsetDate value, StringBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
OffsetDate | 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, OffsetDate)
Creates a pattern for the given pattern text, culture, and template value.
Since 2.3.x
Availability netstandard2.0
Declaration
public static OffsetDatePattern Create(string patternText, CultureInfo cultureInfo, OffsetDate templateValue)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
CultureInfo | cultureInfo | The culture to use in the pattern |
OffsetDate | templateValue | Template value to use for unspecified fields |
Returns
Type | Description |
---|---|
OffsetDatePattern | A pattern for parsing and formatting local dates. |
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 culture, using the default
template value of midnight January 1st 2000 at an offset of 0.
Since 2.3.x
Availability netstandard2.0
Declaration
public static OffsetDatePattern CreateWithCurrentCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
OffsetDatePattern | A pattern for parsing and formatting local dates. |
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, using the default
template value of midnight January 1st 2000 at an offset of 0.
Since 2.3.x
Availability netstandard2.0
Declaration
public static OffsetDatePattern CreateWithInvariantCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
OffsetDatePattern | A pattern for parsing and formatting local dates. |
Remarks
See the user guide for the available pattern text options.
Exceptions
Type | Condition |
---|---|
InvalidPatternException | The pattern text was invalid. |
Format(OffsetDate)
Formats the given offset date as text according to the rules of this pattern.
Since 2.3.x
Availability netstandard2.0
Declaration
public string Format(OffsetDate value)
Parameters
Type | Name | Description |
---|---|---|
OffsetDate | value | The offset date to format. |
Returns
Type | Description |
---|---|
String | The offset date formatted according to this pattern. |
Parse(String)
Parses the given text value according to the rules of this pattern.
Since 2.3.x
Availability netstandard2.0
Declaration
public ParseResult<OffsetDate> Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text value to parse. |
Returns
Type | Description |
---|---|
ParseResult<OffsetDate> | 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.
WithCalendar(CalendarSystem)
Creates a pattern like this one, but with the template value modified to use
the specified calendar system.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDatePattern WithCalendar(CalendarSystem calendar)
Parameters
Type | Name | Description |
---|---|---|
CalendarSystem | calendar | The calendar system to convert the template value into. |
Returns
Type | Description |
---|---|
OffsetDatePattern | A new pattern with a template value in the specified calendar system. |
Remarks
Care should be taken in two (relatively rare) scenarios. Although the default template value is supported by all Noda Time calendar systems, if a pattern is created with a different template value and then this method is called with a calendar system which doesn't support that date, an exception will be thrown. Additionally, if the pattern only specifies some date fields, it's possible that the new template value will not be suitable for all values.
WithCulture(CultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDatePattern WithCulture(CultureInfo cultureInfo)
Parameters
Type | Name | Description |
---|---|---|
CultureInfo | cultureInfo | The culture to use in the new pattern. |
Returns
Type | Description |
---|---|
OffsetDatePattern | A new pattern with the given culture. |
WithPatternText(String)
Creates a pattern for the same original localization information as this pattern, but with the specified
pattern text.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDatePattern WithPatternText(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | The pattern text to use in the new pattern. |
Returns
Type | Description |
---|---|
OffsetDatePattern | A new pattern with the given pattern text. |
WithTemplateValue(OffsetDate)
Creates a pattern for the same original pattern text and culture as this pattern, but with
the specified template value.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDatePattern WithTemplateValue(OffsetDate newTemplateValue)
Parameters
Type | Name | Description |
---|---|---|
OffsetDate | newTemplateValue | The template value to use in the new pattern. |
Returns
Type | Description |
---|---|
OffsetDatePattern | A new pattern with the given template value. |