MySQL 9.7.0
Source Code Documentation
my_time.h
Go to the documentation of this file.
1/* Copyright (c) 2004, 2026, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MY_TIME_INCLUDED
25#define MY_TIME_INCLUDED
26
27/**
28 @ingroup MY_TIME
29 @{
30
31 @file include/my_time.h
32
33 Interface for low level time utilities.
34*/
35
36#include <time.h> // time_t
37#include <algorithm>
38#include <cassert> // assert
39#include <cstdint> // std::int32_t
40#include <cstring> // strncpy
41#include <limits> // std::numeric_limits
42
43#include "field_types.h"
44#include "my_time_t.h"
45#include "mysql_time.h" // struct MYSQL_TIME, shared with client code
46
47class Date_val;
48
49extern const unsigned long long int log_10_int[20];
50extern const unsigned char days_in_month[];
51extern const char my_zero_datetime6[]; /* "0000-00-00 00:00:00.000000" */
52
53constexpr const bool HAVE_64_BITS_TIME_T = sizeof(time_t) == sizeof(my_time_t);
54
55/** Time handling defaults */
56constexpr const int MYTIME_MAX_YEAR = HAVE_64_BITS_TIME_T ? 9999 : 2038;
57constexpr const int TIMESTAMP_MAX_YEAR = 2038;
58
59/** Two-digit years < this are 20XX; >= this are 19XX */
60constexpr const int YY_PART_YEAR = 70;
61constexpr const int MYTIME_MIN_YEAR = (1900 + YY_PART_YEAR - 1);
62
63/** max seconds from epoch of host's time_t stored in my_time_t
64 Windows allows up to 3001-01-18 23:59:59 UTC for localtime_r, so
65 that is our effective limit, although Unixen allow higher time points.
66 Hence the magic constant 32536771199.
67 */
68constexpr const my_time_t MYTIME_MAX_VALUE =
69 HAVE_64_BITS_TIME_T ? 32536771199
71
72/**
73 Zero represents the first time value we allow, i.e. UNIX epoch.
74 We do not allow times before UNIX epoch, except for inside computations,
75 hence we use a signed integer as the base type, cf. prepare_tz_info.
76*/
77constexpr const int MYTIME_MIN_VALUE = 0;
78
79/** max seconds from epoch that can be stored in a column of type TIMESTAMP.
80 This also impacts the max value that can be given to SET TIMESTAMP
81*/
82constexpr const std::int64_t TYPE_TIMESTAMP_MAX_VALUE =
84constexpr const std::int64_t TYPE_TIMESTAMP_MIN_VALUE = 1;
85
86/** Flags to str_to_datetime and int_to_datetime */
87using my_time_flags_t = unsigned int;
88
89/** No flags: default behavior */
90constexpr const my_time_flags_t TIME_NO_FLAGS = 0x00;
91
92/** Only allow full datetimes. */
93constexpr const my_time_flags_t TIME_DATETIME_ONLY = 0x01;
94
95/** Whether to truncate or round fractional time component */
96constexpr const my_time_flags_t TIME_FRAC_TRUNCATE = 0x02;
97
98/** Whether to warn if a fractional time component is rounded or truncated */
100
101/** Don't allow zero day or zero month */
103
104/** Don't allow 0000-00-00 date */
105constexpr const my_time_flags_t TIME_NO_ZERO_DATE = 0x10;
106
107/** Don't allow invalid dates like 2000-02-31 */
109
110/** Allow only valid dates, no zero date, no zero date component */
113
114/** Allow only HH:MM:SS or MM:SS time formats */
115constexpr const my_time_flags_t TIME_STRICT_COLON = 0x40;
116
117/** Allow exact dates only (or dates where time component is 00:00:00) */
119
120/** Conversion warnings */
121constexpr const int MYSQL_TIME_WARN_TRUNCATED = 1;
122constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE = 2;
123constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP = 4;
124constexpr const int MYSQL_TIME_WARN_ZERO_DATE = 8;
125constexpr const int MYSQL_TIME_NOTE_TRUNCATED = 16;
126constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE = 32;
127constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW = 64;
128
129/** Useful constants */
130constexpr const int64_t SECONDS_IN_24H = 86400LL;
131
132/** Limits for the TIME data type */
133constexpr const int TIME_MAX_HOUR = 838;
134constexpr const int TIME_MAX_MINUTE = 59;
135constexpr const int TIME_MAX_SECOND = 59;
136
137/**
138 Note that this MUST be a signed type, as we use the unary - operator on it.
139 */
140constexpr const int TIME_MAX_VALUE =
142
143constexpr const int TIME_MAX_VALUE_SECONDS =
145
146constexpr const int DATETIME_MAX_DECIMALS = 6;
147
148constexpr const int SECS_PER_MIN = 60;
149constexpr const int MINS_PER_HOUR = 60;
150constexpr const int HOURS_PER_DAY = 24;
151constexpr const int DAYS_PER_WEEK = 7;
152constexpr const int DAYS_PER_NYEAR = 365;
153constexpr const int DAYS_PER_LYEAR = 366;
154constexpr const int SECS_PER_HOUR = (SECS_PER_MIN * MINS_PER_HOUR);
155constexpr const int SECS_PER_DAY = (SECS_PER_HOUR * HOURS_PER_DAY);
156constexpr const int MONS_PER_YEAR = 12;
157
158constexpr const int MAX_TIME_ZONE_HOURS = 14;
159
160/** Flags for calc_week() function. */
161constexpr const unsigned int WEEK_MONDAY_FIRST = 1;
162constexpr const unsigned int WEEK_YEAR = 2;
163constexpr const unsigned int WEEK_FIRST_WEEKDAY = 4;
164
165/** Daynumber from year 0 to 9999-12-31 */
166constexpr const int64_t MAX_DAY_NUMBER = 3652424;
167
168/**
169 Structure to return status from
170 str_to_datetime(), str_to_time(), int_to_datetime(), int_to_time()
171 @note Implicit default constructor initializes all members to 0.
172*/
174 int warnings{0};
175 unsigned int fractional_digits{0};
176 unsigned int nanoseconds{0};
177 struct DEPRECATION { // We only report first offense
179 DP_NONE, // no deprecated delimiter seen yet
180 DP_WRONG_KIND, // seen a delimiter in correct position, but wrong one
181 DP_WRONG_SPACE, // seen a space delimiter which isn't 0x20 ' '.
182 DP_SUPERFLUOUS // seen a superfluous delimiter
183 } m_kind{DP_NONE};
185 bool m_colon; // for DP_WRONG_KIND: true if we expect ':', else '-'
186 int m_position; // 0-based in m_arg
187 char m_arg[40]; // the string argument we found a deprecation in
189 ///< Register wrong delimiter if it's the first we see for this value
190 ///< @param kind what kind of deprecation did we see
191 ///< @param arg the string we try to interpret as a datetime value
192 ///< @param end points to the character after arg, usually a '\0'
193 ///< @param delim what delimiter was used
194 ///< @param colon used if kind==DP_WRONG_KIND. true: expect ':' else expect'-'
195 void set_deprecation(DEPRECATION::DEPR_KIND kind, const char *arg,
196 const char *end, const char *delim, bool colon = false) {
197 if (m_deprecation.m_kind == DEPRECATION::DP_NONE) {
198 m_deprecation.m_kind = kind;
200 m_deprecation.m_colon = colon;
201 const size_t bufsize = sizeof(m_deprecation.m_arg) - 1; // -1: for '\0'
202 const size_t argsize = end - arg;
203 const size_t size = std::min(bufsize, argsize);
204 // The input string is not necessarily zero-terminated,
205 // so do not use snprintf().
206 std::strncpy(m_deprecation.m_arg, arg, size);
207 m_deprecation.m_arg[size] = '\0';
208 m_deprecation.m_position = delim - arg;
209 }
210 }
211 MYSQL_TIME_STATUS() = default;
213 /// Assignment: don't clobber an existing deprecation, first one wins
215 warnings = b.warnings;
218 // keep first deprecation
219 if (m_deprecation.m_kind == DEPRECATION::DP_NONE) {
221 }
222 return *this;
223 }
225};
226
227/**
228 Struct representing a duration. Content is similar to MYSQL_TIME
229 but member variables are unsigned.
230 */
231struct Interval {
232 unsigned long int year{0};
233 unsigned long int month{0};
234 unsigned long int day{0};
235 unsigned long int hour{0};
236 unsigned long long int minute{0};
237 unsigned long long int second{0};
238 unsigned long long int second_part{0};
239 bool neg{false};
240};
241
242void my_init_time();
243
244long calc_daynr(unsigned int year, unsigned int month, unsigned int day);
245unsigned int calc_days_in_year(unsigned int year);
246unsigned int year_2000_handling(unsigned int year);
247
248bool time_zone_displacement_to_seconds(const char *str, size_t length,
249 int *result);
250
251void get_date_from_daynr(int64_t daynr, unsigned int *year, unsigned int *month,
252 unsigned int *day);
253int calc_weekday(long daynr, bool sunday_first_day_of_week);
254bool valid_period(long long int period);
255uint64_t convert_period_to_month(uint64_t period);
256uint64_t convert_month_to_period(uint64_t month);
257
258/**
259 Check for valid my_time_t value. Note: timestamp here pertains to seconds
260 since epoch, not the legacy MySQL type TIMESTAMP, which is limited to
261 32 bits even on 64 bit platforms.
262*/
263inline bool is_time_t_valid_for_timestamp(time_t x) {
264 return (static_cast<int64_t>(x) <= static_cast<int64_t>(MYTIME_MAX_VALUE) &&
265 x >= MYTIME_MIN_VALUE);
266}
267
268unsigned int calc_week(const MYSQL_TIME &l_time, unsigned int week_behaviour,
269 unsigned int *year);
270
271bool check_date(const MYSQL_TIME &ltime, bool not_zero_date,
272 my_time_flags_t flags, int *was_cut);
273bool str_to_datetime(const char *str, std::size_t length, MYSQL_TIME *l_time,
275long long int int_to_datetime(long long int nr, MYSQL_TIME *time_res,
276 my_time_flags_t flags, int *was_cut);
277bool int_to_time(long long int nr, MYSQL_TIME *ltime, int *warnings);
278bool int_to_date(long long int nr, Date_val *date, my_time_flags_t,
279 int *warnings);
280unsigned long long int TIME_to_ulonglong_datetime(const MYSQL_TIME &my_time);
281unsigned long long int TIME_to_ulonglong_date(const MYSQL_TIME &my_time);
282unsigned long long int TIME_to_ulonglong_time(const MYSQL_TIME &my_time);
283unsigned long long int TIME_to_ulonglong(const MYSQL_TIME &my_time);
284
285unsigned long long int TIME_to_ulonglong_datetime_round(
286 const MYSQL_TIME &my_time, int *warnings);
287unsigned long long int TIME_to_ulonglong_time_round(const MYSQL_TIME &my_time);
288
289/**
290 Round any MYSQL_TIME timepoint and convert to ulonglong.
291 @param my_time input
292 @param[out] warnings warning vector
293 @return time point as ulonglong
294 */
295inline unsigned long long int TIME_to_ulonglong_round(const MYSQL_TIME &my_time,
296 int *warnings) {
297 switch (my_time.time_type) {
304 default:
305 assert(false);
306 return 0;
307 }
308}
309
310/**
311 Extract the microsecond part of a MYSQL_TIME struct as an n *
312 (1/10^6) fraction as a double.
313
314 @return microseconds part as double
315 */
316inline double TIME_microseconds(const MYSQL_TIME &my_time) {
317 return static_cast<double>(my_time.second_part) / 1000000.0;
318}
319
320/**
321 Convert a MYSQL_TIME datetime to double where the integral part is
322 the timepoint as an ulonglong, and the fractional part is the
323 fraction of the second.
324
325 @param my_time datetime to convert
326 @return datetime as double
327 */
329 return static_cast<double>(TIME_to_ulonglong_datetime(my_time)) +
331}
332
333/**
334 Convert a MYSQL_TIME time to double where the integral part is
335 the timepoint as an ulonglong, and the fractional part is the
336 fraction of the second.
337
338 @param my_time time to convert
339 @return datetime as double
340 */
342 return static_cast<double>(TIME_to_ulonglong_time(my_time)) +
344}
345
346/**
347 Convert a MYSQL_TIME to double where the integral part is the
348 timepoint as an ulonglong, and the fractional part is the fraction
349 of the second. The actual time type is extracted from
350 MYSQL_TIME::time_type.
351
352 @param my_time MYSQL_TIME to convert
353 @return MYSQL_TIME as double
354 */
355inline double TIME_to_double(const MYSQL_TIME &my_time) {
356 return static_cast<double>(TIME_to_ulonglong(my_time)) +
358}
359
360/**
361 Return the fraction of the second as the number of microseconds.
362
363 @param i timepoint as longlong
364 @return frational part of an timepoint represented as an (u)longlong
365*/
366inline long long int my_packed_time_get_frac_part(long long int i) {
367 return (i % (1LL << 24));
368}
369
370long long int year_to_longlong_datetime_packed(long year);
373long long int TIME_to_longlong_packed(const MYSQL_TIME &my_time);
374
375void TIME_from_longlong_datetime_packed(MYSQL_TIME *ltime, long long int nr);
376void TIME_set_yymmdd(MYSQL_TIME *ltime, unsigned int yymmdd);
377void TIME_set_hhmmss(MYSQL_TIME *ltime, unsigned int hhmmss);
378
379void my_datetime_packed_to_binary(long long int nr, unsigned char *ptr,
380 unsigned int dec);
381long long int my_datetime_packed_from_binary(const unsigned char *ptr,
382 unsigned int dec);
383
384void my_timestamp_to_binary(const my_timeval *tm, unsigned char *ptr,
385 unsigned int dec);
386void my_timestamp_from_binary(my_timeval *tm, const unsigned char *ptr,
387 unsigned int dec);
388
389bool str_to_time(const char *str, std::size_t length, MYSQL_TIME *l_time,
391
396
397/**
398 Check whether the argument holds a valid UNIX time value
399 (seconds after epoch). This function doesn't make precise check, but rather a
400 rough estimate before time zone adjustments.
401
402 @param my_time timepoint to check
403 @returns true if value satisfies the check above, false otherwise.
404*/
406 if (my_time.year < MYTIME_MIN_YEAR || my_time.year > MYTIME_MAX_YEAR)
407 return false;
408
409 return true;
410}
411
413 bool *in_dst_time_gap);
414
415void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type);
416void set_max_time(MYSQL_TIME *tm, bool neg);
417void set_max_hhmmss(MYSQL_TIME *tm);
418
419/**
420 Required buffer length for my_time_to_str, my_date_to_str,
421 my_datetime_to_str and TIME_to_string functions. Note, that the
422 caller is still responsible to check that given TIME structure
423 has values in valid ranges, otherwise size of the buffer might
424 well be insufficient. We also rely on the fact that even incorrect values
425 sent using binary protocol fit in this buffer.
426*/
427constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH =
428 sizeof("YYYY-MM-DD AM HH:MM:SS.FFFFFF+HH:MM");
429
430int my_time_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
431int my_date_to_str(const MYSQL_TIME &my_time, char *to);
432int my_datetime_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
433int my_TIME_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
434
435int my_timeval_to_str(const my_timeval *tm, char *to, unsigned int dec);
436
437/**
438 Available interval types used in any statement.
439
440 'interval_type' must be sorted so that simple intervals comes first,
441 ie year, quarter, month, week, day, hour, etc. The order based on
442 interval size is also important and the intervals should be kept in a
443 large to smaller order. (get_interval_value() depends on this)
444
445 @note If you change the order of elements in this enum you should fix
446 order of elements in 'interval_type_to_name' and 'interval_names'
447 arrays
448
449 @see interval_type_to_name, get_interval_value, interval_names
450*/
474
475bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
476 Interval interval, int *warnings);
477
478/**
479 Round the input argument to the specified precision by computing
480 the remainder modulo log10 of the difference between max and
481 desired precision.
482
483 @param nr number to round
484 @param decimals desired precision
485 @return nr rounded according to the desired precision.
486*/
487inline long my_time_fraction_remainder(long nr, unsigned int decimals) {
488 assert(decimals <= DATETIME_MAX_DECIMALS);
489 return nr % static_cast<long>(log_10_int[DATETIME_MAX_DECIMALS - decimals]);
490}
491
492/**
493 Truncate the number of microseconds in MYSQL_TIME::second_part to
494 the desired precision.
495
496 @param ltime time point
497 @param decimals desired precision
498*/
499inline void my_time_trunc(MYSQL_TIME *ltime, unsigned int decimals) {
500 assert(ltime->time_type == MYSQL_TIMESTAMP_TIME || !ltime->neg);
501 ltime->second_part -=
502 my_time_fraction_remainder(ltime->second_part, decimals);
503 // "Negative zero" time is not defined:
504 if (ltime->time_type == MYSQL_TIMESTAMP_TIME && ltime->neg &&
505 ltime->hour == 0 && ltime->minute == 0 && ltime->second == 0 &&
506 ltime->second_part == 0) {
507 ltime->neg = false;
508 }
509}
510
511/**
512 Alias for my_time_trunc.
513
514 @param ltime time point
515 @param decimals desired precision
516 */
517inline void my_datetime_trunc(MYSQL_TIME *ltime, unsigned int decimals) {
518 return my_time_trunc(ltime, decimals);
519}
520
521/**
522 Truncate the tv_usec member of a posix timeval struct to the
523 specified number of decimals.
524
525 @param tv timepoint/duration
526 @param decimals desired precision
527 */
528inline void my_timeval_trunc(my_timeval *tv, unsigned int decimals) {
529 tv->m_tv_usec -= my_time_fraction_remainder(tv->m_tv_usec, decimals);
530}
531
532/**
533 Predicate for fuzzyness of date.
534
535 @param mt datetime or date value to check
536 @param flags bitfield indicating if fuzzy dates are premitted
537
538 @retval true if TIME_NO_ZERO_IN_DATE is set and either month or day is 0,
539 or TIME_NO_ZERO_DATE and all date fields are zero.
540 @retval false otherwise
541 */
543 return ((flags & TIME_NO_ZERO_IN_DATE) && (mt.month == 0 || mt.day == 0)) ||
544 ((flags & TIME_NO_ZERO_DATE) && mt.year == 0 && mt.month == 0 &&
545 mt.day == 0);
546}
547
548/**
549 Predicate which returns true if at least one of the date members are non-zero.
550
551 @param my_time time point to check.
552 @retval false if all the date members are zero
553 @retval true otherwise
554 */
555inline bool non_zero_date(const MYSQL_TIME &my_time) {
556 return my_time.year || my_time.month || my_time.day;
557}
558
559/**
560 Predicate which returns true if at least one of the time members are non-zero.
561
562 @param my_time time point to check.
563 @retval false if all the time members are zero
564 @retval true otherwise
565*/
566inline bool non_zero_time(const MYSQL_TIME &my_time) {
567 return my_time.hour || my_time.minute || my_time.second ||
568 my_time.second_part;
569}
570
571/**
572 "Casts" MYSQL_TIME datetime to a MYSQL_TIME time. Sets
573 MYSQL_TIME::time_type to MYSQL_TIMESTAMP_TIME and zeroes out the
574 date members.
575
576 @param ltime timepoint to cast
577 */
578inline void datetime_to_time(MYSQL_TIME *ltime) {
579 ltime->year = 0;
580 ltime->month = 0;
581 ltime->day = 0;
582 ltime->time_zone_displacement = 0;
584}
585
586/**
587 "Casts" MYSQL_TIME datetime to a MYSQL_TIME date. Sets
588 MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATE and zeroes out the
589 time members.
590
591 @param ltime timepoint to cast
592*/
593inline void datetime_to_date(MYSQL_TIME *ltime) {
594 ltime->hour = 0;
595 ltime->minute = 0;
596 ltime->second = 0;
597 ltime->second_part = 0;
598 ltime->time_zone_displacement = 0;
600}
601
602/**
603 "Casts" a MYSQL_TIME to datetime by setting MYSQL_TIME::time_type to
604 MYSQL_TIMESTAMP_DATETIME.
605 @note There is no check to ensure that the result is a valid datetime.
606
607 @param ltime timpoint to cast
608*/
609inline void date_to_datetime(MYSQL_TIME *ltime) {
611}
612
614 unsigned int nanoseconds,
615 int *warnings);
617 unsigned int nanoseconds);
619 unsigned int nanoseconds, int *warnings);
620
622 unsigned int nanoseconds,
623 int *warnings);
624
626 unsigned int nanoseconds, int *warnings,
627 bool truncate);
628
630 unsigned int nanoseconds,
631 int *warnings, bool truncate);
632
633bool my_time_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, bool truncate);
634bool my_datetime_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, int *warnings,
635 bool truncate);
636bool my_timeval_round(my_timeval *tv, unsigned int decimals);
638
639void localtime_to_TIME(MYSQL_TIME *to, const struct tm *from);
640void calc_time_from_sec(MYSQL_TIME *to, long long int seconds,
641 long microseconds);
642bool calc_time_diff(const MYSQL_TIME &my_time1, const MYSQL_TIME &my_time2,
643 int l_sign, long long int *seconds_out,
644 long *microseconds_out);
645int my_time_compare(const MYSQL_TIME &my_time_a, const MYSQL_TIME &my_time_b);
646
647long long int TIME_to_longlong_packed(const MYSQL_TIME &my_time,
649
651 long long int packed_value);
652
654 long long int packed_value);
655
657 long long int packed_value);
658
659/**
660 @} (end of ingroup MY_TIME)
661*/
662#endif /* MY_TIME_INCLUDED */
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
static const std::string dec("DECRYPTION")
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:1592
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:1127
uint64_t convert_month_to_period(uint64_t month)
Convert month to period.
Definition: my_time.cc:2127
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:1655
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:2707
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:375
bool int_to_date(long long int nr, Date_val *date, my_time_flags_t, int *warnings)
Definition: my_time.cc:994
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:2534
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:2586
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:1605
void set_max_time(MYSQL_TIME *tm, bool neg)
Set MYSQL_TIME variable to maximum time value.
Definition: my_time.cc:171
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:288
long long int int_to_datetime(long long int nr, MYSQL_TIME *time_res, my_time_flags_t flags, int *was_cut)
Convert datetime value specified as integer to broken-down TIME representation and form value of DATE...
Definition: my_time.cc:1503
const char my_zero_datetime6[]
Definition: my_time.cc:91
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:196
long long int year_to_longlong_datetime_packed(long year)
Convert year to packed numeric date representation.
Definition: my_time.cc:1763
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:160
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:2640
bool int_to_time(long long int nr, MYSQL_TIME *ltime, int *warnings)
Convert integer number to TIME.
Definition: my_time.cc:962
bool check_time_range_quick(const MYSQL_TIME &my_time)
Check TIME range.
Definition: my_time.cc:243
void my_init_time()
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
Definition: my_time.cc:1045
bool check_datetime_range(const MYSQL_TIME &my_time)
Check datetime, date, or normalized time (i.e.
Definition: my_time.cc:259
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:2550
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:1943
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:2493
void adjust_time_range(MYSQL_TIME *, int *warning)
Adjust 'time' value to lie in the MYSQL_TIME range.
Definition: my_time.cc:1028
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:1363
const unsigned long long int log_10_int[20]
Definition: my_time.cc:70
long long int obs_TIME_to_longlong_date_packed(const MYSQL_TIME &my_time)
Convert date to packed numeric date representation.
Definition: my_time.cc:1752
const unsigned char days_in_month[]
Definition: my_time.cc:97
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:1697
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:2682
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:2142
unsigned long long int TIME_to_ulonglong_datetime(const MYSQL_TIME &my_time)
Convert time value to integer in YYYYMMDDHHMMSS.
Definition: my_time.cc:1578
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:1680
long long int TIME_to_longlong_datetime_packed(const MYSQL_TIME &my_time)
Convert datetime to packed numeric datetime representation.
Definition: my_time.cc:1733
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:2734
uint64_t convert_period_to_month(uint64_t period)
Calculate month from period.
Definition: my_time.cc:2110
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:151
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:746
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:226
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:1774
int calc_weekday(long daynr, bool sunday_first_day_of_week)
Calc weekday from daynr.
Definition: my_time.cc:2017
static int flags[50]
Definition: hp_test1.cc:40
enum_mysql_timestamp_type
Definition: mysql_time.h:45
@ MYSQL_TIMESTAMP_TIME
Stores hour, minute, second and microsecond.
Definition: mysql_time.h:60
@ MYSQL_TIMESTAMP_DATETIME
Stores all date and time components.
Definition: mysql_time.h:57
@ MYSQL_TIMESTAMP_DATE
Stores year, month and day components.
Definition: mysql_time.h:50
time_t my_time(int)
Return current time.
Definition: my_systime.h:172
long long int my_datetime_packed_from_binary(const unsigned char *ptr, unsigned int dec)
constexpr const int MYTIME_MIN_YEAR
Definition: my_time.h:61
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:499
constexpr const my_time_flags_t TIME_NO_INVALID_DATES
Don't allow invalid dates like 2000-02-31.
Definition: my_time.h:108
void get_date_from_daynr(int64_t daynr, unsigned int *year, unsigned int *month, unsigned int *day)
constexpr const int DAYS_PER_LYEAR
Definition: my_time.h:153
bool time_add_nanoseconds_with_round(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
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:609
constexpr const bool HAVE_64_BITS_TIME_T
Definition: my_time.h:53
constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE
Don't allow zero day or zero month.
Definition: my_time.h:102
constexpr const int YY_PART_YEAR
Two-digit years < this are 20XX; >= this are 19XX.
Definition: my_time.h:60
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:405
bool datetime_add_nanoseconds_adjust_frac(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings, bool truncate)
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:366
void my_datetime_trunc(MYSQL_TIME *ltime, unsigned int decimals)
Alias for my_time_trunc.
Definition: my_time.h:517
int my_time_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec)
unsigned int calc_days_in_year(unsigned int year)
constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP
Definition: my_time.h:123
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:355
bool datetime_add_nanoseconds_with_round(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
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:341
constexpr const my_time_flags_t TIME_EXACT_DATE_ONLY
Allow exact dates only (or dates where time component is 00:00:00)
Definition: my_time.h:118
constexpr const int MYSQL_TIME_NOTE_TRUNCATED
Definition: my_time.h:125
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:555
constexpr const int TIMESTAMP_MAX_YEAR
Definition: my_time.h:57
constexpr const int MYSQL_TIME_WARN_TRUNCATED
Conversion warnings.
Definition: my_time.h:121
constexpr const my_time_flags_t TIME_ONLY_VALID_DATES
Allow only valid dates, no zero date, no zero date component.
Definition: my_time.h:111
constexpr const unsigned int WEEK_FIRST_WEEKDAY
Definition: my_time.h:163
constexpr const int MINS_PER_HOUR
Definition: my_time.h:149
constexpr const my_time_flags_t TIME_DATETIME_ONLY
Only allow full datetimes.
Definition: my_time.h:93
constexpr const int TIME_MAX_HOUR
Limits for the TIME data type.
Definition: my_time.h:133
bool time_add_nanoseconds_adjust_frac(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings, bool truncate)
constexpr const unsigned int WEEK_YEAR
Definition: my_time.h:162
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 ...
Definition: my_time.h:68
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:316
bool time_add_nanoseconds_with_truncate(MYSQL_TIME *ltime, unsigned int nanoseconds, int *warnings)
constexpr const my_time_flags_t TIME_NO_ZERO_DATE
Don't allow 0000-00-00 date.
Definition: my_time.h:105
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:146
constexpr const int MAX_TIME_ZONE_HOURS
Definition: my_time.h:158
constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW
Definition: my_time.h:127
constexpr const int HOURS_PER_DAY
Definition: my_time.h:150
constexpr const int TIME_MAX_MINUTE
Definition: my_time.h:134
constexpr const int64_t MAX_DAY_NUMBER
Daynumber from year 0 to 9999-12-31.
Definition: my_time.h:166
constexpr const int DAYS_PER_NYEAR
Definition: my_time.h:152
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:528
void my_datetime_packed_to_binary(long long int nr, unsigned char *ptr, unsigned int dec)
bool check_fuzzy_date(const MYSQL_TIME &mt, my_time_flags_t flags)
Predicate for fuzzyness of date.
Definition: my_time.h:542
void datetime_to_date(MYSQL_TIME *ltime)
"Casts" MYSQL_TIME datetime to a MYSQL_TIME date.
Definition: my_time.h:593
constexpr const int SECS_PER_DAY
Definition: my_time.h:155
unsigned int year_2000_handling(unsigned int year)
constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE
Definition: my_time.h:126
unsigned int calc_week(const MYSQL_TIME &l_time, unsigned int week_behaviour, unsigned int *year)
bool my_time_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, bool truncate)
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:487
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:140
bool is_time_t_valid_for_timestamp(time_t x)
Check for valid my_time_t value.
Definition: my_time.h:263
void my_timestamp_to_binary(const my_timeval *tm, unsigned char *ptr, unsigned int dec)
constexpr const int TIME_MAX_VALUE_SECONDS
Definition: my_time.h:143
void TIME_set_hhmmss(MYSQL_TIME *ltime, unsigned int hhmmss)
bool my_timeval_round(my_timeval *tv, unsigned int decimals)
constexpr const int64_t SECONDS_IN_24H
Useful constants.
Definition: my_time.h:130
constexpr const int TIME_MAX_SECOND
Definition: my_time.h:135
bool datetime_add_nanoseconds_with_truncate(MYSQL_TIME *ltime, unsigned int nanoseconds)
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:328
void datetime_to_time(MYSQL_TIME *ltime)
"Casts" MYSQL_TIME datetime to a MYSQL_TIME time.
Definition: my_time.h:578
long calc_daynr(unsigned int year, unsigned int month, unsigned int day)
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:295
constexpr const int MYTIME_MIN_VALUE
Zero represents the first time value we allow, i.e.
Definition: my_time.h:77
constexpr const std::int64_t TYPE_TIMESTAMP_MIN_VALUE
Definition: my_time.h:84
constexpr const my_time_flags_t TIME_NO_DATE_FRAC_WARN
Whether to warn if a fractional time component is rounded or truncated.
Definition: my_time.h:99
void TIME_set_yymmdd(MYSQL_TIME *ltime, unsigned int yymmdd)
constexpr const int MYTIME_MAX_YEAR
Time handling defaults.
Definition: my_time.h:56
bool my_datetime_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, int *warnings, bool truncate)
void my_timestamp_from_binary(my_timeval *tm, const unsigned char *ptr, unsigned int dec)
constexpr const std::int64_t TYPE_TIMESTAMP_MAX_VALUE
max seconds from epoch that can be stored in a column of type TIMESTAMP.
Definition: my_time.h:82
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:566
constexpr const my_time_flags_t TIME_NO_FLAGS
No flags: default behavior.
Definition: my_time.h:90
constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE
Definition: my_time.h:122
constexpr const int MONS_PER_YEAR
Definition: my_time.h:156
bool valid_period(long long int period)
unsigned int my_time_flags_t
Flags to str_to_datetime and int_to_datetime.
Definition: my_time.h:87
constexpr const unsigned int WEEK_MONDAY_FIRST
Flags for calc_week() function.
Definition: my_time.h:161
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:427
int my_TIME_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec)
constexpr const int MYSQL_TIME_WARN_ZERO_DATE
Definition: my_time.h:124
constexpr const int DAYS_PER_WEEK
Definition: my_time.h:151
constexpr const my_time_flags_t TIME_FRAC_TRUNCATE
Whether to truncate or round fractional time component.
Definition: my_time.h:96
interval_type
Available interval types used in any statement.
Definition: my_time.h:451
@ INTERVAL_HOUR_SECOND
Definition: my_time.h:466
@ INTERVAL_MONTH
Definition: my_time.h:454
@ INTERVAL_HOUR_MICROSECOND
Definition: my_time.h:469
@ INTERVAL_MINUTE
Definition: my_time.h:458
@ INTERVAL_HOUR_MINUTE
Definition: my_time.h:465
@ INTERVAL_DAY
Definition: my_time.h:456
@ INTERVAL_LAST
Definition: my_time.h:472
@ INTERVAL_MINUTE_MICROSECOND
Definition: my_time.h:470
@ INTERVAL_MINUTE_SECOND
Definition: my_time.h:467
@ INTERVAL_QUARTER
Definition: my_time.h:453
@ INTERVAL_YEAR
Definition: my_time.h:452
@ INTERVAL_WEEK
Definition: my_time.h:455
@ INTERVAL_DAY_MICROSECOND
Definition: my_time.h:468
@ INTERVAL_SECOND_MICROSECOND
Definition: my_time.h:471
@ INTERVAL_SECOND
Definition: my_time.h:459
@ INTERVAL_DAY_HOUR
Definition: my_time.h:462
@ INTERVAL_HOUR
Definition: my_time.h:457
@ INTERVAL_YEAR_MONTH
Definition: my_time.h:461
@ INTERVAL_DAY_SECOND
Definition: my_time.h:464
@ INTERVAL_MICROSECOND
Definition: my_time.h:460
@ INTERVAL_DAY_MINUTE
Definition: my_time.h:463
int my_timeval_to_str(const my_timeval *tm, char *to, unsigned int dec)
constexpr const int SECS_PER_MIN
Definition: my_time.h:148
constexpr const int SECS_PER_HOUR
Definition: my_time.h:154
constexpr const my_time_flags_t TIME_STRICT_COLON
Allow only HH:MM:SS or MM:SS time formats.
Definition: my_time.h:115
int my_datetime_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec)
int64_t my_time_t
Portable time_t replacement.
Definition: my_time_t.h:32
static int interval
Definition: mysqladmin.cc:72
void warning(const char *format,...)
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
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:76
std::chrono::seconds seconds
Definition: authorize_manager.cc:70
ValueType max(X &&first)
Definition: gtid.h:103
size_t size(const char *const c)
Definition: base64.h:46
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
std::string truncate(const std::string &str, const size_t max_length)
Truncates the given string to max_length code points.
Definition: utils_string.cc:418
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
required string type
Definition: replication_group_member_actions.proto:34
Struct representing a duration.
Definition: my_time.h:231
bool neg
Definition: my_time.h:239
unsigned long long int second
Definition: my_time.h:237
unsigned long long int second_part
Definition: my_time.h:238
unsigned long int hour
Definition: my_time.h:235
unsigned long int day
Definition: my_time.h:234
unsigned long int month
Definition: my_time.h:233
unsigned long int year
Definition: my_time.h:232
unsigned long long int minute
Definition: my_time.h:236
Definition: my_time.h:177
DEPR_KIND
Definition: my_time.h:178
@ DP_SUPERFLUOUS
Definition: my_time.h:182
@ DP_WRONG_SPACE
Definition: my_time.h:181
@ DP_NONE
Definition: my_time.h:179
@ DP_WRONG_KIND
Definition: my_time.h:180
char m_delim_seen
Definition: my_time.h:184
char m_arg[40]
Definition: my_time.h:187
enum MYSQL_TIME_STATUS::DEPRECATION::DEPR_KIND DP_NONE
int m_position
Definition: my_time.h:186
bool m_colon
Definition: my_time.h:185
Structure to return status from str_to_datetime(), str_to_time(), int_to_datetime(),...
Definition: my_time.h:173
unsigned int nanoseconds
Definition: my_time.h:176
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:224
void set_deprecation(DEPRECATION::DEPR_KIND kind, const char *arg, const char *end, const char *delim, bool colon=false)
Definition: my_time.h:195
MYSQL_TIME_STATUS & operator=(const MYSQL_TIME_STATUS &b)
Assignment: don't clobber an existing deprecation, first one wins.
Definition: my_time.h:214
int warnings
Definition: my_time.h:174
unsigned int fractional_digits
Definition: my_time.h:175
MYSQL_TIME_STATUS(const MYSQL_TIME_STATUS &)=default
Definition: mysql_time.h:82
int time_zone_displacement
The time zone displacement, specified in seconds.
Definition: mysql_time.h:88
unsigned long second_part
microseconds
Definition: mysql_time.h:84
unsigned int second
Definition: mysql_time.h:83
enum enum_mysql_timestamp_type time_type
Definition: mysql_time.h:86
unsigned int hour
Definition: mysql_time.h:83
unsigned int minute
Definition: mysql_time.h:83
unsigned int month
Definition: mysql_time.h:83
unsigned int day
Definition: mysql_time.h:83
bool neg
Definition: mysql_time.h:85
unsigned int year
Definition: mysql_time.h:83
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
int64_t m_tv_usec
Definition: my_time_t.h:47
Definition: result.h:30
Include file for Sun RPC to compile out of the box.