Struct OffsetDate
A combination of a LocalDate and an Offset, to represent
a date at a specific offset from UTC but without any time-of-day information.
Since 2.3.x
Availability netstandard2.0
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(OffsetDateTypeConverter))]
public struct OffsetDate : IEquatable<OffsetDate>, IXmlSerializable, IFormattable
Remarks
Equality is defined in a component-wise fashion: two values are the same if they represent equal dates (including being in the same calendar) and equal offsets from UTC. Ordering between offset dates is not defined.
Constructors
OffsetDate(LocalDate, Offset)
Constructs an instance of the specified date and offset.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDate(LocalDate date, Offset offset)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | date | The date part of the value. |
Offset | offset | The offset part of the value. |
Sample snippet
using NodaTime;
using System;
OffsetDate offsetDate = new OffsetDate(
new LocalDate(2019, 5, 3),
Offset.FromHours(3));
Console.WriteLine(offsetDate.Offset);
Console.WriteLine(offsetDate.Date);
Output:
+03
Friday, 03 May 2019
Properties
Calendar
Gets the calendar system associated with this offset date.
Since 2.3.x
Availability netstandard2.0
Declaration
public CalendarSystem Calendar { get; }
Property Value
Type | Description |
---|---|
CalendarSystem | The calendar system associated with this offset date. |
Date
Gets the local date represented by this value.
Since 2.3.x
Availability netstandard2.0
Declaration
public LocalDate Date { get; }
Property Value
Type | Description |
---|---|
LocalDate | The local date represented by this value. |
Day
Gets the day of this offset date within the month.
Since 2.3.x
Availability netstandard2.0
Declaration
public int Day { get; }
Property Value
Type | Description |
---|---|
Int32 | The day of this offset date within the month. |
DayOfWeek
Gets the week day of this offset date expressed as an IsoDayOfWeek value.
Since 2.3.x
Availability netstandard2.0
Declaration
public IsoDayOfWeek DayOfWeek { get; }
Property Value
Type | Description |
---|---|
IsoDayOfWeek | The week day of this offset date expressed as an IsoDayOfWeek . |
DayOfYear
Gets the day of this offset date within the year.
Since 2.3.x
Availability netstandard2.0
Declaration
public int DayOfYear { get; }
Property Value
Type | Description |
---|---|
Int32 | The day of this offset date within the year. |
Era
Gets the era of this offset date.
Since 2.3.x
Availability netstandard2.0
Declaration
public Era Era { get; }
Property Value
Type | Description |
---|---|
Era | The era of this offset date. |
Month
Gets the month of this offset date within the year.
Since 2.3.x
Availability netstandard2.0
Declaration
public int Month { get; }
Property Value
Type | Description |
---|---|
Int32 | The month of this offset date within the year. |
Offset
Gets the offset from UTC of this value.
Since 2.3.x
Availability netstandard2.0
Declaration
public Offset Offset { get; }
Property Value
Type | Description |
---|---|
Offset | The offset from UTC of this value. |
Year
Gets the year of this offset date.
Since 2.3.x
Availability netstandard2.0
Declaration
public int Year { get; }
Property Value
Type | Description |
---|---|
Int32 | The year of this offset date. |
Remarks
This returns the "absolute year", so, for the ISO calendar,
a value of 0 means 1 BC, for example.
YearOfEra
Gets the year of this offset date within the era.
Since 2.3.x
Availability netstandard2.0
Declaration
public int YearOfEra { get; }
Property Value
Type | Description |
---|---|
Int32 | The year of this offset date within the era. |
Methods
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the OffsetDate XML serialization to the given
xmlSchemaSet
.
Since 3.0.x
Availability netstandard2.0
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Type | Name | Description |
---|---|---|
XmlSchemaSet | xmlSchemaSet | The XML schema set provided by System.Xml.Serialization.XmlSchemaExporter. |
Returns
Type | Description |
---|---|
XmlQualifiedName | The qualified name of the schema type that was added to the xmlSchemaSet . |
At(LocalTime)
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDateTime At(LocalTime time)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | time | The time to combine with this date. |
Returns
Type | Description |
---|---|
OffsetDateTime | The OffsetDateTime representation of the given time on this date. |
Deconstruct(out LocalDate, out Offset)
Deconstruct this value into its components.
Since 2.3.x
Availability netstandard2.0
Declaration
public void Deconstruct(out LocalDate localDate, out Offset offset)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | localDate | The LocalDate component. |
Offset | offset | The Offset component. |
Equals(OffsetDate)
Compares two OffsetDate values for equality.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability netstandard2.0
Declaration
public bool Equals(OffsetDate other)
Parameters
Type | Name | Description |
---|---|---|
OffsetDate | other | The value to compare this offset date with. |
Returns
Type | Description |
---|---|
Boolean | True if the given value is another offset date equal to this one; false otherwise. |
Equals(Object)
Compares two OffsetDate values for equality.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability netstandard2.0
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare this offset date with. |
Returns
Type | Description |
---|---|
Boolean | True if the given value is another offset date equal to this one; false otherwise. |
Overrides
System.ValueType.Equals(System.Object)
GetHashCode()
Returns a hash code for this offset date.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability netstandard2.0
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this offset date. |
Overrides
System.ValueType.GetHashCode()
ToString()
Returns a System.String that represents this instance.
Since 2.3.x
Availability netstandard2.0
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The value of the current instance in the default format pattern ("G"), using the current thread's culture to obtain a format provider. |
Overrides
System.ValueType.ToString()
ToString(String, IFormatProvider)
Formats the value of the current instance using the specified pattern.
Since 2.3.x
Availability netstandard2.0
Declaration
public string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | The System.String specifying the pattern to use, or null to use the default format pattern ("G"). |
IFormatProvider | formatProvider | The System.IFormatProvider to use when formatting the value, or null to use the current thread's culture to obtain a format provider. |
Returns
Type | Description |
---|---|
String | A System.String containing the value of the current instance in the specified format. |
With(Func<LocalDate, LocalDate>)
Returns this offset date, with the given date adjuster applied to it, maintaining the existing offset.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDate With(Func<LocalDate, LocalDate> adjuster)
Parameters
Type | Name | Description |
---|---|---|
Func<LocalDate, LocalDate> | adjuster | The adjuster to apply. |
Returns
Type | Description |
---|---|
OffsetDate | The adjusted offset date. |
Remarks
If the adjuster attempts to construct an
invalid date (such as by trying to set a day-of-month of 30 in February), any exception thrown by
that construction attempt will be propagated through this method.
Sample snippet
using NodaTime;
using System;
var original = new OffsetDate(
new LocalDate(2019, 5, 3),
Offset.FromHours(3));
Func<LocalDate, LocalDate> tomorrowAdjuster = x => x + Period.FromDays(1);
OffsetDate updated = original.With(tomorrowAdjuster);
Console.WriteLine(updated.Offset);
Console.WriteLine(updated.Date);
Output:
+03
Saturday, 04 May 2019
WithCalendar(CalendarSystem)
Creates a new OffsetDate representing the same physical date and offset, but in a different calendar.
The returned value is likely to have different date field values to this one.
For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDate WithCalendar(CalendarSystem calendar)
Parameters
Type | Name | Description |
---|---|---|
CalendarSystem | calendar | The calendar system to convert this offset date to. |
Returns
Type | Description |
---|---|
OffsetDate | The converted OffsetDate . |
Sample snippet
using NodaTime;
using System;
var original = new OffsetDate(
new LocalDate(2019, 5, 3, CalendarSystem.Iso),
Offset.FromHours(3));
OffsetDate updated = original.WithCalendar(CalendarSystem.Gregorian);
Console.WriteLine(updated.Offset);
Console.WriteLine(updated.Calendar);
Output:
+03
Gregorian
WithOffset(Offset)
Creates a new OffsetDate for the same date, but with the specified UTC offset.
Since 2.3.x
Availability netstandard2.0
Declaration
public OffsetDate WithOffset(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The new UTC offset. |
Returns
Type | Description |
---|---|
OffsetDate | A new OffsetDate for the same date, but with the specified UTC offset. |
Sample snippet
using NodaTime;
using System;
var original = new OffsetDate(
new LocalDate(2019, 5, 3),
Offset.FromHours(3));
OffsetDate updated = original.WithOffset(Offset.FromHours(-3));
Console.WriteLine(updated.Offset);
Console.WriteLine(updated.Date);
Output:
-03
Friday, 03 May 2019
Operators
Equality(OffsetDate, OffsetDate)
Implements the operator == (equality).
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability netstandard2.0
Declaration
public static bool operator ==(OffsetDate left, OffsetDate right)
Parameters
Type | Name | Description |
---|---|---|
OffsetDate | left | The left hand side of the operator. |
OffsetDate | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if values are equal to each other, otherwise false . |
Inequality(OffsetDate, OffsetDate)
Implements the operator != (inequality).
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability netstandard2.0
Declaration
public static bool operator !=(OffsetDate left, OffsetDate right)
Parameters
Type | Name | Description |
---|---|---|
OffsetDate | left | The left hand side of the operator. |
OffsetDate | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if values are not equal to each other, otherwise false . |
Explicit Interface Implementations
IXmlSerializable.GetSchema()
Since 2.3.x
Availability netstandard2.0
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type | Description |
---|---|
XmlSchema |
IXmlSerializable.ReadXml(XmlReader)
Since 2.3.x
Availability netstandard2.0
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader |
IXmlSerializable.WriteXml(XmlWriter)
Since 2.3.x
Availability netstandard2.0
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer |
Implements
System.IEquatable<T>
System.Xml.Serialization.IXmlSerializable
System.IFormattable