Struct SwiftDate

Namespace
Subsembly.Swift
Assembly
Subsembly.Sepa.dll

Represents a special SWIFT date with support for virtual dates such as February, 30th and which can be all zeroes.

public struct SwiftDate : IComparable
Implements
Inherited Members

Remarks

In a null date all components, the Year, the Month, and the Day are zero. The method IsNull can be used to easily check for a null date. The method SetNull() can be used to set a date to null. A newly constructed und uninitialised instance of the SwiftDate structure contains all zeroes which is represents the null date.

Depending on the chosen SWIFT representation not all components of the date may be given. For example the format SwiftDateMMDD does not have a Year component. In such cases, any missing components will simply be zero.

According to SWIFT, any two digit year representations YY are always expanded to a full four digit year using the following rule: If YY > 79 then Year = 19YY, else Year = 20YY.

Constructors

SwiftDate(DateTime)

Constructs a SwiftDate instance from the given DateTime instance.

public SwiftDate(DateTime aDateTime)

Parameters

aDateTime DateTime

A System.DateTime instance that provides the date for the new SwiftDate instance.

Remarks

If the given DateTime value is DateTime.MinValue, then the new SwiftDate will be a logical null value.

SwiftDate(int)

public SwiftDate(int nPackedDate)

Parameters

nPackedDate int

SwiftDate(int, int, int)

Constructs a SwiftDate instance with a valid given date.

public SwiftDate(int nYear, int nMonth, int nDay)

Parameters

nYear int

Year in the range from 1 through 9999.

nMonth int

Month in the range from 1 through 12.

nDay int

Day of month in the range from 1 through 31, regardless of the month. A date specification such as 31st of April is allowed.

Exceptions

ArgumentOutOfRangeException

If any of the arguments is outside the allowed range, then an ArgumentOutOfRangeException will be thrown.

Fields

MaxDate

The maximum date is 31.12.9999.

public static readonly SwiftDate MaxDate

Field Value

SwiftDate

MinDate

The minimum date is 01.01.0001.

public static readonly SwiftDate MinDate

Field Value

SwiftDate

NullDate

Represents a null date.

public static readonly SwiftDate NullDate

Field Value

SwiftDate

Properties

Day

The day in month of this date.

public int Day { get; set; }

Property Value

int

This allowed range of this property is 1 through 31, regardless of the month. The value zero is returned for a logical null date, but cannot be set.

Exceptions

ArgumentOutOfRangeException

An attempt to set the month to a value outside of the allowed range 1 through 31 will cause an ArgumentOutOfRangeException to be thrown.

IsNull

Indicates whether this SwiftDate instance is logically null.

public bool IsNull { get; }

Property Value

bool

Month

The month of this date.

public int Month { get; set; }

Property Value

int

This allowed range of this property is 1 through 12. The value zero is returned for a logical null date, but cannot be set.

Exceptions

ArgumentOutOfRangeException

An attempt to set the month to a value outside of the allowed range 1 through 12 will cause an ArgumentOutOfRangeException to be thrown.

Now

A new SwiftDate for the current date.

public static SwiftDate Now { get; }

Property Value

SwiftDate

PackedDate

public int PackedDate { get; }

Property Value

int

Year

The year of this date.

public int Year { get; set; }

Property Value

int

This valid range of this property is 1 through 9999. The value zero is returned for a logical null date, but cannot be set.

Exceptions

ArgumentOutOfRangeException

An attempt to set the year to a value outside of the allowed range 1 through 9999 will cause an ArgumentOutOfRangeException to be thrown.

Methods

AddDays(int)

Safely add or subtract a number of days to this date.

public SwiftDate AddDays(int nDays)

Parameters

nDays int

Number of days to add. If negative, then the number of days that is subtracted.

Returns

SwiftDate

Remarks

If adding or subtract the days would result in a date exeeding MaxDate or MinDate, then this method just returns MaxDate or MinDate and does not throw an exception.

CompareTo(object)

Implements IComparable.CompareTo.

public int CompareTo(object obj)

Parameters

obj object

Other SwiftDate to compare to.

Returns

int

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Parse(string)

Converts a string in the format YYYYMMDD to a SwiftDate.

public static SwiftDate Parse(string sStringDate)

Parameters

sStringDate string

Returns

SwiftDate

Remarks

This is an overloaded convenience method that internally just calls Parse(string, SwiftDateFormat) requesting the YYYYMMDD format.

Parse(string, SwiftDateFormat)

Parses a string date according to the specified format.

public static SwiftDate Parse(string sStringDate, SwiftDateFormat nFormat)

Parameters

sStringDate string

Date to be parsed according to the specified format.

nFormat SwiftDateFormat

Date format that the given string should have.

Returns

SwiftDate

Returns a new instance of the SwiftDate class that is initialised with the parsed date. If the parameter sStringDate is null or an empty string, then NullDate is returned.

Remarks

If a format with only a two digit year is parsed, then the century is determined according to SWIFT rules, i.e. if YY > 79 then century is 1900, otherwise the century is 2000.

If a partial date format, e.g. MMDD or YYMM is parsed, then any unspecified date component will be zero.

In any format the special case of an all zero date is accepted and will produce a NullDate result.

Exceptions

FormatException

If the given string is not in the specified format, or the month or the day are outside of the allowed range, then a FormatException is thrown.

ArgumentException

The parameter nFormat did specify an unknown format value.

SetNull()

Set this date to a logical null value.

public void SetNull()

ToDateTime()

Attempts to convert this SwiftDate into a System.DateTime value.

public DateTime ToDateTime()

Returns

DateTime

System.DateTime value that is the same as this SwiftDate. The time portion of that value is all zero (midnight). A null date is returned as DateTime.MinValue, a MaxDate is returned as DateTime.MaxValue.

Remarks

Not all dates that can be represented in a SwiftDate can be converted correctly into a System.DateTime value. In particular, a null date or a virtual date cannot be converted. Thus virtual dates will be converted to the last real day of the month. A null date will return DateTime.MinValue.

See Also

ToDateTime(SwiftTime)

Attempts to convert this SwiftDate and SwiftTime into a combined System.DateTime value.

public DateTime ToDateTime(SwiftTime tTime)

Parameters

tTime SwiftTime

The time of the day that shall be contained in the resulting DateTime. May be NullTime.

Returns

DateTime
See Also

ToString()

Converts this date to a string in the format YYYYMMDD.

public override string ToString()

Returns

string

Returns the converted date.

Remarks

This is an overloaded convenience method that internally just calls ToString(SwiftDateFormat) requesting the YYYYMMDD format.

ToString(SwiftDateFormat)

Converts this date to a string representation in the format specified.

public string ToString(SwiftDateFormat nDateFormat)

Parameters

nDateFormat SwiftDateFormat

Selects the format to be used for the generated date string.

Returns

string

Returns the converted date.

TryParse(string)

public static SwiftDate TryParse(string sStringDate)

Parameters

sStringDate string

Returns

SwiftDate

TryParse(string, SwiftDateFormat)

Tries to parse the given string as a date in the requested format.

public static SwiftDate TryParse(string sStringDate, SwiftDateFormat nFormat)

Parameters

sStringDate string
nFormat SwiftDateFormat

Returns

SwiftDate

If parsing fails, this method does not throw an exception, but rather returns NullDate.

See Also

Operators

operator ==(SwiftDate, SwiftDate)

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

Parameters

lhs SwiftDate
rhs SwiftDate

Returns

bool

operator >(SwiftDate, SwiftDate)

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

Parameters

lhs SwiftDate
rhs SwiftDate

Returns

bool

operator >=(SwiftDate, SwiftDate)

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

Parameters

lhs SwiftDate
rhs SwiftDate

Returns

bool

operator !=(SwiftDate, SwiftDate)

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

Parameters

lhs SwiftDate
rhs SwiftDate

Returns

bool

operator <(SwiftDate, SwiftDate)

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

Parameters

lhs SwiftDate
rhs SwiftDate

Returns

bool

operator <=(SwiftDate, SwiftDate)

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

Parameters

lhs SwiftDate
rhs SwiftDate

Returns

bool