libsgfc++ 2.0.1
A C++ library that uses SGFC to read and write SGF (Smart Game Format) data.
|
The SgfcDate struct is a simple type that can hold one of the 1-n decomposed date values of an SgfcPropertyType::DT property value. More...
#include <SgfcDate.h>
Public Member Functions | |
bool | IsPartialDate () const |
Returns true if the date is a partial date, i.e. if one or more of the date parts has value 0. Returns false if the date is not a partial date, i.e. if all date parts have values that are not equal than 0. | |
bool | IsValidCalendarDate () const |
Returns true if the date is a valid calendar date. Returns false if the date is not a valid calendar date. Partial dates are not valid calendar dates. | |
bool | IsValidSgfDate () const |
Returns true if the date is a valid SGF date, i.e. one that can be passed to ToPropertyValue() for composing a property value for SgfcPropertyType::DT). Returns false if the date is not a valid SGF date, i.e. the date cannot be passed to ToPropertyValue(). | |
bool | operator== (const SgfcDate &other) const |
Returns true if all date parts are the same for the current SgfcDate object and for other. Returns false if any of the date parts are different. | |
bool | operator!= (const SgfcDate &other) const |
Returns true if any of the date parts are different for the current SgfcDate object and for other. Returns false if all date parts are the same. | |
Static Public Member Functions | |
static std::vector< SgfcDate > | FromPropertyValue (const SgfcSimpleText &propertyValue) |
Decomposes the content of propertyValue into a collection of distinct SgfcDate values. The order of the collection matches the order in which values appear in propertyValue. The collection is empty if decomposition fails. | |
static SgfcSimpleText | ToPropertyValue (const std::vector< SgfcDate > &gameDates) |
Composes a property value for SgfcPropertyType::DT from the collection of SgfcDate values in gameDates. | |
Public Attributes | |
SgfcNumber | Year = 0 |
The date's year part. Valid values are in the range from 0-9999. The default is 0. | |
SgfcNumber | Month = 0 |
The date's month part. Valid values are in the range from 0-12. The value 0 denotes that the date has no month part. The default is 0. | |
SgfcNumber | Day = 0 |
The date's day part. Valid values are based on the month part and, if the month is February, the year part (for leap years). The value 0 denotes that the date has no day part. The default is 0. | |
The SgfcDate struct is a simple type that can hold one of the 1-n decomposed date values of an SgfcPropertyType::DT property value.
|
static |
Decomposes the content of propertyValue into a collection of distinct SgfcDate values. The order of the collection matches the order in which values appear in propertyValue. The collection is empty if decomposition fails.
Decomposition fails if the SGF standard's specification of the mandatory structure of an SgfcPropertyType::DT property value is not met. Decomposition also fails if any of the dates encoded in propertyValue is not valid, i.e. its IsValidSgfDate() method returns false. As a corollary if decomposition succeeds the IsValidSgfDate() method of all date objects in the returned collection returns true.
See the SGF standard specification for the mandatory structure of an SgfcPropertyType::DT property value.
bool LibSgfcPlusPlus::SgfcDate::IsValidCalendarDate | ( | ) | const |
Returns true if the date is a valid calendar date. Returns false if the date is not a valid calendar date. Partial dates are not valid calendar dates.
This method calculates leap years (in which 29 February is valid) according to the Gregorian calendar.
bool LibSgfcPlusPlus::SgfcDate::IsValidSgfDate | ( | ) | const |
Returns true if the date is a valid SGF date, i.e. one that can be passed to ToPropertyValue() for composing a property value for SgfcPropertyType::DT). Returns false if the date is not a valid SGF date, i.e. the date cannot be passed to ToPropertyValue().
A date is a valid SGF date if IsCalendarDate() returns true. A date is also a valid SGF date if IsPartialDate() returns true and all of the following is true:
Examples:
Partial dates and validity of the day part:
This method calculates leap years (in which 29 February is valid) according to the Gregorian calendar.
|
static |
Composes a property value for SgfcPropertyType::DT from the collection of SgfcDate values in gameDates.
gameDates is evaluated from beginning to end in order to compose the property value from left to right. As recommended by the SGF standard shortcuts are built from the dates in gameDates wherever possible. A date's IsValidSgfDate() method must return true, otherwise the compose operation fails and this method returns SgfcConstants::NoneValueString.
gameDates may contain dates that already are shortcuts, to support the case that the caller wants to do the shortcutting herself. The compose operation does not attempt to generate shortcuts from dates that already are shortcuts. Dates that already are shortcuts are validated differently, but the outcome of a failed validation is the same: The compose operation fails and this method returns SgfcConstants::NoneValueString.
Validation rules for dates that already are shortcut dates:
SgfcNumber LibSgfcPlusPlus::SgfcDate::Day = 0 |
The date's day part. Valid values are based on the month part and, if the month is February, the year part (for leap years). The value 0 denotes that the date has no day part. The default is 0.
SgfcNumber LibSgfcPlusPlus::SgfcDate::Month = 0 |
The date's month part. Valid values are in the range from 0-12. The value 0 denotes that the date has no month part. The default is 0.
SgfcNumber LibSgfcPlusPlus::SgfcDate::Year = 0 |
The date's year part. Valid values are in the range from 0-9999. The default is 0.