MySQL 8.0.29
Source Code Documentation
my_time.h
Go to the documentation of this file.
1/* Copyright (c) 2004, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MY_TIME_INCLUDED
24#define MY_TIME_INCLUDED
25
26/**
27 @ingroup MY_TIME
28 @{
29
30 @file include/my_time.h
31
32 Interface for low level time utilities.
33*/
34
35#include "my_config.h"
36
37#include <assert.h> // assert
38#include <algorithm>
39#include <cstddef> // std::size_t
40#include <cstdint> // std::int32_t
41#include <cstring> // strncpy
42#include <limits> // std::numeric_limits
43
44#ifdef HAVE_SYS_TIME_H
45#include <sys/time.h> // struct timeval
46#endif /* HAVE_SYS_TIME_H */
47#ifdef _WIN32
48#include <winsock2.h> // struct timeval
49#endif /* _WIN32 */
50
51#include "my_time_t.h"
52#include "mysql_time.h" // struct MYSQL_TIME, shared with client code
53
54enum enum_field_types : int;
55
56extern const unsigned long long int log_10_int[20];
57extern const unsigned char days_in_month[];
58extern const char my_zero_datetime6[]; /* "0000-00-00 00:00:00.000000" */
59
60constexpr const bool HAVE_64_BITS_TIME_T = sizeof(time_t) == sizeof(my_time_t);
61
62/** Time handling defaults */
63constexpr const int MYTIME_MAX_YEAR = HAVE_64_BITS_TIME_T ? 9999 : 2038;
64constexpr const int TIMESTAMP_MAX_YEAR = 2038;
65
66/** Two-digit years < this are 20XX; >= this are 19XX */
67constexpr const int YY_PART_YEAR = 70;
68constexpr const int MYTIME_MIN_YEAR = (1900 + YY_PART_YEAR - 1);
69
70/** max seconds from epoch of host's time_t stored in my_time_t
71 Windows allows up to 3001-01-18 23:59:59 UTC for localtime_r, so
72 that is our effective limit, although Unixen allow higher time points.
73 Hence the magic constant 32536771199.
74 */
75constexpr const my_time_t MYTIME_MAX_VALUE =
76 HAVE_64_BITS_TIME_T ? 32536771199
77 : std::numeric_limits<std::int32_t>::max();
78
79/**
80 Zero represents the first time value we allow, i.e. UNIX epoch.
81 We do not allow times before UNIX epoch, except for inside computations,
82 hence we use a signed integer as the base type, cf. prepare_tz_info.
83*/
84constexpr const int MYTIME_MIN_VALUE = 0;
85
86/** max seconds from epoch that can be stored in a column of type TIMESTAMP.
87 This also impacts the max value that can be given to SET TIMESTAMP
88*/
89constexpr const std::int64_t TYPE_TIMESTAMP_MAX_VALUE =
90 std::numeric_limits<std::int32_t>::max();
91constexpr const std::int64_t TYPE_TIMESTAMP_MIN_VALUE = 1;
92
93/** Flags to str_to_datetime and number_to_datetime */
94using my_time_flags_t = unsigned int;
95
96/** Allow zero day and zero month */
97constexpr const my_time_flags_t TIME_FUZZY_DATE = 1;
98
99/** Only allow full datetimes. */
101
104
105/** Don't allow zero day or zero month */
107
108/** Don't allow 0000-00-00 date */
110
111/** Allow 2000-02-31 */
113
114/** Allow only HH:MM:SS or MM:SS time formats */
115constexpr const my_time_flags_t TIME_STRICT_COLON = 128;
116
117/** Conversion warnings */
118constexpr const int MYSQL_TIME_WARN_TRUNCATED = 1;
119constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE = 2;
120constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP = 4;
121constexpr const int MYSQL_TIME_WARN_ZERO_DATE = 8;
122constexpr const int MYSQL_TIME_NOTE_TRUNCATED = 16;
123constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE = 32;
124constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW = 64;
125
126/** Useful constants */
127constexpr const int64_t SECONDS_IN_24H = 86400LL;
128
129/** Limits for the TIME data type */
130constexpr const int TIME_MAX_HOUR = 838;
131constexpr const int TIME_MAX_MINUTE = 59;
132constexpr const int TIME_MAX_SECOND = 59;
133
134/**
135 Note that this MUST be a signed type, as we use the unary - operator on it.
136 */
137constexpr const int TIME_MAX_VALUE =
139
140constexpr const int TIME_MAX_VALUE_SECONDS =
142
143constexpr const int DATETIME_MAX_DECIMALS = 6;
144
145constexpr const int SECS_PER_MIN = 60;
146constexpr const int MINS_PER_HOUR = 60;
147constexpr const int HOURS_PER_DAY = 24;
148constexpr const int DAYS_PER_WEEK = 7;
149constexpr const int DAYS_PER_NYEAR = 365;
150constexpr const int DAYS_PER_LYEAR = 366;
151constexpr const int SECS_PER_HOUR = (SECS_PER_MIN * MINS_PER_HOUR);
152constexpr const int SECS_PER_DAY = (SECS_PER_HOUR * HOURS_PER_DAY);
153constexpr const int MONS_PER_YEAR = 12;
154
155constexpr const int MAX_TIME_ZONE_HOURS = 14;
156
157/** Flags for calc_week() function. */
158constexpr const unsigned int WEEK_MONDAY_FIRST = 1;
159constexpr const unsigned int WEEK_YEAR = 2;
160constexpr const unsigned int WEEK_FIRST_WEEKDAY = 4;
161
162/** Daynumber from year 0 to 9999-12-31 */
163constexpr const int64_t MAX_DAY_NUMBER = 3652424;
164
165/**
166 Structure to return status from
167 str_to_datetime(), str_to_time(), number_to_datetime(), number_to_time()
168 @note Implicit default constructor initializes all members to 0.
169*/
171 int warnings{0};
172 unsigned int fractional_digits{0};
173 unsigned int nanoseconds{0};
174 struct DEPRECATION { // We only report first offense
176 DP_NONE, // no deprecated delimiter seen yet
177 DP_WRONG_KIND, // seen a delimiter in correct position, but wrong one
178 DP_WRONG_SPACE, // seen a space delimiter which isn't 0x20 ' '.
179 DP_SUPERFLUOUS // seen a superfluous delimiter
180 } m_kind{DP_NONE};
182 bool m_colon; // for DP_WRONG_KIND: true if we expect ':', else '-'
183 int m_position; // 0-based in m_arg
184 char m_arg[40]; // the string argument we found a deprecation in
186 ///< Register wrong delimiter if it's the first we see for this value
187 ///< @param kind what kind of deprecation did we see
188 ///< @param arg the string we try to interpret as a datetime value
189 ///< @param end points to the character after arg, usually a '\0'
190 ///< @param delim what delimiter was used
191 ///< @param colon used if kind==DP_WRONG_KIND. true: expect ':' else expect'-'
192 void set_deprecation(DEPRECATION::DEPR_KIND kind, const char *arg,
193 const char *end, const char *delim, bool colon = false) {
194 if (m_deprecation.m_kind == DEPRECATION::DP_NONE) {
195 m_deprecation.m_kind = kind;
197 m_deprecation.m_colon = colon;
198 const size_t bufsize = sizeof(m_deprecation.m_arg) - 1; // -1: for '\0'
199 const size_t argsize = end - arg;
200 const size_t size = std::min(bufsize, argsize);
201 std::strncpy(m_deprecation.m_arg, arg, size);
202 m_deprecation.m_arg[size] = '\0';
203 m_deprecation.m_position = delim - arg;
204 }
205 }
206 MYSQL_TIME_STATUS() = default;
208 /// Assignment: don't clobber an existing deprecation, first one wins
210 warnings = b.warnings;
213 // keep first deprecation
214 if (m_deprecation.m_kind == DEPRECATION::DP_NONE) {
216 }
217 return *this;
218 }
220};
221
222/**
223 Struct representing a duration. Content is similar to MYSQL_TIME
224 but member variables are unsigned.
225 */
226struct Interval {
227 unsigned long int year;
228 unsigned long int month;
229 unsigned long int day;
230 unsigned long int hour;
231 unsigned long long int minute;
232 unsigned long long int second;
233 unsigned long long int second_part;
234 bool neg;
235};
236
237void my_init_time();
238
239long calc_daynr(unsigned int year, unsigned int month, unsigned int day);
240unsigned int calc_days_in_year(unsigned int year);
241unsigned int year_2000_handling(unsigned int year);
242
243bool time_zone_displacement_to_seconds(const char *str, size_t length,
244 int *result);
245
246void get_date_from_daynr(int64_t daynr, unsigned int *year, unsigned int *month,
247 unsigned int *day);
248int calc_weekday(long daynr, bool sunday_first_day_of_week);
249bool valid_period(long long int period);
250uint64_t convert_period_to_month(uint64_t period);
251uint64_t convert_month_to_period(uint64_t month);
252
253/**
254 Check for valid my_time_t value. Note: timestamp here pertains to seconds
255 since epoch, not the legacy MySQL type TIMESTAMP, which is limited to
256 32 bits even on 64 bit platforms.
257*/
258inline bool is_time_t_valid_for_timestamp(time_t x) {
259 return (static_cast<int64_t>(x) <= static_cast<int64_t>(MYTIME_MAX_VALUE) &&
260 x >= MYTIME_MIN_VALUE);
261}
262
263unsigned int calc_week(const MYSQL_TIME &l_time, unsigned int week_behaviour,
264 unsigned int *year);
265
266bool check_date(const MYSQL_TIME &ltime, bool not_zero_date,
267 my_time_flags_t flags, int *was_cut);
268bool str_to_datetime(const char *str, std::size_t length, MYSQL_TIME *l_time,
270long long int number_to_datetime(long long int nr, MYSQL_TIME *time_res,
271 my_time_flags_t flags, int *was_cut);
272bool number_to_time(long long int nr, MYSQL_TIME *ltime, int *warnings);
273unsigned long long int TIME_to_ulonglong_datetime(const MYSQL_TIME &my_time);
274unsigned long long int TIME_to_ulonglong_date(const MYSQL_TIME &my_time);
275unsigned long long int TIME_to_ulonglong_time(const MYSQL_TIME &my_time);
276unsigned long long int TIME_to_ulonglong(const MYSQL_TIME &my_time);
277
278unsigned long long int TIME_to_ulonglong_datetime_round(
279 const MYSQL_TIME &my_time, int *warnings);
280unsigned long long int TIME_to_ulonglong_time_round(const MYSQL_TIME &my_time);
281
282/**
283 Round any MYSQL_TIME timepoint and convert to ulonglong.
284 @param my_time input
285 @param[out] warnings warning vector
286 @return time point as ulonglong
287 */
288inline unsigned long long int TIME_to_ulonglong_round(const MYSQL_TIME &my_time,
289 int *warnings) {
290 switch (my_time.time_type) {
297 default:
298 assert(false);
299 return 0;
300 }
301}
302
303/**
304 Extract the microsecond part of a MYSQL_TIME struct as an n *
305 (1/10^6) fraction as a double.
306
307 @return microseconds part as double
308 */
309inline double TIME_microseconds(const MYSQL_TIME &my_time) {
310 return static_cast<double>(my_time.second_part) / 1000000.0;
311}
312
313/**
314 Convert a MYSQL_TIME datetime to double where the integral part is
315 the timepoint as an ulonglong, and the fractional part is the
316 fraction of the second.
317
318 @param my_time datetime to convert
319 @return datetime as double
320 */
322 return static_cast<double>(TIME_to_ulonglong_datetime(my_time)) +
324}
325
326/**
327 Convert a MYSQL_TIME time to double where the integral part is
328 the timepoint as an ulonglong, and the fractional part is the
329 fraction of the second.
330
331 @param my_time time to convert
332 @return datetime as double
333 */
335 return static_cast<double>(TIME_to_ulonglong_time(my_time)) +
337}
338
339/**
340 Convert a MYSQL_TIME to double where the integral part is the
341 timepoint as an ulonglong, and the fractional part is the fraction
342 of the second. The actual time type is extracted from
343 MYSQL_TIME::time_type.
344
345 @param my_time MYSQL_TIME to convert
346 @return MYSQL_TIME as double
347 */
348inline double TIME_to_double(const MYSQL_TIME &my_time) {
349 return static_cast<double>(TIME_to_ulonglong(my_time)) +
351}
352
353/**
354 Return the fraction of the second as the number of microseconds.
355
356 @param i timepoint as longlong
357 @return frational part of an timepoint represented as an (u)longlong
358*/
359inline long long int my_packed_time_get_frac_part(long long int i) {
360 return (i % (1LL << 24));
361}
362
363long long int year_to_longlong_datetime_packed(long year);
367long long int TIME_to_longlong_packed(const MYSQL_TIME &my_time);
368
369void TIME_from_longlong_datetime_packed(MYSQL_TIME *ltime, long long int nr);
370void TIME_from_longlong_time_packed(MYSQL_TIME *ltime, long long int nr);
371void TIME_from_longlong_date_packed(MYSQL_TIME *ltime, long long int nr);
372void TIME_set_yymmdd(MYSQL_TIME *ltime, unsigned int yymmdd);
373void TIME_set_hhmmss(MYSQL_TIME *ltime, unsigned int hhmmss);
374
375void my_datetime_packed_to_binary(long long int nr, unsigned char *ptr,
376 unsigned int dec);
377long long int my_datetime_packed_from_binary(const unsigned char *ptr,
378 unsigned int dec);
379
380void my_time_packed_to_binary(long long int nr, unsigned char *ptr,
381 unsigned int dec);
382long long int my_time_packed_from_binary(const unsigned char *ptr,
383 unsigned int dec);
384
385void my_timestamp_to_binary(const my_timeval *tm, unsigned char *ptr,
386 unsigned int dec);
387void my_timestamp_from_binary(my_timeval *tm, const unsigned char *ptr,
388 unsigned int dec);
389
390bool str_to_time(const char *str, std::size_t length, MYSQL_TIME *l_time,
392
397
398/**
399 Check whether the argument holds a valid UNIX time value
400 (seconds after epoch). This function doesn't make precise check, but rather a
401 rough estimate before time zone adjustments.
402
403 @param my_time timepoint to check
404 @returns true if value satisfies the check above, false otherwise.
405*/
407 if (my_time.year < MYTIME_MIN_YEAR || my_time.year > MYTIME_MAX_YEAR)
408 return false;
409
410 return true;
411}
412
414 bool *in_dst_time_gap);
415
416void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type);
417void set_max_time(MYSQL_TIME *tm, bool neg);
418void set_max_hhmmss(MYSQL_TIME *tm);
419
420/**
421 Required buffer length for my_time_to_str, my_date_to_str,
422 my_datetime_to_str and TIME_to_string functions. Note, that the
423 caller is still responsible to check that given TIME structure
424 has values in valid ranges, otherwise size of the buffer might
425 well be insufficient. We also rely on the fact that even incorrect values
426 sent using binary protocol fit in this buffer.
427*/
428constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH =
429 sizeof("YYYY-MM-DD AM HH:MM:SS.FFFFFF+HH:MM");
430
431int my_time_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
432int my_date_to_str(const MYSQL_TIME &my_time, char *to);
433int my_datetime_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
434int my_TIME_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
435
436void my_date_to_binary(const MYSQL_TIME *ltime, unsigned char *ptr);
437int my_timeval_to_str(const my_timeval *tm, char *to, unsigned int dec);
438
439/**
440 Available interval types used in any statement.
441
442 'interval_type' must be sorted so that simple intervals comes first,
443 ie year, quarter, month, week, day, hour, etc. The order based on
444 interval size is also important and the intervals should be kept in a
445 large to smaller order. (get_interval_value() depends on this)
446
447 @note If you change the order of elements in this enum you should fix
448 order of elements in 'interval_type_to_name' and 'interval_names'
449 arrays
450
451 @see interval_type_to_name, get_interval_value, interval_names
452*/
476
477bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
478 Interval interval, int *warnings);
479
480/**
481 Round the input argument to the specified precision by computing
482 the remainder modulo log10 of the difference between max and
483 desired precison.
484
485 @param nr number to round
486 @param decimals desired precision
487 @return nr rounded according to the desired precision.
488*/
489inline long my_time_fraction_remainder(long nr, unsigned int decimals) {
490 assert(decimals <= DATETIME_MAX_DECIMALS);
491 return nr % static_cast<long>(log_10_int[DATETIME_MAX_DECIMALS - decimals]);
492}
493
494/**
495 Truncate the number of microseconds in MYSQL_TIME::second_part to
496 the desired precision.
497
498 @param ltime time point
499 @param decimals desired precision
500*/
501inline void my_time_trunc(MYSQL_TIME *ltime, unsigned int decimals) {
502 ltime->second_part -=
503 my_time_fraction_remainder(ltime->second_part, decimals);
504}
505
506/**
507 Alias for my_time_trunc.
508
509 @param ltime time point
510 @param decimals desired precision
511 */
512inline void my_datetime_trunc(MYSQL_TIME *ltime, unsigned int decimals) {
513 return my_time_trunc(ltime, decimals);
514}
515
516/**
517 Truncate the tv_usec member of a posix timeval struct to the
518 specified number of decimals.
519
520 @param tv timepoint/duration
521 @param decimals desired precision
522 */
523inline void my_timeval_trunc(my_timeval *tv, unsigned int decimals) {
524 tv->m_tv_usec -= my_time_fraction_remainder(tv->m_tv_usec, decimals);
525}
526
527/**
528 Predicate for fuzzyness of date.
529
530 @param my_time time point to check
531 @param fuzzydate bitfield indicating if fuzzy dates are premitted
532 @retval true if TIME_FUZZY_DATE is unset and either month or day is 0
533 @retval false otherwise
534 */
536 my_time_flags_t fuzzydate) {
537 return !(fuzzydate & TIME_FUZZY_DATE) && (!my_time.month || !my_time.day);
538}
539
540/**
541 Predicate which returns true if at least one of the date members are non-zero.
542
543 @param my_time time point to check.
544 @retval false if all the date members are zero
545 @retval true otherwise
546 */
547inline bool non_zero_date(const MYSQL_TIME &my_time) {
548 return my_time.year || my_time.month || my_time.day;
549}
550
551/**
552 Predicate which returns true if at least one of the time members are non-zero.
553
554 @param my_time time point to check.
555 @retval false if all the time members are zero
556 @retval true otherwise
557*/
558inline bool non_zero_time(const MYSQL_TIME &my_time) {
559 return my_time.hour || my_time.minute || my_time.second ||
560 my_time.second_part;
561}
562
563/**
564 "Casts" MYSQL_TIME datetime to a MYSQL_TIME time. Sets
565 MYSQL_TIME::time_type to MYSQL_TIMESTAMP_TIME and zeroes out the
566 date members.
567
568 @param ltime timepoint to cast
569 */
570inline void datetime_to_time(MYSQL_TIME *ltime) {
571 ltime->year = 0;
572 ltime->month = 0;
573 ltime->day = 0;
575}
576
577/**
578 "Casts" MYSQL_TIME datetime to a MYSQL_TIME date. Sets
579 MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATE and zeroes out the
580 time members.
581
582 @param ltime timepoint to cast
583*/
584inline void datetime_to_date(MYSQL_TIME *ltime) {
585 ltime->hour = 0;
586 ltime->minute = 0;
587 ltime->second = 0;
588 ltime->second_part = 0;
590}
591
592/**
593 "Casts" a MYSQL_TIME to datetime by setting MYSQL_TIME::time_type to
594 MYSQL_TIMESTAMP_DATETIME.
595 @note There is no check to ensure that the result is a valid datetime.
596
597 @param ltime timpoint to cast
598*/
599inline void date_to_datetime(MYSQL_TIME *ltime) {
601}
602
604 unsigned int nanoseconds,
605 int *warnings);
607 unsigned int nanoseconds);
609 unsigned int nanoseconds, int *warnings);
610
612 unsigned int nanoseconds,
613 int *warnings);
614
616 unsigned int nanoseconds, int *warnings,
617 bool truncate);
618
620 unsigned int nanoseconds,
621 int *warnings, bool truncate);
622
623bool my_time_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, bool truncate);
624bool my_datetime_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, int *warnings,
625 bool truncate);
626bool my_timeval_round(my_timeval *tv, unsigned int decimals);
628
629void localtime_to_TIME(MYSQL_TIME *to, const struct tm *from);
630void calc_time_from_sec(MYSQL_TIME *to, long long int seconds,
631 long microseconds);
632bool calc_time_diff(const MYSQL_TIME &my_time1, const MYSQL_TIME &my_time2,
633 int l_sign, long long int *seconds_out,
634 long *microseconds_out);
635int my_time_compare(const MYSQL_TIME &my_time_a, const MYSQL_TIME &my_time_b);
636
637long long int TIME_to_longlong_packed(const MYSQL_TIME &my_time,
639
641 long long int packed_value);
642
644 long long int packed_value);
645
647 long long int packed_value);
648
649/**
650 @} (end of ingroup MY_TIME)
651*/
652#endif /* MY_TIME_INCLUDED */
enum_field_types
Column types for MySQL.
Definition: field_types.h:57
static const std::string dec("DECRYPTION")
bool my_time_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, bool truncate)
Round/Truncate time value to the given precision.
Definition: my_time.cc:2566
void TIME_set_yymmdd(MYSQL_TIME *ltime, unsigned int yymmdd)
Set day, month and year from a number.
Definition: my_time.cc:1571
unsigned long long int TIME_to_ulonglong_date(const MYSQL_TIME &my_time)
Convert MYSQL_TIME value to integer in YYYYMMDD format.
Definition: my_time.cc:1547
unsigned int calc_days_in_year(unsigned int year)
Calc days in one year.
Definition: my_time.cc:133
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 second...
Definition: my_time.cc:1078
long long int TIME_to_longlong_time_packed(const MYSQL_TIME &my_time)
Convert time value to numeric packed representation.
Definition: my_time.cc:1688
uint64_t convert_month_to_period(uint64_t month)
Convert month to period.
Definition: my_time.cc:2261
bool datetime_add_nanoseconds_with_round(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
Add nanoseconds to a datetime value with rounding.
Definition: my_time.cc:2493
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 YYY...
Definition: my_time.cc:1610
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.
Definition: my_time.cc:2850
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.
Definition: my_time.cc:364
void localtime_to_TIME(MYSQL_TIME *to, const struct tm *from)
Converts a timepoint in a posix tm struct to a MYSQL_TIME struct.
Definition: my_time.cc:2671
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.
Definition: my_time.cc:2723
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.
Definition: my_time.cc:2545
void TIME_from_longlong_time_packed(MYSQL_TIME *ltime, long long int nr)
Convert time packed numeric representation to time.
Definition: my_time.cc:1702
bool datetime_add_nanoseconds_with_truncate(MYSQL_TIME *ltime, unsigned int nanoseconds)
Add nanoseconds to a datetime value with truncation.
Definition: my_time.cc:2430
unsigned long long int TIME_to_ulonglong_time(const MYSQL_TIME &my_time)
Convert MYSQL_TIME value to integer in HHMMSS format.
Definition: my_time.cc:1560
void set_max_time(MYSQL_TIME *tm, bool neg)
Set MYSQL_TIME variable to maximum time value.
Definition: my_time.cc:163
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.
Definition: my_time.cc:276
void my_timestamp_from_binary(my_timeval *tm, const unsigned char *ptr, unsigned int dec)
Convert binary timestamp representation to in-memory representation.
Definition: my_time.cc:2015
const char my_zero_datetime6[]
Definition: my_time.cc:83
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.
Definition: my_time.cc:188
long long int year_to_longlong_datetime_packed(long year)
Convert year to packed numeric date representation.
Definition: my_time.cc:1886
void set_max_hhmmss(MYSQL_TIME *tm)
Set hour, minute and second of a MYSQL_TIME variable to maximum time value.
Definition: my_time.cc:152
int my_time_compare(const MYSQL_TIME &my_time_a, const MYSQL_TIME &my_time_b)
Compare tow MYSQL_TIME objects.
Definition: my_time.cc:2777
void TIME_from_longlong_date_packed(MYSQL_TIME *ltime, long long int nr)
Convert packed numeric date representation to MYSQL_TIME.
Definition: my_time.cc:1930
bool my_datetime_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, int *warnings, bool truncate)
Round/Truncate datetime value to the given precision.
Definition: my_time.cc:2588
bool check_time_range_quick(const MYSQL_TIME &my_time)
Check TIME range.
Definition: my_time.cc:234
void my_init_time()
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
Definition: my_time.cc:996
bool check_datetime_range(const MYSQL_TIME &my_time)
Check datetime, date, or normalized time (i.e.
Definition: my_time.cc:251
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.
Definition: my_time.cc:2687
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.
Definition: my_time.cc:2087
void mix_date_and_time(MYSQL_TIME *ldate, const MYSQL_TIME &my_time)
Mix a date value and a time value.
Definition: my_time.cc:2630
void adjust_time_range(MYSQL_TIME *, int *warning)
Adjust 'time' value to lie in the MYSQL_TIME range.
Definition: my_time.cc:984
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'.
Definition: my_time.cc:1312
const ulonglong log_10_int[20]
Definition: my_time.cc:62
const uchar days_in_month[]
Definition: my_time.cc:89
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.
Definition: my_time.cc:1949
unsigned int year_2000_handling(unsigned int year)
Handle 2 digit year conversions.
Definition: my_time.cc:1025
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.
Definition: my_time.cc:1652
void get_date_from_daynr(int64_t daynr, unsigned int *year, unsigned int *month, unsigned int *day)
Change a daynr to year, month and day.
Definition: my_time.cc:2109
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.
Definition: my_time.cc:2821
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, Interval interval, int *warnings)
Add an interval to a MYSQL_TIME struct.
Definition: my_time.cc:2276
void my_date_to_binary(const MYSQL_TIME *ltime, unsigned char *ptr)
Convert in-memory date representation to on-disk representation.
Definition: my_time.cc:2075
unsigned long long int TIME_to_ulonglong_datetime(const MYSQL_TIME &my_time)
Convert time value to integer in YYYYMMDDHHMMSS.
Definition: my_time.cc:1533
int my_datetime_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec)
Print a datetime value with an optional fractional part.
Definition: my_time.cc:1366
bool my_timeval_round(my_timeval *tv, unsigned int decimals)
Round timeval value to the given precision.
Definition: my_time.cc:2606
void TIME_set_hhmmss(MYSQL_TIME *ltime, unsigned int hhmmss)
Set hour, minute and secondr from a number.
Definition: my_time.cc:1583
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.
Definition: my_time.cc:1635
long long int TIME_to_longlong_datetime_packed(const MYSQL_TIME &my_time)
Convert datetime to packed numeric datetime representation.
Definition: my_time.cc:1859
bool time_add_nanoseconds_with_truncate(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
Add nanoseconds to a time value with truncation.
Definition: my_time.cc:2410
bool number_to_time(long long int nr, MYSQL_TIME *ltime, int *warnings)
Convert number to TIME.
Definition: my_time.cc:943
double double_from_datetime_packed(enum enum_field_types type, long long int packed_value)
Convert packed numeric temporal representation to unpacked numeric representation.
Definition: my_time.cc:2880
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.
Definition: my_time.cc:1733
uint64_t convert_period_to_month(uint64_t period)
Calculate month from period.
Definition: my_time.cc:2244
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.
Definition: my_time.cc:143
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.
Definition: my_time.cc:736
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 DATET...
Definition: my_time.cc:1452
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.
Definition: my_time.cc:1773
bool time_add_nanoseconds_with_round(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
Add nanoseconds to a time value with rounding.
Definition: my_time.cc:2449
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.
Definition: my_time.cc:1980
int my_timeval_to_str(const my_timeval *tm, char *to, unsigned int dec)
Print a timestamp with an oprional fractional part: XXXXX[.YYYYY].
Definition: my_time.cc:1416
bool check_time_mmssff_range(const MYSQL_TIME &my_time)
Check if TIME fields can be adjusted to make the time value valid.
Definition: my_time.cc:217
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).
Definition: my_time.cc:1041
void TIME_from_longlong_datetime_packed(MYSQL_TIME *ltime, long long int nr)
Convert packed numeric datetime representation to MYSQL_TIME.
Definition: my_time.cc:1897
int calc_weekday(long daynr, bool sunday_first_day_of_week)
Calc weekday from daynr.
Definition: my_time.cc:2151
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.
Definition: my_time.cc:2193
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.
Definition: my_time.cc:2527
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.
Definition: my_time.cc:1389
long long int TIME_to_longlong_date_packed(const MYSQL_TIME &my_time)
Convert date to packed numeric date representation.
Definition: my_time.cc:1875
void my_timestamp_to_binary(const my_timeval *tm, unsigned char *ptr, unsigned int dec)
Convert in-memory timestamp representation to on-disk representation.
Definition: my_time.cc:2044
int my_time_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec)
Converts a time value to a string with the format HH:MM:SS[.fraction].
Definition: my_time.cc:1282
static int flags[50]
Definition: hp_test1.cc:39
time_t my_time(int)
Return current time.
Definition: my_systime.h:170
void my_time_trunc(MYSQL_TIME *ltime, unsigned int decimals)
Truncate the number of microseconds in MYSQL_TIME::second_part to the desired precision.
Definition: my_time.h:501
constexpr const int DAYS_PER_LYEAR
Definition: my_time.h:150
void date_to_datetime(MYSQL_TIME *ltime)
"Casts" a MYSQL_TIME to datetime by setting MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATETIME.
Definition: my_time.h:599
constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE
Don't allow zero day or zero month.
Definition: my_time.h:106
bool validate_my_time(const MYSQL_TIME &my_time)
Check whether the argument holds a valid UNIX time value (seconds after epoch).
Definition: my_time.h:406
long long int my_packed_time_get_frac_part(long long int i)
Return the fraction of the second as the number of microseconds.
Definition: my_time.h:359
void my_datetime_trunc(MYSQL_TIME *ltime, unsigned int decimals)
Alias for my_time_trunc.
Definition: my_time.h:512
constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP
Definition: my_time.h:120
constexpr const my_time_flags_t TIME_INVALID_DATES
Allow 2000-02-31.
Definition: my_time.h:112
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,...
Definition: my_time.h:348
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,...
Definition: my_time.h:334
constexpr const int MYSQL_TIME_NOTE_TRUNCATED
Definition: my_time.h:122
bool non_zero_date(const MYSQL_TIME &my_time)
Predicate which returns true if at least one of the date members are non-zero.
Definition: my_time.h:547
constexpr const int MYSQL_TIME_WARN_TRUNCATED
Conversion warnings.
Definition: my_time.h:118
constexpr const unsigned int WEEK_FIRST_WEEKDAY
Definition: my_time.h:160
constexpr const int MINS_PER_HOUR
Definition: my_time.h:146
constexpr const my_time_flags_t TIME_DATETIME_ONLY
Only allow full datetimes.
Definition: my_time.h:100
constexpr const int TIME_MAX_HOUR
Limits for the TIME data type.
Definition: my_time.h:130
constexpr const unsigned int WEEK_YEAR
Definition: my_time.h:159
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.
Definition: my_time.h:309
constexpr const my_time_flags_t TIME_NO_ZERO_DATE
Don't allow 0000-00-00 date.
Definition: my_time.h:109
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:143
constexpr const int MAX_TIME_ZONE_HOURS
Definition: my_time.h:155
constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW
Definition: my_time.h:124
constexpr const int HOURS_PER_DAY
Definition: my_time.h:147
constexpr const int TIME_MAX_MINUTE
Definition: my_time.h:131
bool check_fuzzy_date(const MYSQL_TIME &my_time, my_time_flags_t fuzzydate)
Predicate for fuzzyness of date.
Definition: my_time.h:535
constexpr const int64_t MAX_DAY_NUMBER
Daynumber from year 0 to 9999-12-31.
Definition: my_time.h:163
constexpr const int DAYS_PER_NYEAR
Definition: my_time.h:149
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.
Definition: my_time.h:523
void datetime_to_date(MYSQL_TIME *ltime)
"Casts" MYSQL_TIME datetime to a MYSQL_TIME date.
Definition: my_time.h:584
constexpr const int SECS_PER_DAY
Definition: my_time.h:152
constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE
Definition: my_time.h:123
constexpr const my_time_flags_t TIME_FUZZY_DATE
Allow zero day and zero month.
Definition: my_time.h:97
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 di...
Definition: my_time.h:489
constexpr const int TIME_MAX_VALUE
Note that this MUST be a signed type, as we use the unary - operator on it.
Definition: my_time.h:137
bool is_time_t_valid_for_timestamp(time_t x)
Check for valid my_time_t value.
Definition: my_time.h:258
constexpr const int TIME_MAX_VALUE_SECONDS
Definition: my_time.h:140
constexpr const int64_t SECONDS_IN_24H
Useful constants.
Definition: my_time.h:127
constexpr const int TIME_MAX_SECOND
Definition: my_time.h:132
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,...
Definition: my_time.h:321
void datetime_to_time(MYSQL_TIME *ltime)
"Casts" MYSQL_TIME datetime to a MYSQL_TIME time.
Definition: my_time.h:570
unsigned long long int TIME_to_ulonglong_round(const MYSQL_TIME &my_time, int *warnings)
Round any MYSQL_TIME timepoint and convert to ulonglong.
Definition: my_time.h:288
constexpr const my_time_flags_t TIME_NO_DATE_FRAC_WARN
Definition: my_time.h:103
bool non_zero_time(const MYSQL_TIME &my_time)
Predicate which returns true if at least one of the time members are non-zero.
Definition: my_time.h:558
constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE
Definition: my_time.h:119
constexpr const int MONS_PER_YEAR
Definition: my_time.h:153
bool valid_period(long long int period)
unsigned int my_time_flags_t
Time handling defaults.
constexpr const unsigned int WEEK_MONDAY_FIRST
Flags for calc_week() function.
Definition: my_time.h:158
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 func...
Definition: my_time.h:428
constexpr const int MYSQL_TIME_WARN_ZERO_DATE
Definition: my_time.h:121
constexpr const int DAYS_PER_WEEK
Definition: my_time.h:148
constexpr const my_time_flags_t TIME_FRAC_TRUNCATE
Definition: my_time.h:102
interval_type
Available interval types used in any statement.
Definition: my_time.h:453
@ INTERVAL_HOUR_SECOND
Definition: my_time.h:468
@ INTERVAL_MONTH
Definition: my_time.h:456
@ INTERVAL_HOUR_MICROSECOND
Definition: my_time.h:471
@ INTERVAL_MINUTE
Definition: my_time.h:460
@ INTERVAL_HOUR_MINUTE
Definition: my_time.h:467
@ INTERVAL_DAY
Definition: my_time.h:458
@ INTERVAL_LAST
Definition: my_time.h:474
@ INTERVAL_MINUTE_MICROSECOND
Definition: my_time.h:472
@ INTERVAL_MINUTE_SECOND
Definition: my_time.h:469
@ INTERVAL_QUARTER
Definition: my_time.h:455
@ INTERVAL_YEAR
Definition: my_time.h:454
@ INTERVAL_WEEK
Definition: my_time.h:457
@ INTERVAL_DAY_MICROSECOND
Definition: my_time.h:470
@ INTERVAL_SECOND_MICROSECOND
Definition: my_time.h:473
@ INTERVAL_SECOND
Definition: my_time.h:461
@ INTERVAL_DAY_HOUR
Definition: my_time.h:464
@ INTERVAL_HOUR
Definition: my_time.h:459
@ INTERVAL_YEAR_MONTH
Definition: my_time.h:463
@ INTERVAL_DAY_SECOND
Definition: my_time.h:466
@ INTERVAL_MICROSECOND
Definition: my_time.h:462
@ INTERVAL_DAY_MINUTE
Definition: my_time.h:465
constexpr const int SECS_PER_MIN
Definition: my_time.h:145
constexpr const int SECS_PER_HOUR
Definition: my_time.h:151
constexpr const my_time_flags_t TIME_STRICT_COLON
Allow only HH:MM:SS or MM:SS time formats.
Definition: my_time.h:115
int64_t my_time_t
Portable time_t replacement.
Definition: my_time_t.h:31
Time declarations shared between the server and client API: you should not add anything to this heade...
enum_mysql_timestamp_type
Definition: mysql_time.h:44
@ MYSQL_TIMESTAMP_TIME
Stores hour, minute, second and microsecond.
Definition: mysql_time.h:59
@ MYSQL_TIMESTAMP_DATETIME
Stores all date and time components.
Definition: mysql_time.h:56
@ MYSQL_TIMESTAMP_DATE
Stores year, month and day components.
Definition: mysql_time.h:49
static int interval
Definition: mysqladmin.cc:64
void warning(const char *format,...)
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1055
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:60
required string type
Definition: replication_group_member_actions.proto:33
Struct representing a duration.
Definition: my_time.h:226
bool neg
Definition: my_time.h:234
unsigned long long int second
Definition: my_time.h:232
unsigned long long int second_part
Definition: my_time.h:233
unsigned long int hour
Definition: my_time.h:230
unsigned long int day
Definition: my_time.h:229
unsigned long int month
Definition: my_time.h:228
unsigned long int year
Definition: my_time.h:227
unsigned long long int minute
Definition: my_time.h:231
Definition: my_time.h:174
DEPR_KIND
Definition: my_time.h:175
@ DP_SUPERFLUOUS
Definition: my_time.h:179
@ DP_WRONG_SPACE
Definition: my_time.h:178
@ DP_NONE
Definition: my_time.h:176
@ DP_WRONG_KIND
Definition: my_time.h:177
char m_delim_seen
Definition: my_time.h:181
char m_arg[40]
Definition: my_time.h:184
enum MYSQL_TIME_STATUS::DEPRECATION::DEPR_KIND DP_NONE
int m_position
Definition: my_time.h:183
bool m_colon
Definition: my_time.h:182
Structure to return status from str_to_datetime(), str_to_time(), number_to_datetime(),...
Definition: my_time.h:170
unsigned int nanoseconds
Definition: my_time.h:173
MYSQL_TIME_STATUS()=default
struct MYSQL_TIME_STATUS::DEPRECATION m_deprecation
Register wrong delimiter if it's the first we see for this value.
void squelch_deprecation()
Definition: my_time.h:219
void set_deprecation(DEPRECATION::DEPR_KIND kind, const char *arg, const char *end, const char *delim, bool colon=false)
Definition: my_time.h:192
MYSQL_TIME_STATUS & operator=(const MYSQL_TIME_STATUS &b)
Assignment: don't clobber an existing deprecation, first one wins.
Definition: my_time.h:209
int warnings
Definition: my_time.h:171
unsigned int fractional_digits
Definition: my_time.h:172
MYSQL_TIME_STATUS(const MYSQL_TIME_STATUS &)=default
Definition: mysql_time.h:81
unsigned long second_part
microseconds
Definition: mysql_time.h:83
unsigned int second
Definition: mysql_time.h:82
enum enum_mysql_timestamp_type time_type
Definition: mysql_time.h:85
unsigned int hour
Definition: mysql_time.h:82
unsigned int minute
Definition: mysql_time.h:82
unsigned int month
Definition: mysql_time.h:82
unsigned int day
Definition: mysql_time.h:82
unsigned int year
Definition: mysql_time.h:82
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:44
int64_t m_tv_usec
Definition: my_time_t.h:46
Definition: result.h:29
double seconds()
Definition: task.cc:309
Include file for Sun RPC to compile out of the box.