MySQL 9.7.0
Source Code Documentation
Date_val Class Reference

Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31. More...

#include <my_temporal.h>

Public Member Functions

 Date_val ()=default
 
 Date_val (uint32_t year, uint32_t month, uint32_t day)
 
 Date_val (const MYSQL_TIME &mtime)
 
 Date_val (uint32_t day_number)
 
uint32_t year () const
 
uint32_t month () const
 
uint32_t day () const
 
bool is_zero_date () const
 
int compare (const Date_val arg) const
 
int32_t for_comparison () const
 
int check_date (my_time_flags_t flags) const
 Check date for validity, according to calendar and validation flags. More...
 
uint32_t day_number () const
 
void set_zero ()
 Set zero date. More...
 
bool operator== (const Date_val rhs) const
 
bool operator< (const Date_val rhs) const
 
bool add (Interval &iv, bool subtract)
 Add an interval to a date value, or subtract it. More...
 
void set_last_day_of_month ()
 Adjust date to have last day of month. More...
 
 operator MYSQL_TIME () const
 Convert date value to the generalized temporal time format. More...
 
 operator Datetime_val () const
 Convert date value to a datetime value, where time component is 00:00:00. More...
 
int32_t to_int () const
 
double to_double () const
 
void store_date (uint8_t *ptr) const
 Convert server date value to storage engine interface format. More...
 
size_t to_string (char *buffer) const
 
std::string to_string () const
 

Static Public Member Functions

static uint32_t last_day_number ()
 
static int make_date (uint32_t year, uint32_t month, uint32_t day, my_time_flags_t flags, Date_val *date)
 Make date from year, month and day components, according to validation flags. More...
 
static Date_val strip_time (const MYSQL_TIME &mtime)
 Creates a Date_val from a date_time by extracting only the date fields. More...
 
static void load_date (const uint8_t *ptr, Date_val *date)
 Convert from storage engine interface date format to server date value. More...
 

Private Member Functions

bool is_valid () const
 Internal date validity check. Zero date, invalid calendar dates are OK. More...
 

Static Private Member Functions

static bool is_leap_year (uint32_t year)
 
static void day_number_to_date (uint32_t daynr, uint32_t *year, uint32_t *month, uint32_t *day)
 Convert day number to date. More...
 

Private Attributes

uint32_t m_value = 0xffffffff
 A DATE value is stored in bit coded fields in a 32 bit unsigned value. More...
 

Static Private Attributes

static constexpr const uint32_t DATE_MAX_YEAR = 9999
 
static constexpr const uint32_t DATE_MAX_MONTH = 12
 
static constexpr const uint32_t DATE_MAX_DAY = 31
 
static constexpr const uint32_t DATE_DAYS_IN_YEAR = 365
 
static constexpr const uint32_t DATE_DAYS_IN_LEAP = 366
 
static constexpr const uint32_t DATE_BITS_YEAR = 0x007FFE00
 
static constexpr const uint32_t DATE_BITS_MONTH = 0x000001E0
 
static constexpr const uint32_t DATE_BITS_DAY = 0x0000001F
 
static constexpr const int DATE_SHIFT_YEAR = 9
 
static constexpr const int DATE_SHIFT_MONTH = 5
 
static constexpr const uint32_t DATE_LAST_DAY = 3652424
 

Detailed Description

Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.

In addition, dates with zero values for date and month are supported, for use with certain relaxed SQL modes. Furthermore, a date object may accept invalid dates, but only with day values not greater than 31 and year and month values must be in the supported range.

Date_val implements a proleptic Gregorian calendar, where the rules for leap years are extended back to year 0, except that year 0 itself is not a leap year, even though it matches the common rule. The latter is for compatibility with older implementations.

The SQL standard is defined for years in range from 0 to 9999, thus the range that MySQL supports is standard compliant.

The class has constructors for creating date values from date components (year, month and day), and from MYSQL_TIME objects.

Constructor & Destructor Documentation

◆ Date_val() [1/4]

Date_val::Date_val ( )
default

◆ Date_val() [2/4]

Date_val::Date_val ( uint32_t  year,
uint32_t  month,
uint32_t  day 
)
inline

◆ Date_val() [3/4]

Date_val::Date_val ( const MYSQL_TIME mtime)
inlineexplicit

◆ Date_val() [4/4]

Date_val::Date_val ( uint32_t  day_number)
inlineexplicit

Member Function Documentation

◆ compare()

int Date_val::compare ( const Date_val  arg) const
inline
Returns
whether the value is less than, equal to or greater than the argument value.

◆ day()

uint32_t Date_val::day ( ) const
inline

◆ for_comparison()

int32_t Date_val::for_comparison ( ) const
inline
Returns
an integer value for comparison purposes

◆ is_leap_year()

static bool Date_val::is_leap_year ( uint32_t  year)
inlinestaticprivate
Returns
true if year is a leap year, false otherwise.
Note
In this implementation, year zero is not a leap year, even though it is so in ISO 8601.

◆ is_valid()

bool Date_val::is_valid ( ) const
inlineprivate

Internal date validity check. Zero date, invalid calendar dates are OK.

◆ is_zero_date()

bool Date_val::is_zero_date ( ) const
inline
Returns
true if date is the zero date (0000-00-00)

◆ last_day_number()

static uint32_t Date_val::last_day_number ( )
inlinestatic
Returns
last day number in range

◆ load_date()

static void Date_val::load_date ( const uint8_t *  ptr,
Date_val date 
)
inlinestatic

Convert from storage engine interface date format to server date value.

Parameters
ptrThe pointer to read the value at.
[out]dateReturned date value

◆ month()

uint32_t Date_val::month ( ) const
inline

◆ operator<()

bool Date_val::operator< ( const Date_val  rhs) const
inline

◆ operator==()

bool Date_val::operator== ( const Date_val  rhs) const
inline

◆ set_zero()

void Date_val::set_zero ( )
inline

Set zero date.

◆ store_date()

void Date_val::store_date ( uint8_t *  ptr) const
inline

Convert server date value to storage engine interface format.

Parameters
[out]ptrThe buffer to put value at.

◆ to_double()

double Date_val::to_double ( ) const
inline
Returns
base100 representation, as double precision float

◆ year()

uint32_t Date_val::year ( ) const
inline

Member Data Documentation

◆ DATE_BITS_DAY

constexpr const uint32_t Date_val::DATE_BITS_DAY = 0x0000001F
staticconstexprprivate

◆ DATE_BITS_MONTH

constexpr const uint32_t Date_val::DATE_BITS_MONTH = 0x000001E0
staticconstexprprivate

◆ DATE_BITS_YEAR

constexpr const uint32_t Date_val::DATE_BITS_YEAR = 0x007FFE00
staticconstexprprivate

◆ DATE_DAYS_IN_LEAP

constexpr const uint32_t Date_val::DATE_DAYS_IN_LEAP = 366
staticconstexprprivate

◆ DATE_DAYS_IN_YEAR

constexpr const uint32_t Date_val::DATE_DAYS_IN_YEAR = 365
staticconstexprprivate

◆ DATE_LAST_DAY

constexpr const uint32_t Date_val::DATE_LAST_DAY = 3652424
staticconstexprprivate

◆ DATE_MAX_DAY

constexpr const uint32_t Date_val::DATE_MAX_DAY = 31
staticconstexprprivate

◆ DATE_MAX_MONTH

constexpr const uint32_t Date_val::DATE_MAX_MONTH = 12
staticconstexprprivate

◆ DATE_MAX_YEAR

constexpr const uint32_t Date_val::DATE_MAX_YEAR = 9999
staticconstexprprivate

◆ DATE_SHIFT_MONTH

constexpr const int Date_val::DATE_SHIFT_MONTH = 5
staticconstexprprivate

◆ DATE_SHIFT_YEAR

constexpr const int Date_val::DATE_SHIFT_YEAR = 9
staticconstexprprivate

◆ m_value

uint32_t Date_val::m_value = 0xffffffff
private

A DATE value is stored in bit coded fields in a 32 bit unsigned value.

The format is efficient for comparison, storage, retrieval and movement. Values can be compared using regular unsigned integer logic. The initial value is invalid, thus a separate initialization is required for this member. Format: Bits 0- 4: day (0-31) Bits 5- 8: month (0-12) Bits 9-22: year (0-9999)


The documentation for this class was generated from the following files: