Struct AnnualDate
Represents an annual date (month and day) in the ISO calendar but without a specific year,
typically for recurrent events such as birthdays, anniversaries, and deadlines.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(AnnualDateTypeConverter))]
public readonly struct AnnualDate : IEquatable<AnnualDate>, IComparable<AnnualDate>, IComparable, IFormattable, IXmlSerializable, IComparisonOperators<AnnualDate, AnnualDate, bool>, IEqualityOperators<AnnualDate, AnnualDate, bool>
Constructors
AnnualDate(int, int)
Constructs an instance for the given month and day in the ISO calendar.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public AnnualDate(int month, int day)
Parameters
Type |
Name |
Description |
int |
month |
The month of year. |
int |
day |
The day of month. |
Exceptions
Properties
Day
Gets the day of month.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
Property Value
Type |
Description |
int |
The day of month. |
Month
Gets the month of year.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int Month { get; }
Property Value
Type |
Description |
int |
The month of year. |
Methods
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the
AnnualDate XML serialization to the given
xmlSchemaSet
.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Returns
Type |
Description |
XmlQualifiedName |
The qualified name of the schema type that was added to the xmlSchemaSet . |
CompareTo(AnnualDate)
Indicates whether this annual date is earlier, later or the same as another one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int CompareTo(AnnualDate other)
Parameters
Type |
Name |
Description |
AnnualDate |
other |
The other annual date to compare this one with |
Returns
Type |
Description |
int |
A value less than zero if this annual date is earlier than other ;
zero if this time is the same as other ; a value greater than zero if this annual date is
later than other . |
Sample snippet
using NodaTime;
using System;
var february23rd = new AnnualDate(2, 23);
var august17th = new AnnualDate(8, 17);
var lessThan = february23rd.CompareTo(august17th);
var equal = february23rd.CompareTo(february23rd);
var greaterThan = august17th.CompareTo(february23rd);
Console.WriteLine(lessThan);
Console.WriteLine(equal);
Console.WriteLine(greaterThan);
Output:
-1
0
1
CompareTo(object?)
Implementation of
CompareTo(object) to compare two AnnualDates.
See the type documentation for a description of ordering semantics.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int CompareTo(object? obj)
Parameters
Type |
Name |
Description |
object |
obj |
The object to compare this value with. |
Returns
Type |
Description |
int |
The result of comparing this AnnualDate with another one.
If obj is null, this method returns a value greater than 0. |
Exceptions
Equals(AnnualDate)
Compares this annual date with the specified one for equality.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public bool Equals(AnnualDate other)
Parameters
Type |
Name |
Description |
AnnualDate |
other |
The other annual date to compare this one with |
Returns
Type |
Description |
bool |
True if the specified annual date is equal to this one; false otherwise |
Sample snippet
using NodaTime;
using System;
var february23rd = new AnnualDate(2, 23);
var august17th = new AnnualDate(8, 17);
var unequal = february23rd.Equals(august17th);
var equal = february23rd.Equals(february23rd);
Console.WriteLine(unequal);
Console.WriteLine(equal);
Output:
False
True
Equals(object?)
Compares this annual date with the specified reference.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public override bool Equals(object? obj)
Parameters
Type |
Name |
Description |
object |
obj |
The object to compare this one with |
Returns
Type |
Description |
bool |
True if the specified value is an annual date which is equal to this one; false otherwise |
Overrides
GetHashCode()
Returns a hash code for this annual date.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public override int GetHashCode()
Returns
Type |
Description |
int |
A hash code for this annual date. |
Overrides
InYear(int)
Returns this annual date in a particular year, as a
LocalDate.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalDate InYear(int year)
Parameters
Type |
Name |
Description |
int |
year |
The year component of the required date. |
Returns
Type |
Description |
LocalDate |
A date in the given year, suitable for this annual date. |
Sample snippet
using NodaTime;
using System;
var annualDate = new AnnualDate(3, 12);
var localDate = annualDate.InYear(2013);
Console.WriteLine(localDate);
Output:
Tuesday, 12 March 2013
IsValidYear(int)
Checks whether the specified year forms a valid date with the month/day in this
value, without any truncation. This will always return true
except
for values representing February 29th, where the specified year is a non leap year.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public bool IsValidYear(int year)
Parameters
Type |
Name |
Description |
int |
year |
The year to test for validity |
Returns
Type |
Description |
bool |
true if the current value occurs within the given year;
false otherwise. |
Sample snippet
using NodaTime;
using System;
var leapDay = new AnnualDate(2, 29);
var leapYear = leapDay.IsValidYear(2020);
var nonLeapYear = leapDay.IsValidYear(2018);
Console.WriteLine(leapYear);
Console.WriteLine(nonLeapYear);
Output:
True
False
ToString()
Returns a
string that represents this instance.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public override string ToString()
Returns
Type |
Description |
string |
The value of the current instance in the default format pattern ("G"). |
Overrides
Formats the value of the current instance using the specified pattern.
Since 2.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string ToString(string? patternText, IFormatProvider? formatProvider)
Parameters
Type |
Name |
Description |
string |
patternText |
The string specifying the pattern to use,
or null to use the default format pattern ("G"). |
IFormatProvider |
formatProvider |
The 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 string containing the value of the current instance in the specified format. |
Operators
operator ==(AnnualDate, AnnualDate)
Compares two
AnnualDate values for equality.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator ==(AnnualDate lhs, AnnualDate rhs)
Parameters
Type |
Name |
Description |
AnnualDate |
lhs |
The first value to compare |
AnnualDate |
rhs |
The second value to compare |
Returns
Type |
Description |
bool |
True if the two dates are the same; false otherwise |
operator >(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is strictly later than the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator >(AnnualDate lhs, AnnualDate rhs)
Parameters
Type |
Name |
Description |
AnnualDate |
lhs |
First operand of the comparison |
AnnualDate |
rhs |
Second operand of the comparison |
Returns
Type |
Description |
bool |
true if the lhs is strictly later than rhs , false otherwise. |
operator >=(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is later than or equal to the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator >=(AnnualDate lhs, AnnualDate rhs)
Parameters
Type |
Name |
Description |
AnnualDate |
lhs |
First operand of the comparison |
AnnualDate |
rhs |
Second operand of the comparison |
Returns
Type |
Description |
bool |
true if the lhs is later than or equal to rhs , false otherwise. |
operator !=(AnnualDate, AnnualDate)
Compares two
AnnualDate values for inequality.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator !=(AnnualDate lhs, AnnualDate rhs)
Parameters
Type |
Name |
Description |
AnnualDate |
lhs |
The first value to compare |
AnnualDate |
rhs |
The second value to compare |
Returns
Type |
Description |
bool |
False if the two dates are the same and in the same calendar; true otherwise |
operator <(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is strictly earlier than the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator <(AnnualDate lhs, AnnualDate rhs)
Parameters
Type |
Name |
Description |
AnnualDate |
lhs |
First operand of the comparison |
AnnualDate |
rhs |
Second operand of the comparison |
Returns
Type |
Description |
bool |
true if the lhs is strictly earlier than rhs , false otherwise. |
Exceptions
Type |
Condition |
ArgumentException |
The calendar system of rhs is not the same
as the calendar of lhs . |
operator <=(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is earlier than or equal to the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static bool operator <=(AnnualDate lhs, AnnualDate rhs)
Parameters
Type |
Name |
Description |
AnnualDate |
lhs |
First operand of the comparison |
AnnualDate |
rhs |
Second operand of the comparison |
Returns
Type |
Description |
bool |
true if the lhs is earlier than or equal to rhs , false otherwise. |
Explicit Interface Implementations
IXmlSerializable.GetSchema()
This method is reserved and should not be used. When implementing the
IXmlSerializable
interface, you should return
null (
Nothing
in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the
XmlSchemaProviderAttribute to the class.
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
IXmlSerializable.ReadXml(XmlReader)
Generates an object from its XML representation.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type |
Name |
Description |
XmlReader |
reader |
The XmlReader stream from which the object is deserialized. |
IXmlSerializable.WriteXml(XmlWriter)
Converts an object into its XML representation.
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type |
Name |
Description |
XmlWriter |
writer |
The XmlWriter stream to which the object is serialized. |
Implements