MySQL 9.1.0
Source Code Documentation

Interface for low level time utilities. More...

#include "my_config.h"
#include <assert.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <sys/time.h>
#include "field_types.h"
#include "my_time_t.h"
#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  MYSQL_TIME_STATUS::DEPRECATION
 
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_flags_t = unsigned int
 Flags to str_to_datetime and number_to_datetime. More...
 
const unsigned long long int log_10_int [20]
 
const unsigned char days_in_month []
 
const char my_zero_datetime6 []
 
constexpr const bool HAVE_64_BITS_TIME_T = sizeof(time_t) == sizeof(my_time_t)
 
constexpr const int MYTIME_MAX_YEAR = HAVE_64_BITS_TIME_T ? 9999 : 2038
 Time handling defaults. More...
 
constexpr const int TIMESTAMP_MAX_YEAR = 2038
 
constexpr const int YY_PART_YEAR = 70
 Two-digit years < this are 20XX; >= this are 19XX. More...
 
constexpr const int MYTIME_MIN_YEAR = (1900 + YY_PART_YEAR - 1)
 
constexpr const my_time_t MYTIME_MAX_VALUE
 max seconds from epoch of host's time_t stored in my_time_t Windows allows up to 3001-01-18 23:59:59 UTC for localtime_r, so that is our effective limit, although Unixen allow higher time points. More...
 
constexpr const int MYTIME_MIN_VALUE = 0
 Zero represents the first time value we allow, i.e. More...
 
constexpr const std::int64_t TYPE_TIMESTAMP_MAX_VALUE
 max seconds from epoch that can be stored in a column of type TIMESTAMP. More...
 
constexpr const std::int64_t TYPE_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 int64_t SECONDS_IN_24H = 86400LL
 Useful 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 int SECS_PER_MIN = 60
 
constexpr const int MINS_PER_HOUR = 60
 
constexpr const int HOURS_PER_DAY = 24
 
constexpr const int DAYS_PER_WEEK = 7
 
constexpr const int DAYS_PER_NYEAR = 365
 
constexpr const int DAYS_PER_LYEAR = 366
 
constexpr const int SECS_PER_HOUR = (SECS_PER_MIN * MINS_PER_HOUR)
 
constexpr const int SECS_PER_DAY = (SECS_PER_HOUR * HOURS_PER_DAY)
 
constexpr const int MONS_PER_YEAR = 12
 
constexpr const int MAX_TIME_ZONE_HOURS = 14
 
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 int64_t MAX_DAY_NUMBER = 3652424
 Daynumber from year 0 to 9999-12-31. More...
 
constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH
 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)
 
unsigned int calc_days_in_year (unsigned int year)
 
unsigned int year_2000_handling (unsigned int year)
 
bool time_zone_displacement_to_seconds (const char *str, size_t length, int *result)
 Parses a time zone displacement string on the form {+-}HH:MM, converting to seconds. More...
 
void get_date_from_daynr (int64_t daynr, unsigned int *year, unsigned int *month, unsigned int *day)
 
int calc_weekday (long daynr, bool sunday_first_day_of_week)
 Calc weekday from daynr. More...
 
bool valid_period (long long int period)
 
uint64_t convert_period_to_month (uint64_t period)
 Calculate month from period. More...
 
uint64_t convert_month_to_period (uint64_t month)
 Convert month to period. More...
 
bool is_time_t_valid_for_timestamp (time_t x)
 Check for valid my_time_t value. More...
 
unsigned int calc_week (const MYSQL_TIME &l_time, unsigned int week_behaviour, unsigned int *year)
 
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/... to a number in format YYYYMMDDHHMMSS (DATETIME), YYYYMMDD (DATE) or HHMMSS (TIME). 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)
 
void TIME_set_hhmmss (MYSQL_TIME *ltime, unsigned int hhmmss)
 
void my_datetime_packed_to_binary (long long int nr, unsigned char *ptr, unsigned int dec)
 
long long int my_datetime_packed_from_binary (const unsigned char *ptr, unsigned int dec)
 
void my_time_packed_to_binary (long long int nr, unsigned char *ptr, unsigned int dec)
 
long long int my_time_packed_from_binary (const unsigned char *ptr, unsigned int dec)
 
void my_timestamp_to_binary (const my_timeval *tm, unsigned char *ptr, unsigned int dec)
 
void my_timestamp_from_binary (my_timeval *tm, const unsigned char *ptr, unsigned int dec)
 
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_my_time (const MYSQL_TIME &my_time)
 Check whether the argument holds a valid UNIX time value (seconds after epoch). More...
 
my_time_t my_system_gmt_sec (const MYSQL_TIME &my_time, my_time_t *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 beginning 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)
 
int my_date_to_str (const MYSQL_TIME &my_time, char *to)
 Converts a date value to a string with the format 'YYYY-MM-DD'. More...
 
int my_datetime_to_str (const MYSQL_TIME &my_time, char *to, unsigned int dec)
 
int my_TIME_to_str (const MYSQL_TIME &my_time, char *to, unsigned int dec)
 
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 my_timeval *tm, char *to, unsigned int dec)
 
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 precision. 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 (my_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)
 
bool datetime_add_nanoseconds_with_truncate (MYSQL_TIME *ltime, unsigned int nanoseconds)
 
bool time_add_nanoseconds_with_round (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
 
bool datetime_add_nanoseconds_with_round (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
 
bool time_add_nanoseconds_adjust_frac (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings, bool truncate)
 
bool datetime_add_nanoseconds_adjust_frac (MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings, bool truncate)
 
bool my_time_adjust_frac (MYSQL_TIME *ltime, unsigned int dec, bool truncate)
 
bool my_datetime_adjust_frac (MYSQL_TIME *ltime, unsigned int dec, int *warnings, bool truncate)
 
bool my_timeval_round (my_timeval *tv, unsigned int decimals)
 
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)
 Converts a timepoint in a posix tm struct to a MYSQL_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.

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

◆ calc_daynr()

long calc_daynr ( unsigned int  year,
unsigned int  month,
unsigned int  day 
)

◆ calc_days_in_year()

unsigned int calc_days_in_year ( unsigned int  year)

◆ calc_week()

unsigned int calc_week ( const MYSQL_TIME l_time,
unsigned int  week_behaviour,
unsigned int *  year 
)

◆ 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

◆ 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_add_nanoseconds_adjust_frac()

bool datetime_add_nanoseconds_adjust_frac ( MYSQL_TIME ltime,
unsigned int  nanoseconds,
int *  warnings,
bool  truncate 
)

◆ datetime_add_nanoseconds_with_round()

bool datetime_add_nanoseconds_with_round ( MYSQL_TIME ltime,
unsigned int  nanoseconds,
int *  warnings 
)

◆ datetime_add_nanoseconds_with_truncate()

bool datetime_add_nanoseconds_with_truncate ( MYSQL_TIME ltime,
unsigned int  nanoseconds 
)

◆ 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

◆ get_date_from_daynr()

void get_date_from_daynr ( int64_t  daynr,
unsigned int *  year,
unsigned int *  month,
unsigned int *  day 
)

◆ is_time_t_valid_for_timestamp()

bool is_time_t_valid_for_timestamp ( time_t  x)
inline

Check for valid my_time_t value.

Note: timestamp here pertains to seconds since epoch, not the legacy MySQL type TIMESTAMP, which is limited to 32 bits even on 64 bit platforms.

◆ my_datetime_adjust_frac()

bool my_datetime_adjust_frac ( MYSQL_TIME ltime,
unsigned int  dec,
int *  warnings,
bool  truncate 
)

◆ my_datetime_packed_from_binary()

long long int my_datetime_packed_from_binary ( const unsigned char *  ptr,
unsigned int  dec 
)

◆ my_datetime_packed_to_binary()

void my_datetime_packed_to_binary ( long long int  nr,
unsigned char *  ptr,
unsigned int  dec 
)

◆ my_datetime_to_str()

int my_datetime_to_str ( const MYSQL_TIME my_time,
char *  to,
unsigned int  dec 
)

◆ 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_adjust_frac()

bool my_time_adjust_frac ( MYSQL_TIME ltime,
unsigned int  dec,
bool  truncate 
)

◆ 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 precision.

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

◆ my_time_packed_from_binary()

long long int my_time_packed_from_binary ( const unsigned char *  ptr,
unsigned int  dec 
)

◆ my_time_packed_to_binary()

void my_time_packed_to_binary ( long long int  nr,
unsigned char *  ptr,
unsigned int  dec 
)

◆ my_time_to_str()

int my_time_to_str ( const MYSQL_TIME my_time,
char *  to,
unsigned int  dec 
)

◆ my_TIME_to_str()

int my_TIME_to_str ( const MYSQL_TIME my_time,
char *  to,
unsigned int  dec 
)

◆ 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_timestamp_from_binary()

void my_timestamp_from_binary ( my_timeval tm,
const unsigned char *  ptr,
unsigned int  dec 
)

◆ my_timestamp_to_binary()

void my_timestamp_to_binary ( const my_timeval tm,
unsigned char *  ptr,
unsigned int  dec 
)

◆ my_timeval_round()

bool my_timeval_round ( my_timeval tv,
unsigned int  decimals 
)

◆ my_timeval_to_str()

int my_timeval_to_str ( const my_timeval tm,
char *  to,
unsigned int  dec 
)

◆ my_timeval_trunc()

void my_timeval_trunc ( my_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_add_nanoseconds_adjust_frac()

bool time_add_nanoseconds_adjust_frac ( MYSQL_TIME ltime,
unsigned int  nanoseconds,
int *  warnings,
bool  truncate 
)

◆ time_add_nanoseconds_with_round()

bool time_add_nanoseconds_with_round ( MYSQL_TIME ltime,
unsigned int  nanoseconds,
int *  warnings 
)

◆ time_add_nanoseconds_with_truncate()

bool time_add_nanoseconds_with_truncate ( MYSQL_TIME ltime,
unsigned int  nanoseconds,
int *  warnings 
)

◆ 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_set_hhmmss()

void TIME_set_hhmmss ( MYSQL_TIME ltime,
unsigned int  hhmmss 
)

◆ TIME_set_yymmdd()

void TIME_set_yymmdd ( MYSQL_TIME ltime,
unsigned int  yymmdd 
)

◆ 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_my_time()

bool validate_my_time ( const MYSQL_TIME my_time)
inline

Check whether the argument holds a valid UNIX time value (seconds after epoch).

This function doesn't make precise check, but rather a rough estimate before time zone adjustments.

Parameters
my_timetimepoint to check
Returns
true if value satisfies the check above, false otherwise.

◆ year_2000_handling()

unsigned int year_2000_handling ( unsigned int  year)

Variable Documentation

◆ DATETIME_MAX_DECIMALS

constexpr const int DATETIME_MAX_DECIMALS = 6
constexpr

◆ DAYS_PER_LYEAR

constexpr const int DAYS_PER_LYEAR = 366
constexpr

◆ DAYS_PER_NYEAR

constexpr const int DAYS_PER_NYEAR = 365
constexpr

◆ DAYS_PER_WEEK

constexpr const int DAYS_PER_WEEK = 7
constexpr

◆ HAVE_64_BITS_TIME_T

constexpr const bool HAVE_64_BITS_TIME_T = sizeof(time_t) == sizeof(my_time_t)
constexpr

◆ HOURS_PER_DAY

constexpr const int HOURS_PER_DAY = 24
constexpr

◆ MAX_DATE_STRING_REP_LENGTH

constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH
constexpr
Initial value:
=
sizeof("YYYY-MM-DD AM HH:MM:SS.FFFFFF+HH:MM")

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 might well be insufficient. We also rely on the fact that even incorrect values sent using binary protocol fit in this buffer.

◆ MAX_DAY_NUMBER

constexpr const int64_t MAX_DAY_NUMBER = 3652424
constexpr

Daynumber from year 0 to 9999-12-31.

◆ MAX_TIME_ZONE_HOURS

constexpr const int MAX_TIME_ZONE_HOURS = 14
constexpr

◆ MINS_PER_HOUR

constexpr const int MINS_PER_HOUR = 60
constexpr

◆ MONS_PER_YEAR

constexpr const int MONS_PER_YEAR = 12
constexpr

◆ MYSQL_TIME_NOTE_TRUNCATED

constexpr const int MYSQL_TIME_NOTE_TRUNCATED = 16
constexpr

◆ MYSQL_TIME_WARN_DATETIME_OVERFLOW

constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW = 64
constexpr

◆ MYSQL_TIME_WARN_INVALID_TIMESTAMP

constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP = 4
constexpr

◆ MYSQL_TIME_WARN_OUT_OF_RANGE

constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE = 2
constexpr

◆ MYSQL_TIME_WARN_TRUNCATED

constexpr const int MYSQL_TIME_WARN_TRUNCATED = 1
constexpr

Conversion warnings.

◆ MYSQL_TIME_WARN_ZERO_DATE

constexpr const int MYSQL_TIME_WARN_ZERO_DATE = 8
constexpr

◆ MYSQL_TIME_WARN_ZERO_IN_DATE

constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE = 32
constexpr

◆ MYTIME_MAX_VALUE

constexpr const my_time_t MYTIME_MAX_VALUE
constexpr
Initial value:
=
HAVE_64_BITS_TIME_T ? 32536771199
: std::numeric_limits<std::int32_t>::max()
constexpr const bool HAVE_64_BITS_TIME_T
Definition: my_time.h:60

max seconds from epoch of host's time_t stored in my_time_t Windows allows up to 3001-01-18 23:59:59 UTC for localtime_r, so that is our effective limit, although Unixen allow higher time points.

Hence the magic constant 32536771199.

◆ MYTIME_MAX_YEAR

constexpr const int MYTIME_MAX_YEAR = HAVE_64_BITS_TIME_T ? 9999 : 2038
constexpr

Time handling defaults.

◆ MYTIME_MIN_VALUE

constexpr const int MYTIME_MIN_VALUE = 0
constexpr

Zero represents the first time value we allow, i.e.

UNIX epoch. We do not allow times before UNIX epoch, except for inside computations, hence we use a signed integer as the base type, cf. prepare_tz_info.

◆ MYTIME_MIN_YEAR

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

◆ SECONDS_IN_24H

constexpr const int64_t SECONDS_IN_24H = 86400LL
constexpr

Useful constants.

◆ SECS_PER_DAY

constexpr const int SECS_PER_DAY = (SECS_PER_HOUR * HOURS_PER_DAY)
constexpr

◆ SECS_PER_HOUR

constexpr const int SECS_PER_HOUR = (SECS_PER_MIN * MINS_PER_HOUR)
constexpr

◆ SECS_PER_MIN

constexpr const int SECS_PER_MIN = 60
constexpr

◆ TIME_DATETIME_ONLY

constexpr const my_time_flags_t TIME_DATETIME_ONLY = 2
constexpr

Only allow full datetimes.

◆ TIME_FRAC_TRUNCATE

constexpr const my_time_flags_t TIME_FRAC_TRUNCATE = 4
constexpr

◆ TIME_FUZZY_DATE

constexpr const my_time_flags_t TIME_FUZZY_DATE = 1
constexpr

Allow zero day and zero month.

◆ TIME_INVALID_DATES

constexpr const my_time_flags_t TIME_INVALID_DATES = 64
constexpr

Allow 2000-02-31.

◆ TIME_MAX_HOUR

constexpr const int TIME_MAX_HOUR = 838
constexpr

Limits for the TIME data type.

◆ TIME_MAX_MINUTE

constexpr const int TIME_MAX_MINUTE = 59
constexpr

◆ TIME_MAX_SECOND

constexpr const int TIME_MAX_SECOND = 59
constexpr

◆ TIME_MAX_VALUE

constexpr const int TIME_MAX_VALUE
constexpr
Initial value:
=
constexpr const int TIME_MAX_HOUR
Limits for the TIME data type.
Definition: my_time.h:130
constexpr const int TIME_MAX_MINUTE
Definition: my_time.h:131
constexpr const int TIME_MAX_SECOND
Definition: my_time.h:132

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
constexpr
Initial value:

◆ TIME_NO_DATE_FRAC_WARN

constexpr const my_time_flags_t TIME_NO_DATE_FRAC_WARN = 8
constexpr

◆ TIME_NO_ZERO_DATE

constexpr const my_time_flags_t TIME_NO_ZERO_DATE = 32
constexpr

Don't allow 0000-00-00 date.

◆ TIME_NO_ZERO_IN_DATE

constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE = 16
constexpr

Don't allow zero day or zero month.

◆ TIME_STRICT_COLON

constexpr const my_time_flags_t TIME_STRICT_COLON = 128
constexpr

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

◆ TIMESTAMP_MAX_YEAR

constexpr const int TIMESTAMP_MAX_YEAR = 2038
constexpr

◆ TYPE_TIMESTAMP_MAX_VALUE

constexpr const std::int64_t TYPE_TIMESTAMP_MAX_VALUE
constexpr
Initial value:
=
std::numeric_limits<std::int32_t>::max()

max seconds from epoch that can be stored in a column of type TIMESTAMP.

This also impacts the max value that can be given to SET TIMESTAMP

◆ TYPE_TIMESTAMP_MIN_VALUE

constexpr const std::int64_t TYPE_TIMESTAMP_MIN_VALUE = 1
constexpr

◆ WEEK_FIRST_WEEKDAY

constexpr const unsigned int WEEK_FIRST_WEEKDAY = 4
constexpr

◆ WEEK_MONDAY_FIRST

constexpr const unsigned int WEEK_MONDAY_FIRST = 1
constexpr

Flags for calc_week() function.


◆ WEEK_YEAR

constexpr const unsigned int WEEK_YEAR = 2
constexpr

◆ YY_PART_YEAR

constexpr const int YY_PART_YEAR = 70
constexpr

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