MySQL  8.0.17
Source Code Documentation

Interface for low level time utilities. More...

#include "my_config.h"
#include <assert.h>
#include <cstddef>
#include <cstdint>
#include <limits>
#include "mysql_time.h"

Go to the source code of this file.

Classes

struct  MYSQL_TIME_STATUS
 Structure to return status from str_to_datetime(), str_to_time(), number_to_datetime(), number_to_time() More...
 
struct  Interval
 Struct representing a duration. More...
 
enum  interval_type {
  INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK,
  INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND,
  INTERVAL_MICROSECOND, INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE,
  INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND,
  INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND, INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND,
  INTERVAL_LAST
}
 Available interval types used in any statement. More...
 
using my_time_t = [] long int
 Portable time_t replacement. More...
 
using my_time_flags_t = unsigned int
 Flags to str_to_datetime and number_to_datetime. More...
 
constexpr const my_time_t MY_TIME_T_MAX = std::numeric_limits<my_time_t>::max()
 
constexpr const my_time_t MY_TIME_T_MIN = std::numeric_limits<my_time_t>::min()
 
constexpr const int TIMESTAMP_MAX_YEAR = 2038
 Time handling defaults. More...
 
constexpr const int YY_PART_YEAR = 70
 Two-digit years < this are 20XX; >= this are 19XX. More...
 
constexpr const int TIMESTAMP_MIN_YEAR = (1900 + YY_PART_YEAR - 1)
 
constexpr const int TIMESTAMP_MAX_VALUE
 
constexpr const int TIMESTAMP_MIN_VALUE = 1
 
constexpr const my_time_flags_t TIME_FUZZY_DATE = 1
 Allow zero day and zero month. More...
 
constexpr const my_time_flags_t TIME_DATETIME_ONLY = 2
 Only allow full datetimes. More...
 
constexpr const my_time_flags_t TIME_FRAC_TRUNCATE = 4
 
constexpr const my_time_flags_t TIME_NO_DATE_FRAC_WARN = 8
 
constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE = 16
 Don't allow zero day or zero month. More...
 
constexpr const my_time_flags_t TIME_NO_ZERO_DATE = 32
 Don't allow 0000-00-00 date. More...
 
constexpr const my_time_flags_t TIME_INVALID_DATES = 64
 Allow 2000-02-31. More...
 
constexpr const my_time_flags_t TIME_STRICT_COLON = 128
 Allow only HH:MM:SS or MM:SS time formats. More...
 
constexpr const int MYSQL_TIME_WARN_TRUNCATED = 1
 Conversion warnings. More...
 
constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE = 2
 
constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP = 4
 
constexpr const int MYSQL_TIME_WARN_ZERO_DATE = 8
 
constexpr const int MYSQL_TIME_NOTE_TRUNCATED = 16
 
constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE = 32
 
constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW = 64
 
constexpr const long int SECONDS_IN_24H = 86400L
 Usefull constants. More...
 
constexpr const int TIME_MAX_HOUR = 838
 Limits for the TIME data type. More...
 
constexpr const int TIME_MAX_MINUTE = 59
 
constexpr const int TIME_MAX_SECOND = 59
 
constexpr const int TIME_MAX_VALUE
 
Note that this MUST be a signed type, as we use the unary - operator on it. More...
 
constexpr const int TIME_MAX_VALUE_SECONDS
 
constexpr const int DATETIME_MAX_DECIMALS = 6
 
constexpr const unsigned int WEEK_MONDAY_FIRST = 1
 Flags for calc_week() function. More...
 
constexpr const unsigned int WEEK_YEAR = 2
 
constexpr const unsigned int WEEK_FIRST_WEEKDAY = 4
 
constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH = 30
 Required buffer length for my_time_to_str, my_date_to_str, my_datetime_to_str and TIME_to_string functions. More...
 
void my_init_time ()
 Prepare offset of system time zone from UTC for my_system_gmt_sec() func. More...
 
long calc_daynr (unsigned int year, unsigned int month, unsigned int day)
 Calculate nr of day since year 0 in new date-system (from 1615). More...
 
unsigned int calc_days_in_year (unsigned int year)
 Calc days in one year. More...
 
unsigned int year_2000_handling (unsigned int year)
 Handle 2 digit year conversions. More...
 
void get_date_from_daynr (long daynr, unsigned int *year, unsigned int *month, unsigned int *day)
 Change a daynr to year, month and day. More...
 
int calc_weekday (long daynr, bool sunday_first_day_of_week)
 Calc weekday from daynr. More...
 
bool valid_period (long long int period)
 
unsigned long int convert_period_to_month (unsigned long int period)
 
unsigned long int convert_month_to_period (unsigned long int month)
 
bool is_time_t_valid_for_timestamp (time_t x)
 Check for valid times only if the range of time_t is greater than the range of my_time_t. More...
 
unsigned int calc_week (const MYSQL_TIME &l_time, unsigned int week_behaviour, unsigned int *year)
 Calculate the week number from a MYSQL_TIME value. More...
 
bool check_date (const MYSQL_TIME &ltime, bool not_zero_date, my_time_flags_t flags, int *was_cut)
 Check datetime value for validity according to flags. More...
 
bool str_to_datetime (const char *str, std::size_t length, MYSQL_TIME *l_time, my_time_flags_t flags, MYSQL_TIME_STATUS *status)
 Convert a timestamp string to a MYSQL_TIME value. More...
 
long long int number_to_datetime (long long int nr, MYSQL_TIME *time_res, my_time_flags_t flags, int *was_cut)
 Convert datetime value specified as number to broken-down TIME representation and form value of DATETIME type as side-effect. More...
 
bool number_to_time (long long int nr, MYSQL_TIME *ltime, int *warnings)
 Convert number to TIME. More...
 
unsigned long long int TIME_to_ulonglong_datetime (const MYSQL_TIME &my_time)
 Convert time value to integer in YYYYMMDDHHMMSS. More...
 
unsigned long long int TIME_to_ulonglong_date (const MYSQL_TIME &my_time)
 Convert MYSQL_TIME value to integer in YYYYMMDD format. More...
 
unsigned long long int TIME_to_ulonglong_time (const MYSQL_TIME &my_time)
 Convert MYSQL_TIME value to integer in HHMMSS format. More...
 
unsigned long long int TIME_to_ulonglong (const MYSQL_TIME &my_time)
 Convert struct MYSQL_TIME (date and time split into year/month/day/hour/... More...
 
unsigned long long int TIME_to_ulonglong_datetime_round (const MYSQL_TIME &my_time, int *warnings)
 Round MYSQL_TIME datetime value and convert to ulonglong representation. More...
 
unsigned long long int TIME_to_ulonglong_time_round (const MYSQL_TIME &my_time)
 Round MYSQL_TIME time value and convert to to ulonglong representation. More...
 
unsigned long long int TIME_to_ulonglong_round (const MYSQL_TIME &my_time, int *warnings)
 Round any MYSQL_TIME timepoint and convert to ulonglong. More...
 
double TIME_microseconds (const MYSQL_TIME &my_time)
 Extract the microsecond part of a MYSQL_TIME struct as an n * (1/10^6) fraction as a double. More...
 
double TIME_to_double_datetime (const MYSQL_TIME &my_time)
 Convert a MYSQL_TIME datetime to double where the integral part is the timepoint as an ulonglong, and the fractional part is the fraction of the second. More...
 
double TIME_to_double_time (const MYSQL_TIME &my_time)
 Convert a MYSQL_TIME time to double where the integral part is the timepoint as an ulonglong, and the fractional part is the fraction of the second. More...
 
double TIME_to_double (const MYSQL_TIME &my_time)
 Convert a MYSQL_TIME to double where the integral part is the timepoint as an ulonglong, and the fractional part is the fraction of the second. More...
 
long long int my_packed_time_get_frac_part (long long int i)
 Return the fraction of the second as the number of microseconds. More...
 
long long int year_to_longlong_datetime_packed (long year)
 Convert year to packed numeric date representation. More...
 
long long int TIME_to_longlong_datetime_packed (const MYSQL_TIME &my_time)
 Convert datetime to packed numeric datetime representation. More...
 
long long int TIME_to_longlong_date_packed (const MYSQL_TIME &my_time)
 Convert date to packed numeric date representation. More...
 
long long int TIME_to_longlong_time_packed (const MYSQL_TIME &my_time)
 Convert time value to numeric packed representation. More...
 
long long int TIME_to_longlong_packed (const MYSQL_TIME &my_time)
 Convert a temporal value to packed numeric temporal representation, depending on its time_type. More...
 
void TIME_from_longlong_datetime_packed (MYSQL_TIME *ltime, long long int nr)
 Convert packed numeric datetime representation to MYSQL_TIME. More...
 
void TIME_from_longlong_time_packed (MYSQL_TIME *ltime, long long int nr)
 Convert time packed numeric representation to time. More...
 
void TIME_from_longlong_date_packed (MYSQL_TIME *ltime, long long int nr)
 Convert packed numeric date representation to MYSQL_TIME. More...
 
void TIME_set_yymmdd (MYSQL_TIME *ltime, unsigned int yymmdd)
 Set day, month and year from a number. More...
 
void TIME_set_hhmmss (MYSQL_TIME *ltime, unsigned int hhmmss)
 Set hour, minute and secondr from a number. More...
 
void my_datetime_packed_to_binary (long long int nr, unsigned char *ptr, unsigned int dec)
 Store in-memory numeric packed datetime representation to disk. More...
 
long long int my_datetime_packed_from_binary (const unsigned char *ptr, unsigned int dec)
 Convert on-disk datetime representation to in-memory packed numeric representation. More...
 
void my_time_packed_to_binary (long long int nr, unsigned char *ptr, unsigned int dec)
 Convert in-memory numeric time representation to on-disk representation. More...
 
long long int my_time_packed_from_binary (const unsigned char *ptr, unsigned int dec)
 Convert on-disk time representation to in-memory packed numeric representation. More...
 
void my_timestamp_to_binary (const struct timeval *tm, unsigned char *ptr, unsigned int dec)
 Convert in-memory timestamp representation to on-disk representation. More...
 
void my_timestamp_from_binary (struct timeval *tm, const unsigned char *ptr, unsigned int dec)
 Convert binary timestamp representation to in-memory representation. More...
 
bool str_to_time (const char *str, std::size_t length, MYSQL_TIME *l_time, MYSQL_TIME_STATUS *status, my_time_flags_t flags=0)
 
Convert a time string to a MYSQL_TIME struct. More...
 
bool check_time_mmssff_range (const MYSQL_TIME &my_time)
 Check if TIME fields can be adjusted to make the time value valid. More...
 
bool check_time_range_quick (const MYSQL_TIME &my_time)
 Check TIME range. More...
 
bool check_datetime_range (const MYSQL_TIME &my_time)
 Check datetime, date, or normalized time (i.e. More...
 
void adjust_time_range (MYSQL_TIME *, int *warning)
 Adjust 'time' value to lie in the MYSQL_TIME range. More...
 
bool validate_timestamp_range (const MYSQL_TIME &my_time)
 Function to check sanity of a TIMESTAMP value. More...
 
my_time_t my_system_gmt_sec (const MYSQL_TIME &my_time, long *my_timezone, bool *in_dst_time_gap)
 Convert time in MYSQL_TIME representation in system time zone to its my_time_t form (number of seconds in UTC since begginning of Unix Epoch). More...
 
void set_zero_time (MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type)
 Set MYSQL_TIME structure to 0000-00-00 00:00:00.000000. More...
 
void set_max_time (MYSQL_TIME *tm, bool neg)
 Set MYSQL_TIME variable to maximum time value. More...
 
void set_max_hhmmss (MYSQL_TIME *tm)
 Set hour, minute and second of a MYSQL_TIME variable to maximum time value. More...
 
int my_time_to_str (const MYSQL_TIME &my_time, char *to, unsigned int dec)
 Functions to convert time value to a string, using default format. More...
 
int my_date_to_str (const MYSQL_TIME &my_time, char *to)
 Function to convert date value to a string, using default format. More...
 
int my_datetime_to_str (const MYSQL_TIME &my_time, char *to, unsigned int dec)
 Print a datetime value with an optional fractional part. More...
 
int my_TIME_to_str (const MYSQL_TIME &my_time, char *to, unsigned int dec)
 Convert struct DATE/TIME/DATETIME value to string using built-in MySQL time conversion formats. More...
 
void my_date_to_binary (const MYSQL_TIME *ltime, unsigned char *ptr)
 Convert in-memory date representation to on-disk representation. More...
 
int my_timeval_to_str (const struct timeval *tm, char *to, unsigned int dec)
 Print a timestamp with an oprional fractional part: XXXXX[.YYYYY]. More...
 
bool date_add_interval (MYSQL_TIME *ltime, interval_type int_type, Interval interval, int *warnings)
 Add an interval to a MYSQL_TIME struct. More...
 
long my_time_fraction_remainder (long nr, unsigned int decimals)
 Round the input argument to the specified precision by computing the remainder modulo log10 of the difference between max and desired precison. More...
 
void my_time_trunc (MYSQL_TIME *ltime, unsigned int decimals)
 Truncate the number of microseconds in MYSQL_TIME::second_part to the desired precision. More...
 
void my_datetime_trunc (MYSQL_TIME *ltime, unsigned int decimals)
 Alias for my_time_trunc. More...
 
void my_timeval_trunc (struct timeval *tv, unsigned int decimals)
 Truncate the tv_usec member of a posix timeval struct to the specified number of decimals. More...
 
bool check_fuzzy_date (const MYSQL_TIME &my_time, my_time_flags_t fuzzydate)
 Predicate for fuzzyness of date. More...
 
bool non_zero_date (const MYSQL_TIME &my_time)
 
Predicate which returns true if at least one of the date members are non-zero. More...
 
bool non_zero_time (const MYSQL_TIME &my_time)
 
Predicate which returns true if at least one of the time members are non-zero. More...
 
void datetime_to_time (MYSQL_TIME *ltime)
 "Casts" MYSQL_TIME datetime to a MYSQL_TIME time. More...
 
void datetime_to_date (MYSQL_TIME *ltime)
 "Casts" MYSQL_TIME datetime to a MYSQL_TIME date. More...
 
void date_to_datetime (MYSQL_TIME *ltime)
 "Casts" a MYSQL_TIME to datetime by setting MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATETIME. More...
 
bool time_add_nanoseconds_with_truncate (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
 Add nanoseconds to a time value with truncation. More...
 
bool datetime_add_nanoseconds_with_truncate (MYSQL_TIME *ltime, unsigned int nanoseconds)
 Add nanoseconds to a datetime value with truncation. More...
 
bool time_add_nanoseconds_with_round (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
 Add nanoseconds to a time value with rounding. More...
 
bool datetime_add_nanoseconds_with_round (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
 Add nanoseconds to a datetime value with rounding. More...
 
bool time_add_nanoseconds_adjust_frac (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings, bool truncate)
 Add nanoseconds to time and round or tuncate as indicated by argument. More...
 
bool datetime_add_nanoseconds_adjust_frac (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings, bool truncate)
 Add nanoseconds to datetime and round or tuncate as indicated by argument. More...
 
bool my_time_adjust_frac (MYSQL_TIME *ltime, unsigned int dec, bool truncate)
 Round/Truncate time value to the given precision. More...
 
bool my_datetime_adjust_frac (MYSQL_TIME *ltime, unsigned int dec, int *warnings, bool truncate)
 Round/Truncate datetime value to the given precision. More...
 
bool my_timeval_round (struct timeval *tv, unsigned int decimals)
 Round timeval value to the given precision. More...
 
void mix_date_and_time (MYSQL_TIME *ldate, const MYSQL_TIME &my_time)
 Mix a date value and a time value. More...
 
void localtime_to_TIME (MYSQL_TIME *to, const struct tm *from)
 Convert a timepoint in a posix tm struct to a MSYQL_TIME struct. More...
 
void calc_time_from_sec (MYSQL_TIME *to, long long int seconds, long microseconds)
 Initialize MYSQL_TIME with MYSQL_TIMESTAMP_TIME from given number of seconds and microseconds. More...
 
bool calc_time_diff (const MYSQL_TIME &my_time1, const MYSQL_TIME &my_time2, int l_sign, long long int *seconds_out, long *microseconds_out)
 Calculate difference between two datetime values as seconds + microseconds. More...
 
int my_time_compare (const MYSQL_TIME &my_time_a, const MYSQL_TIME &my_time_b)
 Compare tow MYSQL_TIME objects. More...
 
long long int TIME_to_longlong_packed (const MYSQL_TIME &my_time, enum enum_field_types type)
 Convert MYSQL_TIME value to its packed numeric representation, using field type. More...
 
void TIME_from_longlong_packed (MYSQL_TIME *ltime, enum enum_field_types type, long long int packed_value)
 Convert packed numeric temporal representation to time, date or datetime, using field type. More...
 
long long int longlong_from_datetime_packed (enum enum_field_types type, long long int packed_value)
 Convert packed numeric representation to unpacked numeric representation. More...
 
double double_from_datetime_packed (enum enum_field_types type, long long int packed_value)
 Convert packed numeric temporal representation to unpacked numeric representation. More...
 

Detailed Description

Interface for low level time utilities.

Typedef Documentation

◆ my_time_flags_t

using my_time_flags_t = unsigned int

Flags to str_to_datetime and number_to_datetime.

◆ my_time_t

using my_time_t = [] long int

Portable time_t replacement.

Should be signed and hold seconds for 1902 – 2038-01-19 range i.e at least a 32bit variable

Using the system built in time_t is not an option as we rely on the above requirements in the time functions

Enumeration Type Documentation

◆ interval_type

Available interval types used in any statement.

'interval_type' must be sorted so that simple intervals comes first, ie year, quarter, month, week, day, hour, etc. The order based on interval size is also important and the intervals should be kept in a large to smaller order. (get_interval_value() depends on this)

Note
If you change the order of elements in this enum you should fix order of elements in 'interval_type_to_name' and 'interval_names' arrays
See also
interval_type_to_name, get_interval_value, interval_names
Enumerator
INTERVAL_YEAR 
INTERVAL_QUARTER 
INTERVAL_MONTH 
INTERVAL_WEEK 
INTERVAL_DAY 
INTERVAL_HOUR 
INTERVAL_MINUTE 
INTERVAL_SECOND 
INTERVAL_MICROSECOND 
INTERVAL_YEAR_MONTH 
INTERVAL_DAY_HOUR 
INTERVAL_DAY_MINUTE 
INTERVAL_DAY_SECOND 
INTERVAL_HOUR_MINUTE 
INTERVAL_HOUR_SECOND 
INTERVAL_MINUTE_SECOND 
INTERVAL_DAY_MICROSECOND 
INTERVAL_HOUR_MICROSECOND 
INTERVAL_MINUTE_MICROSECOND 
INTERVAL_SECOND_MICROSECOND 
INTERVAL_LAST 

Function Documentation

◆ check_fuzzy_date()

bool check_fuzzy_date ( const MYSQL_TIME my_time,
my_time_flags_t  fuzzydate 
)
inline

Predicate for fuzzyness of date.

Parameters
my_timetime point to check
fuzzydatebitfield indicating if fuzzy dates are premitted
Return values
trueif TIME_FUZZY_DATE is unset and either month or day is 0
falseotherwise

◆ convert_month_to_period()

unsigned long int convert_month_to_period ( unsigned long int  month)

◆ convert_period_to_month()

unsigned long int convert_period_to_month ( unsigned long int  period)

◆ date_to_datetime()

void date_to_datetime ( MYSQL_TIME ltime)
inline

"Casts" a MYSQL_TIME to datetime by setting MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATETIME.

Note
There is no check to ensure that the result is a valid datetime.
Parameters
ltimetimpoint to cast

◆ datetime_to_date()

void datetime_to_date ( MYSQL_TIME ltime)
inline

"Casts" MYSQL_TIME datetime to a MYSQL_TIME date.

Sets MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATE and zeroes out the time members.

Parameters
ltimetimepoint to cast

◆ datetime_to_time()

void datetime_to_time ( MYSQL_TIME ltime)
inline

"Casts" MYSQL_TIME datetime to a MYSQL_TIME time.

Sets MYSQL_TIME::time_type to MYSQL_TIMESTAMP_TIME and zeroes out the date members.

Parameters
ltimetimepoint to cast

◆ is_time_t_valid_for_timestamp()

bool is_time_t_valid_for_timestamp ( time_t  x)
inline

Check for valid times only if the range of time_t is greater than the range of my_time_t.

Which is almost always the case and even time_t does have the same range, the compiler will optimize away the unnecessary test (checked with compiler explorer).

◆ my_datetime_trunc()

void my_datetime_trunc ( MYSQL_TIME ltime,
unsigned int  decimals 
)
inline

Alias for my_time_trunc.

Parameters
ltimetime point
decimalsdesired precision

◆ my_packed_time_get_frac_part()

long long int my_packed_time_get_frac_part ( long long int  i)
inline

Return the fraction of the second as the number of microseconds.

Parameters
itimepoint as longlong
Returns
frational part of an timepoint represented as an (u)longlong

◆ my_time_fraction_remainder()

long my_time_fraction_remainder ( long  nr,
unsigned int  decimals 
)
inline

Round the input argument to the specified precision by computing the remainder modulo log10 of the difference between max and desired precison.

Parameters
nrnumber to round
decimalsdesired precision
Returns
nr rounded according to the desired precision.

◆ my_time_trunc()

void my_time_trunc ( MYSQL_TIME ltime,
unsigned int  decimals 
)
inline

Truncate the number of microseconds in MYSQL_TIME::second_part to the desired precision.

Parameters
ltimetime point
decimalsdesired precision

◆ my_timeval_trunc()

void my_timeval_trunc ( struct timeval *  tv,
unsigned int  decimals 
)
inline

Truncate the tv_usec member of a posix timeval struct to the specified number of decimals.

Parameters
tvtimepoint/duration
decimalsdesired precision

◆ non_zero_date()

bool non_zero_date ( const MYSQL_TIME my_time)
inline


Predicate which returns true if at least one of the date members are non-zero.

Parameters
my_timetime point to check.
Return values
falseif all the date members are zero
trueotherwise

◆ non_zero_time()

bool non_zero_time ( const MYSQL_TIME my_time)
inline


Predicate which returns true if at least one of the time members are non-zero.

Parameters
my_timetime point to check.
Return values
falseif all the time members are zero
trueotherwise

◆ TIME_microseconds()

double TIME_microseconds ( const MYSQL_TIME my_time)
inline

Extract the microsecond part of a MYSQL_TIME struct as an n * (1/10^6) fraction as a double.

Returns
microseconds part as double

◆ TIME_to_double()

double TIME_to_double ( const MYSQL_TIME my_time)
inline

Convert a MYSQL_TIME to double where the integral part is the timepoint as an ulonglong, and the fractional part is the fraction of the second.

The actual time type is extracted from MYSQL_TIME::time_type.

Parameters
my_timeMYSQL_TIME to convert
Returns
MYSQL_TIME as double

◆ TIME_to_double_datetime()

double TIME_to_double_datetime ( const MYSQL_TIME my_time)
inline

Convert a MYSQL_TIME datetime to double where the integral part is the timepoint as an ulonglong, and the fractional part is the fraction of the second.

Parameters
my_timedatetime to convert
Returns
datetime as double

◆ TIME_to_double_time()

double TIME_to_double_time ( const MYSQL_TIME my_time)
inline

Convert a MYSQL_TIME time to double where the integral part is the timepoint as an ulonglong, and the fractional part is the fraction of the second.

Parameters
my_timetime to convert
Returns
datetime as double

◆ TIME_to_ulonglong_round()

unsigned long long int TIME_to_ulonglong_round ( const MYSQL_TIME my_time,
int *  warnings 
)
inline

Round any MYSQL_TIME timepoint and convert to ulonglong.

Parameters
my_timeinput
[out]warningswarning vector
Returns
time point as ulonglong

◆ valid_period()

bool valid_period ( long long int  period)

◆ validate_timestamp_range()

bool validate_timestamp_range ( const MYSQL_TIME my_time)
inline

Function to check sanity of a TIMESTAMP value.

Check if a given MYSQL_TIME value fits in TIMESTAMP range. This function doesn't make precise check, but rather a rough estimate.

Parameters
my_timetimepoint to check
Return values
trueThe value seems sane
falseThe MYSQL_TIME value is definitely out of range

Variable Documentation

◆ DATETIME_MAX_DECIMALS

constexpr const int DATETIME_MAX_DECIMALS = 6

◆ MAX_DATE_STRING_REP_LENGTH

constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH = 30

Required buffer length for my_time_to_str, my_date_to_str, my_datetime_to_str and TIME_to_string functions.

Note, that the caller is still responsible to check that given TIME structure has values in valid ranges, otherwise size of the buffer could be not enough. We also rely on the fact that even wrong values sent using binary protocol fit in this buffer.

◆ MY_TIME_T_MAX

constexpr const my_time_t MY_TIME_T_MAX = std::numeric_limits<my_time_t>::max()

◆ MY_TIME_T_MIN

constexpr const my_time_t MY_TIME_T_MIN = std::numeric_limits<my_time_t>::min()

◆ MYSQL_TIME_NOTE_TRUNCATED

constexpr const int MYSQL_TIME_NOTE_TRUNCATED = 16

◆ MYSQL_TIME_WARN_DATETIME_OVERFLOW

constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW = 64

◆ MYSQL_TIME_WARN_INVALID_TIMESTAMP

constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP = 4

◆ MYSQL_TIME_WARN_OUT_OF_RANGE

constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE = 2

◆ MYSQL_TIME_WARN_TRUNCATED

constexpr const int MYSQL_TIME_WARN_TRUNCATED = 1

Conversion warnings.

◆ MYSQL_TIME_WARN_ZERO_DATE

constexpr const int MYSQL_TIME_WARN_ZERO_DATE = 8

◆ MYSQL_TIME_WARN_ZERO_IN_DATE

constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE = 32

◆ SECONDS_IN_24H

constexpr const long int SECONDS_IN_24H = 86400L

Usefull constants.

◆ TIME_DATETIME_ONLY

constexpr const my_time_flags_t TIME_DATETIME_ONLY = 2

Only allow full datetimes.

◆ TIME_FRAC_TRUNCATE

constexpr const my_time_flags_t TIME_FRAC_TRUNCATE = 4

◆ TIME_FUZZY_DATE

constexpr const my_time_flags_t TIME_FUZZY_DATE = 1

Allow zero day and zero month.

◆ TIME_INVALID_DATES

constexpr const my_time_flags_t TIME_INVALID_DATES = 64

Allow 2000-02-31.

◆ TIME_MAX_HOUR

constexpr const int TIME_MAX_HOUR = 838

Limits for the TIME data type.

◆ TIME_MAX_MINUTE

constexpr const int TIME_MAX_MINUTE = 59

◆ TIME_MAX_SECOND

constexpr const int TIME_MAX_SECOND = 59

◆ TIME_MAX_VALUE

constexpr const int TIME_MAX_VALUE
Initial value:
=
constexpr const int TIME_MAX_MINUTE
Definition: my_time.h:119
constexpr const int TIME_MAX_HOUR
Limits for the TIME data type.
Definition: my_time.h:118
constexpr const int TIME_MAX_SECOND
Definition: my_time.h:120


Note that this MUST be a signed type, as we use the unary - operator on it.

◆ TIME_MAX_VALUE_SECONDS

constexpr const int TIME_MAX_VALUE_SECONDS
Initial value:
=
constexpr const int TIME_MAX_MINUTE
Definition: my_time.h:119
constexpr const int TIME_MAX_HOUR
Limits for the TIME data type.
Definition: my_time.h:118
constexpr const int TIME_MAX_SECOND
Definition: my_time.h:120

◆ TIME_NO_DATE_FRAC_WARN

constexpr const my_time_flags_t TIME_NO_DATE_FRAC_WARN = 8

◆ TIME_NO_ZERO_DATE

constexpr const my_time_flags_t TIME_NO_ZERO_DATE = 32

Don't allow 0000-00-00 date.

◆ TIME_NO_ZERO_IN_DATE

constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE = 16

Don't allow zero day or zero month.

◆ TIME_STRICT_COLON

constexpr const my_time_flags_t TIME_STRICT_COLON = 128

Allow only HH:MM:SS or MM:SS time formats.

◆ TIMESTAMP_MAX_VALUE

constexpr const int TIMESTAMP_MAX_VALUE
Initial value:
=
std::numeric_limits<std::int32_t>::max()

◆ TIMESTAMP_MAX_YEAR

constexpr const int TIMESTAMP_MAX_YEAR = 2038

Time handling defaults.

◆ TIMESTAMP_MIN_VALUE

constexpr const int TIMESTAMP_MIN_VALUE = 1

◆ TIMESTAMP_MIN_YEAR

constexpr const int TIMESTAMP_MIN_YEAR = (1900 + YY_PART_YEAR - 1)

◆ WEEK_FIRST_WEEKDAY

constexpr const unsigned int WEEK_FIRST_WEEKDAY = 4

◆ WEEK_MONDAY_FIRST

constexpr const unsigned int WEEK_MONDAY_FIRST = 1

Flags for calc_week() function.

◆ WEEK_YEAR

constexpr const unsigned int WEEK_YEAR = 2

◆ YY_PART_YEAR

constexpr const int YY_PART_YEAR = 70

Two-digit years < this are 20XX; >= this are 19XX.