MySQL 9.7.0
Source Code Documentation
Collaboration diagram for Mysys temporal utilities:

Files

file  my_temporal.h
 Server classes for temporal handling (DATE, TIME, DATETIME)
 
file  my_temporal.cc
 Implementation of low level date, time and datetime utilities.
 

Functions

bool Time_val::is_adjusted (uint32_t decimals) const
 
uint32_t Time_val::actual_decimals () const
 
void Time_val::adjust_fraction (uint32_t decimals, bool round)
 
bool Time_val::add (Time_val tv, bool subtract)
 Add a time value to another time value, or subtract it. More...
 
bool Time_val::add (Interval &iv, bool subtract)
 Add an interval to a time value, or subtract it. More...
 
static Time_val Time_val::strip_date (const MYSQL_TIME &mt)
 Creates a Time_val from a date_time by extracting only the time fields. More...
 
 Time_val::operator MYSQL_TIME () const
 Convert time value to the generalized temporal time format. More...
 
void Time_val::store_time (uint8_t *ptr, uint32_t dec) const
 Convert server time value to storage engine interface format. More...
 
static void Time_val::load_time (const uint8_t *ptr, uint32_t dec, Time_val *time)
 Convert from storage engine interface time format to server time value. More...
 
int64_t Time_val::to_int_rounded () const
 base100 representation without microsecond, but rounded '-12:34:56.999999' is returned as -123457 More...
 
int64_t Time_val::to_int_truncated () const
 base100 representation without microsecond, '-12:34:56.999999' is returned as -123456 More...
 
double Time_val::to_double () const
 base100 representation with microseconds, returned as double precision float More...
 
size_t Time_val::to_string (char *buffer, uint32_t dec) const
 
std::string Time_val::to_string () const
 
static int Date_val::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...
 
int Date_val::check_date (my_time_flags_t flags) const
 Check date for validity, according to calendar and validation flags. More...
 
static void Date_val::day_number_to_date (uint32_t daynr, uint32_t *year, uint32_t *month, uint32_t *day)
 Convert day number to date. More...
 
bool Date_val::add (Interval &iv, bool subtract)
 Add an interval to a date value, or subtract it. More...
 
void Date_val::set_last_day_of_month ()
 Adjust date to have last day of month. More...
 
static Date_val Date_val::strip_time (const MYSQL_TIME &mtime)
 Creates a Date_val from a date_time by extracting only the date fields. More...
 
 Date_val::operator MYSQL_TIME () const
 Convert date value to the generalized temporal time format. More...
 
 Date_val::operator Datetime_val () const
 Convert date value to a datetime value, where time component is 00:00:00. More...
 
int32_t Date_val::to_int () const
 
uint32_t Date_val::day_number () const
 
size_t Date_val::to_string (char *buffer) const
 
std::string Date_val::to_string () const
 

Variables

static const uint32_t divisors [] = {1000000, 100000, 10000, 1000, 100, 10}
 
static const uint32_t month_days []
 
static const uint32_t leap_days []
 
static const uint32_t sum_days []
 

Detailed Description

Function Documentation

◆ actual_decimals()

uint32_t Time_val::actual_decimals ( ) const
Returns
actual number of decimals in fraction

◆ add() [1/3]

bool Time_val::add ( Interval iv,
bool  subtract 
)

Add an interval to a time value, or subtract it.

Parameters
ivInterval to add or subtract
subtractIf true, subtract the time value, otherwise add it.
Returns
false if result is within valid time range, true otherwise.

◆ add() [2/3]

bool Date_val::add ( Interval iv,
bool  subtract 
)

Add an interval to a date value, or subtract it.

Parameters
ivInterval to add or subtract
subtractIf true, subtract the interval value, otherwise add it.
Returns
false if result is within valid date range, true otherwise.

◆ add() [3/3]

bool Time_val::add ( Time_val  tv,
bool  subtract 
)

Add a time value to another time value, or subtract it.

Parameters
tvTime value to add or subtract
subtractIf true, subtract the time value, otherwise add it.
Returns
false if result is within valid time range, true otherwise.

◆ adjust_fraction()

void Time_val::adjust_fraction ( uint32_t  decimals,
bool  round 
)

◆ check_date()

int Date_val::check_date ( my_time_flags_t  flags) const

Check date for validity, according to calendar and validation flags.

Parameters
flagsvalidation flags
Returns
= 0: date value is correct = MYSQL_TIME_WARN_ZERO_DATE date is invalid zero date = MYSQL_TIME_WARN_ZERO_IN_DATE date has invalid zero component = MYSQL_TIME_WARN_OUT_OF_RANGE out-of range day value

◆ day_number()

uint32_t Date_val::day_number ( ) const
Returns
day number of a date, January 1 of year 0 returns 1.

Date must have valid year, month and day values (month 0 and day 0 are invalid), but there is no other validity check (e.g February 31 is allowed).

◆ day_number_to_date()

void Date_val::day_number_to_date ( uint32_t  daynr,
uint32_t *  year,
uint32_t *  month,
uint32_t *  day 
)
staticprivate

Convert day number to date.

Convert a day number to a date.

Day number 1 is date 0000-01-01.

Parameters
daynrday number to convert
[out]yearyear of date, range is 0000 to 9999.
[out]monthmonth of date (note: January is 0, February is 1, etc)
[out]dayday of date, returned as a zero-based number

Day number 1 is returned as date 0000-01-01.

This function is called from mysqld's print_fatal_signal(). Do not make changes to this function that make that call unsafe.

◆ is_adjusted()

bool Time_val::is_adjusted ( uint32_t  decimals) const
Returns
true if value is adjusted to number of decimals in fraction

◆ load_time()

void Time_val::load_time ( const uint8_t *  ptr,
uint32_t  dec,
Time_val time 
)
static

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

Parameters
ptrThe pointer to read the value at.
decPrecision.
[out]timeReturned time value

◆ make_date()

int Date_val::make_date ( uint32_t  year,
uint32_t  month,
uint32_t  day,
my_time_flags_t  flags,
Date_val date 
)
static

Make date from year, month and day components, according to validation flags.

Parameters
yearyear component
monthmonth component
dayday component
flagsflags for validation
[out]dateconstructed date, if date is valid
Returns
= 0: values are valid <> 0: value, out of range, zero component, or zero date

◆ operator Datetime_val()

Date_val::operator Datetime_val ( ) const
explicit

Convert date value to a datetime value, where time component is 00:00:00.

◆ operator MYSQL_TIME() [1/2]

Time_val::operator MYSQL_TIME ( ) const
explicit

Convert time value to the generalized temporal time format.

◆ operator MYSQL_TIME() [2/2]

Date_val::operator MYSQL_TIME ( ) const
explicit

Convert date value to the generalized temporal time format.

◆ set_last_day_of_month()

void Date_val::set_last_day_of_month ( )

Adjust date to have last day of month.

Setting last day of month zero is not a valid operation.

◆ store_time()

void Time_val::store_time ( uint8_t *  ptr,
uint32_t  dec 
) const

Convert server time value to storage engine interface format.

Parameters
[out]ptrThe buffer to put value at.
decPrecision.

◆ strip_date()

Time_val Time_val::strip_date ( const MYSQL_TIME mt)
static

Creates a Time_val from a date_time by extracting only the time fields.

◆ strip_time()

Date_val Date_val::strip_time ( const MYSQL_TIME mtime)
static

Creates a Date_val from a date_time by extracting only the date fields.

◆ to_double()

double Time_val::to_double ( ) const

base100 representation with microseconds, returned as double precision float

◆ to_int()

int32_t Date_val::to_int ( ) const
Returns
base100 representation, '2025-02-29' is returned as 20250229

◆ to_int_rounded()

int64_t Time_val::to_int_rounded ( ) const

base100 representation without microsecond, but rounded '-12:34:56.999999' is returned as -123457

◆ to_int_truncated()

int64_t Time_val::to_int_truncated ( ) const

base100 representation without microsecond, '-12:34:56.999999' is returned as -123456

◆ to_string() [1/4]

std::string Time_val::to_string ( ) const

◆ to_string() [2/4]

std::string Date_val::to_string ( ) const

◆ to_string() [3/4]

size_t Date_val::to_string ( char *  buffer) const

◆ to_string() [4/4]

size_t Time_val::to_string ( char *  buffer,
uint32_t  dec 
) const

Variable Documentation

◆ divisors

const uint32_t divisors[] = {1000000, 100000, 10000, 1000, 100, 10}
static

◆ leap_days

const uint32_t leap_days[]
static
Initial value:
=
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

◆ month_days

const uint32_t month_days[]
static
Initial value:
=
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

◆ sum_days

const uint32_t sum_days[]
static
Initial value:
=
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}