MySQL 9.1.0
Source Code Documentation
|
Files | |
file | my_time.h |
Interface for low level time utilities. | |
file | my_time.cc |
Implementation of low level time utilities. | |
Macros | |
#define | MAX_DATE_PARTS 8 |
#define | TIMEF_OFS 0x800000000000LL |
On disk we convert from signed representation to unsigned representation using TIMEF_OFS, so all values become binary comparable. More... | |
#define | TIMEF_INT_OFS 0x800000LL |
#define | DATETIMEF_INT_OFS 0x8000000000LL |
On disk we store as unsigned number with DATETIMEF_INT_OFS offset, for HA_KETYPE_BINARY compatibility purposes. More... | |
Functions | |
static longlong | my_packed_time_get_int_part (longlong i) |
static longlong | my_packed_time_make (longlong i, longlong f) |
static longlong | my_packed_time_make_int (longlong i) |
static int | isspace_char (char ch) |
static int | isdigit_char (char ch) |
static int | ispunct_char (char ch) |
uint | calc_days_in_year (uint year) |
Calc days in one year. 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_hhmmss (MYSQL_TIME *tm) |
Set hour, minute and second of a MYSQL_TIME variable to maximum time value. More... | |
void | set_max_time (MYSQL_TIME *tm, bool neg) |
Set MYSQL_TIME variable to maximum time value. More... | |
bool | check_date (const MYSQL_TIME &my_time, bool not_zero_date, my_time_flags_t flags, int *was_cut) |
Check datetime value for validity according to flags. 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... | |
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... | |
bool | str_to_datetime (const char *const str_arg, 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... | |
bool | str_to_time (const char *str, std::size_t length, MYSQL_TIME *l_time, MYSQL_TIME_STATUS *status, my_time_flags_t flags) |
Convert a time string to a MYSQL_TIME struct. More... | |
bool | number_to_time (longlong nr, MYSQL_TIME *ltime, int *warnings) |
Convert number to TIME. More... | |
void | adjust_time_range (MYSQL_TIME *my_time, int *warning) |
Adjust 'time' value to lie in the MYSQL_TIME range. More... | |
void | my_init_time () |
Prepare offset of system time zone from UTC for my_system_gmt_sec() func. More... | |
uint | year_2000_handling (uint year) |
Handle 2 digit year conversions. More... | |
long | calc_daynr (uint year, uint month, uint day) |
Calculate nr of day since year 0 in new date-system (from 1615). 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... | |
static char * | format_two_digits (int value, char *to) |
Writes a two-digit number to a string, padded with zero if it is less than 10. More... | |
static int | my_useconds_to_str (char *to, unsigned useconds, unsigned dec) |
Print the microsecond part with the specified precision. More... | |
int | my_time_to_str (const MYSQL_TIME &my_time, char *to, uint dec) |
Converts a time value to a string with the format HH:MM:SS[.fraction]. More... | |
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... | |
static int | TIME_to_datetime_str (const MYSQL_TIME &my_time, char *to) |
Convert datetime to a string 'YYYY-MM-DD hh:mm:ss'. More... | |
int | my_datetime_to_str (const MYSQL_TIME &my_time, char *to, uint dec) |
Print a datetime value with an optional fractional part. More... | |
int | my_TIME_to_str (const MYSQL_TIME &my_time, char *to, uint dec) |
Convert struct DATE/TIME/DATETIME value to string using built-in MySQL time conversion formats. More... | |
int | my_timeval_to_str (const my_timeval *tm, char *to, uint dec) |
Print a timestamp with an oprional fractional part: XXXXX[.YYYYY]. More... | |
longlong | number_to_datetime (longlong 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... | |
ulonglong | TIME_to_ulonglong_datetime (const MYSQL_TIME &my_time) |
Convert time value to integer in YYYYMMDDHHMMSS. More... | |
ulonglong | TIME_to_ulonglong_date (const MYSQL_TIME &my_time) |
Convert MYSQL_TIME value to integer in YYYYMMDD format. More... | |
ulonglong | TIME_to_ulonglong_time (const MYSQL_TIME &my_time) |
Convert MYSQL_TIME value to integer in HHMMSS format. More... | |
void | TIME_set_yymmdd (MYSQL_TIME *ltime, uint yymmdd) |
Set day, month and year from a number. More... | |
void | TIME_set_hhmmss (MYSQL_TIME *ltime, uint hhmmss) |
Set hour, minute and secondr from a number. More... | |
ulonglong | 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... | |
ulonglong | TIME_to_ulonglong_datetime_round (const MYSQL_TIME &my_time, int *warnings) |
Round MYSQL_TIME datetime value and convert to ulonglong representation. More... | |
ulonglong | TIME_to_ulonglong_time_round (const MYSQL_TIME &my_time) |
Round MYSQL_TIME time value and convert to to ulonglong representation. More... | |
longlong | TIME_to_longlong_time_packed (const MYSQL_TIME &my_time) |
Convert time value to numeric packed representation. More... | |
void | TIME_from_longlong_time_packed (MYSQL_TIME *ltime, longlong tmp) |
Convert time packed numeric representation to time. More... | |
void | my_time_packed_to_binary (longlong nr, uchar *ptr, uint dec) |
Convert in-memory numeric time representation to on-disk representation. More... | |
longlong | my_time_packed_from_binary (const uchar *ptr, uint dec) |
Convert on-disk time representation to in-memory packed numeric representation. More... | |
longlong | TIME_to_longlong_datetime_packed (const MYSQL_TIME &my_time) |
Convert datetime to packed numeric datetime representation. More... | |
longlong | TIME_to_longlong_date_packed (const MYSQL_TIME &my_time) |
Convert date to packed numeric date representation. More... | |
longlong | year_to_longlong_datetime_packed (long year) |
Convert year to packed numeric date representation. More... | |
void | TIME_from_longlong_datetime_packed (MYSQL_TIME *ltime, longlong tmp) |
Convert packed numeric datetime representation to MYSQL_TIME. More... | |
void | TIME_from_longlong_date_packed (MYSQL_TIME *ltime, longlong tmp) |
Convert packed numeric date representation to MYSQL_TIME. More... | |
longlong | my_datetime_packed_from_binary (const uchar *ptr, uint dec) |
Convert on-disk datetime representation to in-memory packed numeric representation. More... | |
void | my_datetime_packed_to_binary (longlong nr, uchar *ptr, uint dec) |
Store in-memory numeric packed datetime representation to disk. More... | |
void | my_timestamp_from_binary (my_timeval *tm, const uchar *ptr, uint dec) |
Convert binary timestamp representation to in-memory representation. More... | |
void | my_timestamp_to_binary (const my_timeval *tm, uchar *ptr, uint dec) |
Convert in-memory timestamp representation to on-disk representation. More... | |
void | my_date_to_binary (const MYSQL_TIME *ltime, uchar *ptr) |
Convert in-memory date representation to on-disk representation. More... | |
longlong | 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 | get_date_from_daynr (int64_t daynr, uint *ret_year, uint *ret_month, uint *ret_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... | |
uint | calc_week (const MYSQL_TIME &my_time, uint week_behaviour, uint *year) |
Calculate the week number from a MYSQL_TIME value. More... | |
bool | valid_period (long long period) |
Predicate for the validity of a period. More... | |
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 | date_add_interval (MYSQL_TIME *ltime, interval_type int_type, Interval interval, int *warnings) |
Add an interval to a MYSQL_TIME struct. More... | |
bool | time_add_nanoseconds_with_truncate (MYSQL_TIME *ltime, uint nanoseconds, int *warnings) |
Add nanoseconds to a time value with truncation. More... | |
bool | datetime_add_nanoseconds_with_truncate (MYSQL_TIME *ltime, uint nanoseconds) |
Add nanoseconds to a datetime value with truncation. More... | |
bool | time_add_nanoseconds_with_round (MYSQL_TIME *ltime, uint nanoseconds, int *warnings) |
Add nanoseconds to a time value with rounding. More... | |
bool | datetime_add_nanoseconds_with_round (MYSQL_TIME *ltime, uint nanoseconds, int *warnings) |
Add nanoseconds to a datetime value with rounding. More... | |
bool | time_add_nanoseconds_adjust_frac (MYSQL_TIME *ltime, uint nanoseconds, int *warnings, bool truncate) |
Add nanoseconds to time and round or truncate as indicated by argument. More... | |
bool | datetime_add_nanoseconds_adjust_frac (MYSQL_TIME *ltime, uint nanoseconds, int *warnings, bool truncate) |
Add nanoseconds to datetime and round or truncate as indicated by argument. More... | |
bool | my_time_adjust_frac (MYSQL_TIME *ltime, uint dec, bool truncate) |
Round/Truncate time value to the given precision. More... | |
bool | my_datetime_adjust_frac (MYSQL_TIME *ltime, uint dec, int *warnings, bool truncate) |
Round/Truncate datetime value to the given precision. More... | |
bool | my_timeval_round (struct my_timeval *tv, uint 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) |
Converts a timepoint in a posix tm struct to a MYSQL_TIME struct. More... | |
void | calc_time_from_sec (MYSQL_TIME *to, longlong 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, longlong *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... | |
longlong | 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, longlong packed_value) |
Convert packed numeric temporal representation to time, date or datetime, using field type. More... | |
longlong | longlong_from_datetime_packed (enum enum_field_types type, longlong packed_value) |
Convert packed numeric representation to unpacked numeric representation. More... | |
double | double_from_datetime_packed (enum enum_field_types type, longlong packed_value) |
Convert packed numeric temporal representation to unpacked numeric representation. More... | |
Variables | |
const ulonglong | log_10_int [20] |
const char | my_zero_datetime6 [] = "0000-00-00 00:00:00.000000" |
static constexpr const char | time_separator = ':' |
static constexpr ulong const | days_at_timestart = 719528 |
Day number with 1970-01-01 as base. More... | |
const uchar | days_in_month [] |
static my_time_t | my_time_zone = 0 |
Offset of system time zone from UTC in seconds used to speed up work of my_system_gmt_sec() function. More... | |
static constexpr const uint | msec_round_add [7] |
Rounding functions. More... | |
Bits | Field | Value range |
---|---|---|
1 | sign | (Used for sign, when on disk) |
1 | unused | (Reserved for wider hour range, e.g. for intervals) |
10 | hour | (0-838) |
6 | minute | (0-59) |
6 | second | (0-59) |
24 | microseconds | (0-999999) |
Format: Suhhhhhh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff
Bits | Field | Value |
---|---|---|
1 | sign | (used when on disk) |
17 | year*13+month | (year 0-9999, month 0-12) |
5 | day | (0-31) |
5 | hour | (0-23) |
6 | minute | (0-59) |
6 | second | (0-59) |
24 | microseconds | (0-999999) |
Format: SYYYYYYY.YYYYYYYY.YYdddddh.hhhhmmmm.mmssssss.ffffffff.ffffffff.ffffffff
#define DATETIMEF_INT_OFS 0x8000000000LL |
On disk we store as unsigned number with DATETIMEF_INT_OFS offset, for HA_KETYPE_BINARY compatibility purposes.
#define MAX_DATE_PARTS 8 |
#define TIMEF_INT_OFS 0x800000LL |
#define TIMEF_OFS 0x800000000000LL |
On disk we convert from signed representation to unsigned representation using TIMEF_OFS, so all values become binary comparable.
void adjust_time_range | ( | MYSQL_TIME * | my_time, |
int * | warning | ||
) |
Adjust 'time' value to lie in the MYSQL_TIME range.
If the time value lies outside of the range [-838:59:59, 838:59:59], set it to the closest endpoint of the range and set MYSQL_TIME_WARN_OUT_OF_RANGE flag in the 'warning' variable.
[in,out] | my_time | pointer to MYSQL_TIME value |
[out] | warning | set MYSQL_TIME_WARN_OUT_OF_RANGE flag if the value is out of range |
long calc_daynr | ( | uint | year, |
uint | month, | ||
uint | day | ||
) |
Calculate nr of day since year 0 in new date-system (from 1615).
year | Year (exact 4 digit year, no year conversions) |
month | Month |
day | Day |
uint calc_days_in_year | ( | uint | year | ) |
Calc days in one year.
bool calc_time_diff | ( | const MYSQL_TIME & | my_time1, |
const MYSQL_TIME & | my_time2, | ||
int | l_sign, | ||
longlong * | seconds_out, | ||
long * | microseconds_out | ||
) |
Calculate difference between two datetime values as seconds + microseconds.
my_time1 | - TIME/DATE/DATETIME value | |
my_time2 | - TIME/DATE/DATETIME value | |
l_sign | - 1 absolute values are subtracted, -1 absolute values are added. | |
[out] | seconds_out | - where difference between my_time1 and my_time2 in seconds is stored. |
[out] | microseconds_out | - where microsecond part of difference between my_time1 and my_time2 is stored. |
1 | means negative result |
0 | means positive result |
void calc_time_from_sec | ( | MYSQL_TIME * | to, |
longlong | seconds, | ||
long | microseconds | ||
) |
Initialize MYSQL_TIME with MYSQL_TIMESTAMP_TIME from given number of seconds and microseconds.
uint calc_week | ( | const MYSQL_TIME & | my_time, |
uint | week_behaviour, | ||
uint * | year | ||
) |
Calculate the week number from a MYSQL_TIME value.
The bits in week_format has the following meaning: WEEK_MONDAY_FIRST (0) If not set Sunday is first day of week If set Monday is first day of week WEEK_YEAR (1) If not set Week is in range 0-53
Week 0 is returned for the the last week of the previous year (for a date at start of january) In this case one can get 53 for the first week of next year. This flag ensures that the week is relevant for the given year. Note that this flag is only relevant if WEEK_JANUARY is not set. If set Week is in range 1-53. In this case one may get week 53 for a date in January (when the week is that last week of previous year) and week 1 for a date in December.
WEEK_FIRST_WEEKDAY (2) If not set Weeks are numbered according to ISO 8601:1988 If set The week that contains the first 'first-day-of-week' is week 1.
ISO 8601:1988 means that if the week containing January 1 has four or more days in the new year, then it is week 1; Otherwise it is the last week of the previous year, and the next week is week 1.
my_time | Source time value | |
week_behaviour | Parameter controlling how weeks are counted | |
[out] | year | The year of the week number (which may be different from my_time.year as described above) |
int calc_weekday | ( | long | daynr, |
bool | sunday_first_day_of_week | ||
) |
Calc weekday from daynr.
0 | for Monday |
6 | for Sunday |
bool check_date | ( | const MYSQL_TIME & | my_time, |
bool | not_zero_date, | ||
my_time_flags_t | flags, | ||
int * | was_cut | ||
) |
Check datetime value for validity according to flags.
[in] | my_time | Date to check. |
[in] | not_zero_date | my_time is not the zero date |
[in] | flags | flags to check (see str_to_datetime() flags in my_time.h) |
[out] | was_cut | set to 2 if value was invalid according to flags. (Feb 29 in non-leap etc.). This remains unchanged if value is not invalid. |
Here we assume that year and month is ok! If month is 0 we allow any date. (This only happens if we allow zero date parts in str_to_datetime()) Disallow dates with zero year and non-zero month and/or day.
false | OK |
true | error |
bool check_datetime_range | ( | const MYSQL_TIME & | my_time | ) |
Check datetime, date, or normalized time (i.e.
time without days) range.
my_time | Datetime value. |
false | on success |
true | on error |
bool check_time_mmssff_range | ( | const MYSQL_TIME & | my_time | ) |
Check if TIME fields can be adjusted to make the time value valid.
my_time | Time value. |
true | if the value cannot be made valid. |
false | if the value is already valid or can be adjusted to become valid. |
bool check_time_range_quick | ( | const MYSQL_TIME & | my_time | ) |
Check TIME range.
The value can include day part, for example: '1 10:20:30.123456'.
minute, second and second_part values are not checked unless hour is equal TIME_MAX_HOUR.
my_time | Time value. |
false | if value is Ok. |
true | if value is out of range. |
uint64_t convert_month_to_period | ( | uint64_t | month | ) |
Convert month to period.
uint64_t convert_period_to_month | ( | uint64_t | period | ) |
Calculate month from period.
bool date_add_interval | ( | MYSQL_TIME * | ltime, |
interval_type | int_type, | ||
Interval | interval, | ||
int * | warnings | ||
) |
Add an interval to a MYSQL_TIME struct.
true | if error |
false | otherwise |
bool datetime_add_nanoseconds_adjust_frac | ( | MYSQL_TIME * | ltime, |
uint | nanoseconds, | ||
int * | warnings, | ||
bool | truncate | ||
) |
Add nanoseconds to datetime and round or truncate as indicated by argument.
[in,out] | ltime | MYSQL_TIME variable to add to. |
nanoseconds | Nanoseconds value. | |
[in,out] | warnings | Warning flag vector. |
truncate | Decides whether fractional part of seconds will be truncated/rounded. |
False | on success, true on error. |
bool datetime_add_nanoseconds_with_round | ( | MYSQL_TIME * | ltime, |
uint | nanoseconds, | ||
int * | warnings | ||
) |
Add nanoseconds to a datetime value with rounding.
[in,out] | ltime | MYSQL_TIME variable to add to. |
nanoseconds | Nanoseconds value. | |
[in,out] | warnings | Warning flag vector. |
False | on success, true on error. |
bool datetime_add_nanoseconds_with_truncate | ( | MYSQL_TIME * | ltime, |
uint | nanoseconds | ||
) |
Add nanoseconds to a datetime value with truncation.
[in,out] | ltime | MYSQL_TIME variable to add to. |
nanoseconds | Nanoseconds value. |
False | on success. No real failure case here. |
double double_from_datetime_packed | ( | enum enum_field_types | type, |
longlong | packed_value | ||
) |
Convert packed numeric temporal representation to unpacked numeric representation.
type | MySQL field type. |
packed_value | Numeric packed temporal representation. |
|
static |
Writes a two-digit number to a string, padded with zero if it is less than 10.
If the number is greater than or equal to 100, "00" is written to the string. The number should be less than 100 for valid temporal values, but the formatting functions need to handle invalid values too, since they are used for formatting the values in error/warning messages when invalid values have been given by the user.
void get_date_from_daynr | ( | int64_t | daynr, |
uint * | ret_year, | ||
uint * | ret_month, | ||
uint * | ret_day | ||
) |
Change a daynr to year, month and day.
Daynr 0 is returned as date 00.00.00
This function is called from mysqld's print_fatal_signal(). Do not make changes to this function that make that call unsafe.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
void localtime_to_TIME | ( | MYSQL_TIME * | to, |
const struct tm * | from | ||
) |
Converts a timepoint in a posix tm struct to a MYSQL_TIME struct.
[out] | to | store converted timepoint here |
from | posix tm struct holding a valid timepoint |
longlong longlong_from_datetime_packed | ( | enum enum_field_types | type, |
longlong | packed_value | ||
) |
Convert packed numeric representation to unpacked numeric representation.
type | MySQL field type. |
packed_value | Packed numeric temporal value. |
void mix_date_and_time | ( | MYSQL_TIME * | ldate, |
const MYSQL_TIME & | my_time | ||
) |
Mix a date value and a time value.
[in,out] | ldate | Date value. |
my_time | Time value. |
void my_date_to_binary | ( | const MYSQL_TIME * | ltime, |
uchar * | ptr | ||
) |
Convert in-memory date representation to on-disk representation.
ltime | The value to convert. | |
[out] | ptr | The pointer to store the value to. |
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'.
This function doesn't check that the given MYSQL_TIME structure members are in the valid range. If they are not, the returned value won't reflect any valid date either.
my_time | Source time value | |
[out] | to | Destination character array |
bool my_datetime_adjust_frac | ( | MYSQL_TIME * | ltime, |
uint | dec, | ||
int * | warnings, | ||
bool | truncate | ||
) |
Round/Truncate datetime value to the given precision.
[in,out] | ltime | The value to round. |
dec | Precision. | |
[in,out] | warnings | Warning flag vector |
truncate | Decides whether fractional part of seconds will be truncated/rounded. |
Convert on-disk datetime representation to in-memory packed numeric representation.
ptr | The pointer to read value at. |
dec | Precision. |
Store in-memory numeric packed datetime representation to disk.
nr | In-memory numeric packed datetime representation. | |
[out] | ptr | The pointer to store at. |
dec | Precision, 1-6. |
int my_datetime_to_str | ( | const MYSQL_TIME & | my_time, |
char * | to, | ||
uint | dec | ||
) |
Print a datetime value with an optional fractional part.
my_time | The MYSQL_TIME value to print | |
[out] | to | The string pointer to print at. This function is guaranteed not to write more than MAX_DATE_STRING_REP_LENGTH characters. |
dec | Precision, in the range 0..6 |
void my_init_time | ( | ) |
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
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).
my_time | - time value to be converted |
my_timezone | - pointer to a my_time_t where offset of system time zone from UTC will be stored for caching |
in_dst_time_gap | - set to true if time falls into spring time-gap |
bool my_time_adjust_frac | ( | MYSQL_TIME * | ltime, |
uint | dec, | ||
bool | truncate | ||
) |
Round/Truncate time value to the given precision.
[in,out] | ltime | The value to round. |
dec | Precision. | |
truncate | Decides whether fractional part of seconds will be truncated/rounded. |
int my_time_compare | ( | const MYSQL_TIME & | my_time_a, |
const MYSQL_TIME & | my_time_b | ||
) |
Compare tow MYSQL_TIME objects.
0 | if a and b are equal |
-1 | if a comes before b |
1 | if b comes before a |
Convert on-disk time representation to in-memory packed numeric representation.
ptr | The pointer to read the value at. |
dec | Precision. |
Convert in-memory numeric time representation to on-disk representation.
nr | Value in packed numeric time format. | |
[out] | ptr | The buffer to put value at. |
dec | Precision. |
int my_time_to_str | ( | const MYSQL_TIME & | my_time, |
char * | to, | ||
uint | dec | ||
) |
Converts a time value to a string with the format HH:MM:SS[.fraction].
This function doesn't check that the given MYSQL_TIME structure members are in the valid range. If they are not, the returned value won't reflect any valid time either. Additionally, it doesn't take into account time->day member: it's assumed that days have been converted to hours already.
my_time | Source time value | |
[out] | to | Destnation char array |
dec | Precision, in the range 0..6 |
int my_TIME_to_str | ( | const MYSQL_TIME & | my_time, |
char * | to, | ||
uint | dec | ||
) |
Convert struct DATE/TIME/DATETIME value to string using built-in MySQL time conversion formats.
my_time | The MYSQL_TIME value to print | |
[out] | to | The string pointer to print at |
dec | Precision, in the range 0..6 |
void my_timestamp_from_binary | ( | my_timeval * | tm, |
const uchar * | ptr, | ||
uint | dec | ||
) |
Convert binary timestamp representation to in-memory representation.
[out] | tm | The variable to convert to. |
ptr | The pointer to read the value from. | |
dec | Precision. |
void my_timestamp_to_binary | ( | const my_timeval * | tm, |
uchar * | ptr, | ||
uint | dec | ||
) |
Convert in-memory timestamp representation to on-disk representation.
tm | The value to convert. | |
[out] | ptr | The pointer to store the value to. |
dec | Precision. |
bool my_timeval_round | ( | struct my_timeval * | tv, |
uint | decimals | ||
) |
Round timeval value to the given precision.
[in,out] | tv | The value to round. |
decimals | Precision. |
int my_timeval_to_str | ( | const my_timeval * | tm, |
char * | to, | ||
uint | dec | ||
) |
Print a timestamp with an oprional fractional part: XXXXX[.YYYYY].
tm | The timestamp value to print. | |
[out] | to | The string pointer to print at. |
dec | Precision, in the range 0..6. |
|
static |
Print the microsecond part with the specified precision.
[out] | to | The string pointer to print at |
useconds | The microseconds value | |
dec | Precision, between 1 and 6 |
longlong number_to_datetime | ( | longlong | 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.
Convert a datetime value of formats YYMMDD, YYYYMMDD, YYMMDDHHMSS, YYYYMMDDHHMMSS to broken-down MYSQL_TIME representation. Return value in YYYYMMDDHHMMSS format as side-effect.
This function also checks if datetime value fits in DATETIME range.
Datetime value in YYYYMMDDHHMMSS format.
was_cut if return value -1: one of
nr | datetime value as number | |
[in,out] | time_res | pointer for structure for broken-down representation |
flags | TIME_NO_ZERO_DATE and flags used by check_date() | |
[out] | was_cut | 0 Value ok 1 If value was cut during conversion 2 check_date(date,flags) considers date invalid |
-1 | Timestamp with wrong values, e.g. nr == 0 with TIME_NO_ZERO_DATE |
anything | else DATETIME as integer in YYYYMMDDHHMMSS format |
bool number_to_time | ( | longlong | nr, |
MYSQL_TIME * | ltime, | ||
int * | warnings | ||
) |
Convert number to TIME.
nr | Number to convert. | |
[out] | ltime | Variable to convert to. |
[out] | warnings | Warning vector. |
false | OK |
true | No. is out of range |
void set_max_hhmmss | ( | MYSQL_TIME * | tm | ) |
Set hour, minute and second of a MYSQL_TIME variable to maximum time value.
Unlike set_max_time(), does not touch the other structure members.
void set_max_time | ( | MYSQL_TIME * | tm, |
bool | neg | ||
) |
Set MYSQL_TIME variable to maximum time value.
tm | OUT The variable to set. |
neg | Sign: 1 if negative, 0 if positive. |
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.
[out] | tm | The value to set. |
time_type | Timestasmp type |
bool str_to_datetime | ( | const char *const | str_arg, |
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.
DESCRIPTION At least the following formats are recognized (based on number of digits) YYMMDD, YYYYMMDD, YYMMDDHHMMSS, YYYYMMDDHHMMSS YY-MM-DD, YYYY-MM-DD, YY-MM-DD HH.MM.SS YYYYMMDDTHHMMSS where T is a the character T (ISO8601) Also dates where all parts are zero are allowed
The second part may have an optional .###### fraction part. The datetime value may be followed by a time zone displacement +/-HH:MM.
NOTES This function should work with a format position vector as long as the following things holds:
The hour part must be specified in hour-minute-second order.
status->warnings is set to: 0 Value OK MYSQL_TIME_WARN_TRUNCATED If value was cut during conversion MYSQL_TIME_WARN_OUT_OF_RANGE check_date(date,flags) considers date invalid
l_time->time_type is set as follows: MYSQL_TIMESTAMP_NONE String wasn't a timestamp, like [DD [HH:[MM:[SS]]]].fraction. l_time is not changed. MYSQL_TIMESTAMP_DATE DATE string (YY MM and DD parts ok) MYSQL_TIMESTAMP_DATETIME Full timestamp MYSQL_TIMESTAMP_ERROR Timestamp with wrong values. All elements in l_time is set to 0
flags is a bit field with the following possible values: TIME_FUZZY_DATE TIME_DATETIME_ONLY TIME_NO_ZERO_IN_DATE TIME_NO_ZERO_DATE TIME_INVALID_DATES
str_arg | String to parse | |
length | Length of string | |
[out] | l_time | Date is stored here |
flags | Bitfield TIME_FUZZY_DATE|TIME_DATETIME_ONLY|TIME_NO_ZERO_IN_DATE|TIME_NO_ZERO_DATE|TIME_INVALID_DATES (described above) | |
status | Conversion status and warnings |
false | Ok |
true | Error |
bool str_to_time | ( | const char * | str, |
std::size_t | length, | ||
MYSQL_TIME * | l_time, | ||
MYSQL_TIME_STATUS * | status, | ||
my_time_flags_t | flags | ||
) |
Convert a time string to a MYSQL_TIME struct.
status.warning is set to: MYSQL_TIME_WARN_TRUNCATED flag if the input string was cut during conversion, and/or MYSQL_TIME_WARN_OUT_OF_RANGE flag, if the value is out of range.
str | A string in full TIMESTAMP format or [-] DAYS [H]H:MM:SS, [H]H:MM:SS, [M]M:SS, [H]HMMSS, [M]MSS or [S]S | |
length | Length of str | |
[out] | l_time | Store result here |
[out] | status | Conversion status, including warnings. |
flags | Optional flags to control conversion |
false | Ok |
true | Error |
bool time_add_nanoseconds_adjust_frac | ( | MYSQL_TIME * | ltime, |
uint | nanoseconds, | ||
int * | warnings, | ||
bool | truncate | ||
) |
Add nanoseconds to time and round or truncate as indicated by argument.
[in,out] | ltime | MYSQL_TIME variable to add to. |
nanoseconds | Nanosecons value. | |
[in,out] | warnings | Warning flag vector. |
truncate | Decides whether fractional part of seconds will be truncated/rounded. |
False | on success. No real failure case here. |
bool time_add_nanoseconds_with_round | ( | MYSQL_TIME * | ltime, |
uint | nanoseconds, | ||
int * | warnings | ||
) |
Add nanoseconds to a time value with rounding.
[in,out] | ltime | MYSQL_TIME variable to add to. |
nanoseconds | Nanoseconds value. | |
[in,out] | warnings | Warning flag vector. |
False | on success, true on error. |
bool time_add_nanoseconds_with_truncate | ( | MYSQL_TIME * | ltime, |
uint | nanoseconds, | ||
int * | warnings | ||
) |
Add nanoseconds to a time value with truncation.
[in,out] | ltime | MYSQL_TIME variable to add to. |
nanoseconds | Nanoseconds value. | |
[in,out] | warnings | Warning flag vector. |
False | on success. No real failure case here. |
void TIME_from_longlong_date_packed | ( | MYSQL_TIME * | ltime, |
longlong | tmp | ||
) |
Convert packed numeric date representation to MYSQL_TIME.
[out] | ltime | The date variable to convert to. |
tmp | The packed numeric date value. |
void TIME_from_longlong_datetime_packed | ( | MYSQL_TIME * | ltime, |
longlong | tmp | ||
) |
Convert packed numeric datetime representation to MYSQL_TIME.
[out] | ltime | The datetime variable to convert to. |
tmp | The packed numeric datetime value. |
void TIME_from_longlong_packed | ( | MYSQL_TIME * | ltime, |
enum enum_field_types | type, | ||
longlong | packed_value | ||
) |
Convert packed numeric temporal representation to time, date or datetime, using field type.
[out] | ltime | The variable to write to. |
type | MySQL field type. | |
packed_value | Numeric datetype representation. |
void TIME_from_longlong_time_packed | ( | MYSQL_TIME * | ltime, |
longlong | tmp | ||
) |
Convert time packed numeric representation to time.
[out] | ltime | The MYSQL_TIME variable to set. |
tmp | The packed numeric representation. |
void TIME_set_hhmmss | ( | MYSQL_TIME * | ltime, |
uint | hhmmss | ||
) |
Set hour, minute and secondr from a number.
ltime | MYSQL_TIME variable |
hhmmss | Number in HHMMSS format |
void TIME_set_yymmdd | ( | MYSQL_TIME * | ltime, |
uint | yymmdd | ||
) |
Set day, month and year from a number.
ltime | MYSQL_TIME variable |
yymmdd | Number in YYYYMMDD format |
|
static |
Convert datetime to a string 'YYYY-MM-DD hh:mm:ss'.
Open coded for better performance. This code previously resided in field.cc, in Field_timestamp::val_str().
my_time | The src MYSQL_TIME value. | |
[out] | to | The string pointer to print at. |
longlong TIME_to_longlong_date_packed | ( | const MYSQL_TIME & | my_time | ) |
Convert date to packed numeric date representation.
Numeric packed date format is similar to numeric packed datetime representation, with zero hhmmss part.
my_time | The value to convert. |
longlong TIME_to_longlong_datetime_packed | ( | const MYSQL_TIME & | my_time | ) |
Convert datetime to packed numeric datetime representation.
my_time | The value to convert. |
longlong TIME_to_longlong_packed | ( | const MYSQL_TIME & | my_time | ) |
Convert a temporal value to packed numeric temporal representation, depending on its time_type.
my_time | The value to convert. |
longlong 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.
my_time | The time value to convert. |
type | MySQL field type. |
longlong TIME_to_longlong_time_packed | ( | const MYSQL_TIME & | my_time | ) |
Convert time value to numeric packed representation.
my_time | The value to convert. |
ulonglong 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).
The function is used when we need to convert value of time item to a number if it's used in numeric context, i. e.: SELECT NOW()+1, CURDATE()+0, CURTIMIE()+0; SELECT ?+1;
my_time | Source time value |
0 | in case of errors! |
number | in format YYYYMMDDHHMMSS (DATETIME), YYYYMMDD (DATE) or HHMMSS (TIME), otherwise. |
ulonglong TIME_to_ulonglong_date | ( | const MYSQL_TIME & | my_time | ) |
Convert MYSQL_TIME value to integer in YYYYMMDD format.
my_time | The MYSQL_TIME value to convert. |
ulonglong TIME_to_ulonglong_datetime | ( | const MYSQL_TIME & | my_time | ) |
Convert time value to integer in YYYYMMDDHHMMSS.
my_time | The MYSQL_TIME value to convert. |
ulonglong TIME_to_ulonglong_datetime_round | ( | const MYSQL_TIME & | my_time, |
int * | warnings | ||
) |
Round MYSQL_TIME datetime value and convert to ulonglong representation.
my_time | input time | |
[out] | warnings | warning vector |
ulonglong TIME_to_ulonglong_time | ( | const MYSQL_TIME & | my_time | ) |
Convert MYSQL_TIME value to integer in HHMMSS format.
This function doesn't take into account time->day member: it's assumed that days have been converted to hours already.
my_time | The TIME value to convert. |
ulonglong TIME_to_ulonglong_time_round | ( | const MYSQL_TIME & | my_time | ) |
Round MYSQL_TIME time value and convert to to ulonglong representation.
my_time | input time |
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.
[in] | str | Time zone displacement string. |
[in] | length | Length of said string. |
[out] | result | Calculated displacement in seconds. |
false | Ok. |
true | Not a valid time zone displacement string. |
bool valid_period | ( | long long | period | ) |
Predicate for the validity of a period.
uint year_2000_handling | ( | uint | year | ) |
Handle 2 digit year conversions.
year | 2 digit year |
longlong year_to_longlong_datetime_packed | ( | long | year | ) |
Convert year to packed numeric date representation.
Packed value for YYYY is the same to packed value for date YYYY-00-00.
|
staticconstexpr |
Day number with 1970-01-01 as base.
const uchar days_in_month[] |
const ulonglong log_10_int[20] |
|
staticconstexpr |
Rounding functions.
|
static |
Offset of system time zone from UTC in seconds used to speed up work of my_system_gmt_sec() function.
const char my_zero_datetime6[] = "0000-00-00 00:00:00.000000" |
|
staticconstexpr |