Google Cloud Spanner v1 API - Struct SpannerDate (4.1.0)

public readonly struct SpannerDate : IEquatable<SpannerDate>, IComparable<SpannerDate>, IComparable

Reference documentation and code samples for the Google Cloud Spanner v1 API struct SpannerDate.

The SpannerDate type represents a logical calendar date, independent of time zone. Represents dates with values ranging from January 1, 0001 A.D through December 31, 9999 A.D. in the Gregorian calendar.

Namespace

Google.Cloud.Spanner.V1

Assembly

Google.Cloud.Spanner.V1.dll

Constructors

SpannerDate(Int32, Int32, Int32)

public SpannerDate(int year, int month, int day)

Initializes a new instance of the SpannerDate structure to the specified year, month, and day in the Gregorian calendar.

Parameters
NameDescription
yearSystem.Int32

The year (in the range 1-9999 inclusive).

monthSystem.Int32

The month (in the range 1-12 inclusive).

daySystem.Int32

The day (1 through the number of days in month).

Properties

Day

public readonly int Day { get; }

Gets the day of the month of the date represented by this instance.

Property Value
TypeDescription
System.Int32

MaxDate

public static readonly SpannerDate MaxDate { get; }

Gets the latest possible date that can be represented by SpannerDate.

Property Value
TypeDescription
SpannerDate

MinDate

public static readonly SpannerDate MinDate { get; }

Gets the earliest possible date that can be represented by SpannerDate.

Property Value
TypeDescription
SpannerDate

Month

public readonly int Month { get; }

Gets the month component of the date represented by this instance.

Property Value
TypeDescription
System.Int32

Year

public readonly int Year { get; }

Gets the year component of the date represented by this instance.

Property Value
TypeDescription
System.Int32

Methods

AddDays(Int32)

public readonly SpannerDate AddDays(int days)

Returns a new instance of the SpannerDate that adds the specified number of days to the value of this instance.

Parameter
NameDescription
daysSystem.Int32

The number of days to be added.

Returns
TypeDescription
SpannerDate

A new instance of the SpannerDate value that is the sum of the date represented by this instance and the number of days represented by days.

CompareTo(SpannerDate)

public readonly int CompareTo(SpannerDate other)
Parameter
NameDescription
otherSpannerDate
Returns
TypeDescription
System.Int32

FromDateTime(DateTime)

public static SpannerDate FromDateTime(DateTime dateTime)

Returns a SpannerDate instance that is set to the date part of the specified DateTime.

Parameter
NameDescription
dateTimeDateTime

The DateTime value.

Returns
TypeDescription
SpannerDate

The SpannerDate instance

GetHashCode()

public override readonly int GetHashCode()
Returns
TypeDescription
System.Int32
Overrides

Parse(String)

public static SpannerDate Parse(string text)

Parses a textual representation in yyyy-MM-dd format as a SpannerDate.

Parameter
NameDescription
textString

The text to parse. Must not be null. Must be in yyyy-MM-dd format only.

Returns
TypeDescription
SpannerDate

The parsed value.

Remarks

text must be a representation of a date value in yyyy-MM-dd format which can be represented by SpannerDate.

Exceptions
TypeDescription
FormatException

The value could not be parsed as a SpannerDate.

ToDateTime()

public readonly DateTime ToDateTime()

Converts the value of this SpannerDate instance to the DateTime of kind Unspecified.

Returns
TypeDescription
DateTime

The DateTime value.

ToString()

public override readonly string ToString()

Returns the ISO 8601 representation (yyyy-MM-dd) of the date represented by this instance.

Returns
TypeDescription
String

The ISO 8601 string representation of the date represented by this instance.

Overrides

TryParse(String, out SpannerDate)

public static bool TryParse(string text, out SpannerDate value)

Attempts to parse a textual representation of date in yyyy-MM-dd format as SpannerDate.

Parameters
NameDescription
textString

The text to parse. Must not be null. Must be in yyyy-MM-dd format only.

valueSpannerDate

The parsed value, or 0 on failure.

Returns
TypeDescription
Boolean

true if text was parsed successfully; false otherwise.

Remarks

See Parse(String) for format details. This method will return true if and only if Parse(String) would return without an exception.

Operators

Equality(SpannerDate, SpannerDate)

public static bool operator ==(SpannerDate lhs, SpannerDate rhs)

Returns a value that indicates whether the values of two SpannerDate objects are equal.

Parameters
NameDescription
lhsSpannerDate

The first value to compare.

rhsSpannerDate

The second value to compare.

Returns
TypeDescription
Boolean

true if the two arguments are equal; false otherwise.

Explicit(SpannerDate to DateTime)

public static explicit operator DateTime(SpannerDate value)

Performs an explicit conversion from SpannerDate to DateTime.

Parameter
NameDescription
valueSpannerDate

The SpannerDate value.

Returns
TypeDescription
DateTime

The result of the conversion.

Explicit(DateTime to SpannerDate)

public static explicit operator SpannerDate(DateTime value)

Performs an explicit conversion from DateTime to SpannerDate.

Parameter
NameDescription
valueDateTime

The DateTime value.

Returns
TypeDescription
SpannerDate

The result of the conversion.

GreaterThan(SpannerDate, SpannerDate)

public static bool operator>(SpannerDate lhs, SpannerDate rhs)

Returns a value that indicates whether a SpannerDate value is greater than another SpannerDate.

Parameters
NameDescription
lhsSpannerDate

The value to compare with rhs.

rhsSpannerDate

The value to compare with lhs.

Returns
TypeDescription
Boolean

true if lhs is greater than rhs; otherwise, false.

GreaterThanOrEqual(SpannerDate, SpannerDate)

public static bool operator >=(SpannerDate lhs, SpannerDate rhs)

Returns a value that indicates whether a SpannerDate value is greater than or equal to another SpannerDate.

Parameters
NameDescription
lhsSpannerDate

The value to compare with rhs.

rhsSpannerDate

The value to compare with lhs.

Returns
TypeDescription
Boolean

true if lhs is greater than or equal to rhs; otherwise, false.

Inequality(SpannerDate, SpannerDate)

public static bool operator !=(SpannerDate lhs, SpannerDate rhs)

Returns a value that indicates whether the two SpannerDate objects have unequal values.

Parameters
NameDescription
lhsSpannerDate

The first value to compare.

rhsSpannerDate

The second value to compare.

Returns
TypeDescription
Boolean

false if the two arguments are equal; true otherwise.

LessThan(SpannerDate, SpannerDate)

public static bool operator <(SpannerDate lhs, SpannerDate rhs)

Returns a value that indicates whether a SpannerDate value is less than another SpannerDate.

Parameters
NameDescription
lhsSpannerDate

The value to compare with rhs.

rhsSpannerDate

The value to compare with lhs.

Returns
TypeDescription
Boolean

true if lhs is less than rhs; otherwise, false.

LessThanOrEqual(SpannerDate, SpannerDate)

public static bool operator <=(SpannerDate lhs, SpannerDate rhs)

Returns a value that indicates whether a SpannerDate value is less than or equal to another SpannerDate.

Parameters
NameDescription
lhsSpannerDate

The value to compare with rhs.

rhsSpannerDate

The value to compare with lhs.

Returns
TypeDescription
Boolean

true if lhs is less than or equal to rhs; otherwise, false.

Explicit Interface Implementations

IComparable.CompareTo(Object)

readonly int IComparable.CompareTo(object obj)

Implementation of CompareTo(Object) to compare two SpannerDate values.

Parameter
NameDescription
objSystem.Object

The object to compare this value with.

Returns
TypeDescription
System.Int32

The result of comparing this value with obj. obj is null, this method returns a value greater than 0.

Remarks

This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.

Exceptions
TypeDescription
ArgumentException

obj is non-null but does not refer to an instance of SpannerDate.