MySQL 9.5.0
Source Code Documentation
my_time.h
Go to the documentation of this file.
1/* Copyright (c) 2004, 2025, 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
47extern const unsigned long long int log_10_int[20];
48extern const unsigned char days_in_month[];
49extern const char my_zero_datetime6[]; /* "0000-00-00 00:00:00.000000" */
50
51constexpr const bool HAVE_64_BITS_TIME_T = sizeof(time_t) == sizeof(my_time_t);
52
53/** Time handling defaults */
54constexpr const int MYTIME_MAX_YEAR = HAVE_64_BITS_TIME_T ? 9999 : 2038;
55constexpr const int TIMESTAMP_MAX_YEAR = 2038;
56
57/** Two-digit years < this are 20XX; >= this are 19XX */
58constexpr const int YY_PART_YEAR = 70;
59constexpr const int MYTIME_MIN_YEAR = (1900 + YY_PART_YEAR - 1);
60
61/** max seconds from epoch of host's time_t stored in my_time_t
62 Windows allows up to 3001-01-18 23:59:59 UTC for localtime_r, so
63 that is our effective limit, although Unixen allow higher time points.
64 Hence the magic constant 32536771199.
65 */
66constexpr const my_time_t MYTIME_MAX_VALUE =
67 HAVE_64_BITS_TIME_T ? 32536771199
69
70/**
71 Zero represents the first time value we allow, i.e. UNIX epoch.
72 We do not allow times before UNIX epoch, except for inside computations,
73 hence we use a signed integer as the base type, cf. prepare_tz_info.
74*/
75constexpr const int MYTIME_MIN_VALUE = 0;
76
77/** max seconds from epoch that can be stored in a column of type TIMESTAMP.
78 This also impacts the max value that can be given to SET TIMESTAMP
79*/
80constexpr const std::int64_t TYPE_TIMESTAMP_MAX_VALUE =
82constexpr const std::int64_t TYPE_TIMESTAMP_MIN_VALUE = 1;
83
84/** Flags to str_to_datetime and number_to_datetime */
85using my_time_flags_t = unsigned int;
86
87/** Allow zero day and zero month */
88constexpr const my_time_flags_t TIME_FUZZY_DATE = 1;
89
90/** Only allow full datetimes. */
92
95
96/** Don't allow zero day or zero month */
98
99/** Don't allow 0000-00-00 date */
101
102/** Allow 2000-02-31 */
104
105/** Allow only HH:MM:SS or MM:SS time formats */
106constexpr const my_time_flags_t TIME_STRICT_COLON = 128;
107
108/** Conversion warnings */
109constexpr const int MYSQL_TIME_WARN_TRUNCATED = 1;
110constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE = 2;
111constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP = 4;
112constexpr const int MYSQL_TIME_WARN_ZERO_DATE = 8;
113constexpr const int MYSQL_TIME_NOTE_TRUNCATED = 16;
114constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE = 32;
115constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW = 64;
116
117/** Useful constants */
118constexpr const int64_t SECONDS_IN_24H = 86400LL;
119
120/** Limits for the TIME data type */
121constexpr const int TIME_MAX_HOUR = 838;
122constexpr const int TIME_MAX_MINUTE = 59;
123constexpr const int TIME_MAX_SECOND = 59;
124
125/**
126 Note that this MUST be a signed type, as we use the unary - operator on it.
127 */
128constexpr const int TIME_MAX_VALUE =
130
131constexpr const int TIME_MAX_VALUE_SECONDS =
133
134constexpr const int DATETIME_MAX_DECIMALS = 6;
135
136constexpr const int SECS_PER_MIN = 60;
137constexpr const int MINS_PER_HOUR = 60;
138constexpr const int HOURS_PER_DAY = 24;
139constexpr const int DAYS_PER_WEEK = 7;
140constexpr const int DAYS_PER_NYEAR = 365;
141constexpr const int DAYS_PER_LYEAR = 366;
142constexpr const int SECS_PER_HOUR = (SECS_PER_MIN * MINS_PER_HOUR);
143constexpr const int SECS_PER_DAY = (SECS_PER_HOUR * HOURS_PER_DAY);
144constexpr const int MONS_PER_YEAR = 12;
145
146constexpr const int MAX_TIME_ZONE_HOURS = 14;
147
148/** Flags for calc_week() function. */
149constexpr const unsigned int WEEK_MONDAY_FIRST = 1;
150constexpr const unsigned int WEEK_YEAR = 2;
151constexpr const unsigned int WEEK_FIRST_WEEKDAY = 4;
152
153/** Daynumber from year 0 to 9999-12-31 */
154constexpr const int64_t MAX_DAY_NUMBER = 3652424;
155
156/**
157 Structure to return status from
158 str_to_datetime(), str_to_time(), number_to_datetime(), number_to_time()
159 @note Implicit default constructor initializes all members to 0.
160*/
162 int warnings{0};
163 unsigned int fractional_digits{0};
164 unsigned int nanoseconds{0};
165 struct DEPRECATION { // We only report first offense
167 DP_NONE, // no deprecated delimiter seen yet
168 DP_WRONG_KIND, // seen a delimiter in correct position, but wrong one
169 DP_WRONG_SPACE, // seen a space delimiter which isn't 0x20 ' '.
170 DP_SUPERFLUOUS // seen a superfluous delimiter
171 } m_kind{DP_NONE};
173 bool m_colon; // for DP_WRONG_KIND: true if we expect ':', else '-'
174 int m_position; // 0-based in m_arg
175 char m_arg[40]; // the string argument we found a deprecation in
177 ///< Register wrong delimiter if it's the first we see for this value
178 ///< @param kind what kind of deprecation did we see
179 ///< @param arg the string we try to interpret as a datetime value
180 ///< @param end points to the character after arg, usually a '\0'
181 ///< @param delim what delimiter was used
182 ///< @param colon used if kind==DP_WRONG_KIND. true: expect ':' else expect'-'
183 void set_deprecation(DEPRECATION::DEPR_KIND kind, const char *arg,
184 const char *end, const char *delim, bool colon = false) {
185 if (m_deprecation.m_kind == DEPRECATION::DP_NONE) {
186 m_deprecation.m_kind = kind;
188 m_deprecation.m_colon = colon;
189 const size_t bufsize = sizeof(m_deprecation.m_arg) - 1; // -1: for '\0'
190 const size_t argsize = end - arg;
191 const size_t size = std::min(bufsize, argsize);
192 // The input string is not necessarily zero-terminated,
193 // so do not use snprintf().
194 std::strncpy(m_deprecation.m_arg, arg, size);
195 m_deprecation.m_arg[size] = '\0';
196 m_deprecation.m_position = delim - arg;
197 }
198 }
199 MYSQL_TIME_STATUS() = default;
201 /// Assignment: don't clobber an existing deprecation, first one wins
203 warnings = b.warnings;
206 // keep first deprecation
207 if (m_deprecation.m_kind == DEPRECATION::DP_NONE) {
209 }
210 return *this;
211 }
213};
214
215/**
216 Struct representing a duration. Content is similar to MYSQL_TIME
217 but member variables are unsigned.
218 */
219struct Interval {
220 unsigned long int year;
221 unsigned long int month;
222 unsigned long int day;
223 unsigned long int hour;
224 unsigned long long int minute;
225 unsigned long long int second;
226 unsigned long long int second_part;
227 bool neg;
228};
229
230void my_init_time();
231
232long calc_daynr(unsigned int year, unsigned int month, unsigned int day);
233unsigned int calc_days_in_year(unsigned int year);
234unsigned int year_2000_handling(unsigned int year);
235
236bool time_zone_displacement_to_seconds(const char *str, size_t length,
237 int *result);
238
239void get_date_from_daynr(int64_t daynr, unsigned int *year, unsigned int *month,
240 unsigned int *day);
241int calc_weekday(long daynr, bool sunday_first_day_of_week);
242bool valid_period(long long int period);
243uint64_t convert_period_to_month(uint64_t period);
244uint64_t convert_month_to_period(uint64_t month);
245
246/**
247 Check for valid my_time_t value. Note: timestamp here pertains to seconds
248 since epoch, not the legacy MySQL type TIMESTAMP, which is limited to
249 32 bits even on 64 bit platforms.
250*/
251inline bool is_time_t_valid_for_timestamp(time_t x) {
252 return (static_cast<int64_t>(x) <= static_cast<int64_t>(MYTIME_MAX_VALUE) &&
253 x >= MYTIME_MIN_VALUE);
254}
255
256unsigned int calc_week(const MYSQL_TIME &l_time, unsigned int week_behaviour,
257 unsigned int *year);
258
259bool check_date(const MYSQL_TIME &ltime, bool not_zero_date,
260 my_time_flags_t flags, int *was_cut);
261bool str_to_datetime(const char *str, std::size_t length, MYSQL_TIME *l_time,
263long long int number_to_datetime(long long int nr, MYSQL_TIME *time_res,
264 my_time_flags_t flags, int *was_cut);
265bool number_to_time(long long int nr, MYSQL_TIME *ltime, int *warnings);
266unsigned long long int TIME_to_ulonglong_datetime(const MYSQL_TIME &my_time);
267unsigned long long int TIME_to_ulonglong_date(const MYSQL_TIME &my_time);
268unsigned long long int TIME_to_ulonglong_time(const MYSQL_TIME &my_time);
269unsigned long long int TIME_to_ulonglong(const MYSQL_TIME &my_time);
270
271unsigned long long int TIME_to_ulonglong_datetime_round(
272 const MYSQL_TIME &my_time, int *warnings);
273unsigned long long int TIME_to_ulonglong_time_round(const MYSQL_TIME &my_time);
274
275/**
276 Round any MYSQL_TIME timepoint and convert to ulonglong.
277 @param my_time input
278 @param[out] warnings warning vector
279 @return time point as ulonglong
280 */
281inline unsigned long long int TIME_to_ulonglong_round(const MYSQL_TIME &my_time,
282 int *warnings) {
283 switch (my_time.time_type) {
290 default:
291 assert(false);
292 return 0;
293 }
294}
295
296/**
297 Extract the microsecond part of a MYSQL_TIME struct as an n *
298 (1/10^6) fraction as a double.
299
300 @return microseconds part as double
301 */
302inline double TIME_microseconds(const MYSQL_TIME &my_time) {
303 return static_cast<double>(my_time.second_part) / 1000000.0;
304}
305
306/**
307 Convert a MYSQL_TIME datetime to double where the integral part is
308 the timepoint as an ulonglong, and the fractional part is the
309 fraction of the second.
310
311 @param my_time datetime to convert
312 @return datetime as double
313 */
315 return static_cast<double>(TIME_to_ulonglong_datetime(my_time)) +
317}
318
319/**
320 Convert a MYSQL_TIME time to double where the integral part is
321 the timepoint as an ulonglong, and the fractional part is the
322 fraction of the second.
323
324 @param my_time time to convert
325 @return datetime as double
326 */
328 return static_cast<double>(TIME_to_ulonglong_time(my_time)) +
330}
331
332/**
333 Convert a MYSQL_TIME to double where the integral part is the
334 timepoint as an ulonglong, and the fractional part is the fraction
335 of the second. The actual time type is extracted from
336 MYSQL_TIME::time_type.
337
338 @param my_time MYSQL_TIME to convert
339 @return MYSQL_TIME as double
340 */
341inline double TIME_to_double(const MYSQL_TIME &my_time) {
342 return static_cast<double>(TIME_to_ulonglong(my_time)) +
344}
345
346/**
347 Return the fraction of the second as the number of microseconds.
348
349 @param i timepoint as longlong
350 @return frational part of an timepoint represented as an (u)longlong
351*/
352inline long long int my_packed_time_get_frac_part(long long int i) {
353 return (i % (1LL << 24));
354}
355
356long long int year_to_longlong_datetime_packed(long year);
359long long int TIME_to_longlong_packed(const MYSQL_TIME &my_time);
360
361void TIME_from_longlong_datetime_packed(MYSQL_TIME *ltime, long long int nr);
362void TIME_from_longlong_date_packed(MYSQL_TIME *ltime, long long int nr);
363void TIME_set_yymmdd(MYSQL_TIME *ltime, unsigned int yymmdd);
364void TIME_set_hhmmss(MYSQL_TIME *ltime, unsigned int hhmmss);
365
366void my_datetime_packed_to_binary(long long int nr, unsigned char *ptr,
367 unsigned int dec);
368long long int my_datetime_packed_from_binary(const unsigned char *ptr,
369 unsigned int dec);
370
371void my_timestamp_to_binary(const my_timeval *tm, unsigned char *ptr,
372 unsigned int dec);
373void my_timestamp_from_binary(my_timeval *tm, const unsigned char *ptr,
374 unsigned int dec);
375
376bool str_to_time(const char *str, std::size_t length, MYSQL_TIME *l_time,
378
383
384/**
385 Check whether the argument holds a valid UNIX time value
386 (seconds after epoch). This function doesn't make precise check, but rather a
387 rough estimate before time zone adjustments.
388
389 @param my_time timepoint to check
390 @returns true if value satisfies the check above, false otherwise.
391*/
393 if (my_time.year < MYTIME_MIN_YEAR || my_time.year > MYTIME_MAX_YEAR)
394 return false;
395
396 return true;
397}
398
400 bool *in_dst_time_gap);
401
402void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type);
403void set_max_time(MYSQL_TIME *tm, bool neg);
404void set_max_hhmmss(MYSQL_TIME *tm);
405
406/**
407 Required buffer length for my_time_to_str, my_date_to_str,
408 my_datetime_to_str and TIME_to_string functions. Note, that the
409 caller is still responsible to check that given TIME structure
410 has values in valid ranges, otherwise size of the buffer might
411 well be insufficient. We also rely on the fact that even incorrect values
412 sent using binary protocol fit in this buffer.
413*/
414constexpr const std::size_t MAX_DATE_STRING_REP_LENGTH =
415 sizeof("YYYY-MM-DD AM HH:MM:SS.FFFFFF+HH:MM");
416
417int my_time_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
418int my_date_to_str(const MYSQL_TIME &my_time, char *to);
419int my_datetime_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
420int my_TIME_to_str(const MYSQL_TIME &my_time, char *to, unsigned int dec);
421
422void my_date_to_binary(const MYSQL_TIME *ltime, unsigned char *ptr);
423int my_timeval_to_str(const my_timeval *tm, char *to, unsigned int dec);
424
425/**
426 Available interval types used in any statement.
427
428 'interval_type' must be sorted so that simple intervals comes first,
429 ie year, quarter, month, week, day, hour, etc. The order based on
430 interval size is also important and the intervals should be kept in a
431 large to smaller order. (get_interval_value() depends on this)
432
433 @note If you change the order of elements in this enum you should fix
434 order of elements in 'interval_type_to_name' and 'interval_names'
435 arrays
436
437 @see interval_type_to_name, get_interval_value, interval_names
438*/
462
463bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
464 Interval interval, int *warnings);
465
466/**
467 Round the input argument to the specified precision by computing
468 the remainder modulo log10 of the difference between max and
469 desired precision.
470
471 @param nr number to round
472 @param decimals desired precision
473 @return nr rounded according to the desired precision.
474*/
475inline long my_time_fraction_remainder(long nr, unsigned int decimals) {
476 assert(decimals <= DATETIME_MAX_DECIMALS);
477 return nr % static_cast<long>(log_10_int[DATETIME_MAX_DECIMALS - decimals]);
478}
479
480/**
481 Truncate the number of microseconds in MYSQL_TIME::second_part to
482 the desired precision.
483
484 @param ltime time point
485 @param decimals desired precision
486*/
487inline void my_time_trunc(MYSQL_TIME *ltime, unsigned int decimals) {
488 assert(ltime->time_type == MYSQL_TIMESTAMP_TIME || !ltime->neg);
489 ltime->second_part -=
490 my_time_fraction_remainder(ltime->second_part, decimals);
491 // "Negative zero" time is not defined:
492 if (ltime->time_type == MYSQL_TIMESTAMP_TIME && ltime->neg &&
493 ltime->hour == 0 && ltime->minute == 0 && ltime->second == 0 &&
494 ltime->second_part == 0) {
495 ltime->neg = false;
496 }
497}
498
499/**
500 Alias for my_time_trunc.
501
502 @param ltime time point
503 @param decimals desired precision
504 */
505inline void my_datetime_trunc(MYSQL_TIME *ltime, unsigned int decimals) {
506 return my_time_trunc(ltime, decimals);
507}
508
509/**
510 Truncate the tv_usec member of a posix timeval struct to the
511 specified number of decimals.
512
513 @param tv timepoint/duration
514 @param decimals desired precision
515 */
516inline void my_timeval_trunc(my_timeval *tv, unsigned int decimals) {
517 tv->m_tv_usec -= my_time_fraction_remainder(tv->m_tv_usec, decimals);
518}
519
520/**
521 Predicate for fuzzyness of date.
522
523 @param my_time time point to check
524 @param fuzzydate bitfield indicating if fuzzy dates are premitted
525 @retval true if TIME_FUZZY_DATE is unset and either month or day is 0
526 @retval false otherwise
527 */
529 my_time_flags_t fuzzydate) {
530 return !(fuzzydate & TIME_FUZZY_DATE) && (!my_time.month || !my_time.day);
531}
532
533/**
534 Predicate which returns true if at least one of the date members are non-zero.
535
536 @param my_time time point to check.
537 @retval false if all the date members are zero
538 @retval true otherwise
539 */
540inline bool non_zero_date(const MYSQL_TIME &my_time) {
541 return my_time.year || my_time.month || my_time.day;
542}
543
544/**
545 Predicate which returns true if at least one of the time members are non-zero.
546
547 @param my_time time point to check.
548 @retval false if all the time members are zero
549 @retval true otherwise
550*/
551inline bool non_zero_time(const MYSQL_TIME &my_time) {
552 return my_time.hour || my_time.minute || my_time.second ||
553 my_time.second_part;
554}
555
556/**
557 "Casts" MYSQL_TIME datetime to a MYSQL_TIME time. Sets
558 MYSQL_TIME::time_type to MYSQL_TIMESTAMP_TIME and zeroes out the
559 date members.
560
561 @param ltime timepoint to cast
562 */
563inline void datetime_to_time(MYSQL_TIME *ltime) {
564 ltime->year = 0;
565 ltime->month = 0;
566 ltime->day = 0;
568}
569
570/**
571 "Casts" MYSQL_TIME datetime to a MYSQL_TIME date. Sets
572 MYSQL_TIME::time_type to MYSQL_TIMESTAMP_DATE and zeroes out the
573 time members.
574
575 @param ltime timepoint to cast
576*/
577inline void datetime_to_date(MYSQL_TIME *ltime) {
578 ltime->hour = 0;
579 ltime->minute = 0;
580 ltime->second = 0;
581 ltime->second_part = 0;
583}
584
585/**
586 "Casts" a MYSQL_TIME to datetime by setting MYSQL_TIME::time_type to
587 MYSQL_TIMESTAMP_DATETIME.
588 @note There is no check to ensure that the result is a valid datetime.
589
590 @param ltime timpoint to cast
591*/
592inline void date_to_datetime(MYSQL_TIME *ltime) {
594}
595
597 unsigned int nanoseconds,
598 int *warnings);
600 unsigned int nanoseconds);
602 unsigned int nanoseconds, int *warnings);
603
605 unsigned int nanoseconds,
606 int *warnings);
607
609 unsigned int nanoseconds, int *warnings,
610 bool truncate);
611
613 unsigned int nanoseconds,
614 int *warnings, bool truncate);
615
616bool my_time_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, bool truncate);
617bool my_datetime_adjust_frac(MYSQL_TIME *ltime, unsigned int dec, int *warnings,
618 bool truncate);
619bool my_timeval_round(my_timeval *tv, unsigned int decimals);
621
622void localtime_to_TIME(MYSQL_TIME *to, const struct tm *from);
623void calc_time_from_sec(MYSQL_TIME *to, long long int seconds,
624 long microseconds);
625bool calc_time_diff(const MYSQL_TIME &my_time1, const MYSQL_TIME &my_time2,
626 int l_sign, long long int *seconds_out,
627 long *microseconds_out);
628int my_time_compare(const MYSQL_TIME &my_time_a, const MYSQL_TIME &my_time_b);
629
630long long int TIME_to_longlong_packed(const MYSQL_TIME &my_time,
632
634 long long int packed_value);
635
637 long long int packed_value);
638
640 long long int packed_value);
641
642/**
643 @} (end of ingroup MY_TIME)
644*/
645#endif /* MY_TIME_INCLUDED */
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:1565
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:1094
uint64_t convert_month_to_period(uint64_t month)
Convert month to period.
Definition: my_time.cc:2117
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:1628
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:2703
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
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:2525
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:2577
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:1578
void set_max_time(MYSQL_TIME *tm, bool neg)
Set MYSQL_TIME variable to maximum time value.
Definition: my_time.cc:170
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:287
const char my_zero_datetime6[]
Definition: my_time.cc:90
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:195
long long int year_to_longlong_datetime_packed(long year)
Convert year to packed numeric date representation.
Definition: my_time.cc:1735
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:159
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:2631
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:1779
bool check_time_range_quick(const MYSQL_TIME &my_time)
Check TIME range.
Definition: my_time.cc:242
void my_init_time()
Prepare offset of system time zone from UTC for my_system_gmt_sec() func.
Definition: my_time.cc:1012
bool check_datetime_range(const MYSQL_TIME &my_time)
Check datetime, date, or normalized time (i.e.
Definition: my_time.cc:258
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:2541
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:1936
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:2484
void adjust_time_range(MYSQL_TIME *, int *warning)
Adjust 'time' value to lie in the MYSQL_TIME range.
Definition: my_time.cc:995
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:1330
const unsigned long long int log_10_int[20]
Definition: my_time.cc:69
const unsigned char days_in_month[]
Definition: my_time.cc:96
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:1670
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:2675
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:2132
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:1924
unsigned long long int TIME_to_ulonglong_datetime(const MYSQL_TIME &my_time)
Convert time value to integer in YYYYMMDDHHMMSS.
Definition: my_time.cc:1551
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:1653
long long int TIME_to_longlong_datetime_packed(const MYSQL_TIME &my_time)
Convert datetime to packed numeric datetime representation.
Definition: my_time.cc:1706
bool number_to_time(long long int nr, MYSQL_TIME *ltime, int *warnings)
Convert number to TIME.
Definition: my_time.cc:953
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:2733
uint64_t convert_period_to_month(uint64_t period)
Calculate month from period.
Definition: my_time.cc:2100
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:150
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
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:1470
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:225
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:1746
int calc_weekday(long daynr, bool sunday_first_day_of_week)
Calc weekday from daynr.
Definition: my_time.cc:2007
long long int TIME_to_longlong_date_packed(const MYSQL_TIME &my_time)
Convert date to packed numeric date representation.
Definition: my_time.cc:1724
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:59
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:487
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:141
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:592
constexpr const bool HAVE_64_BITS_TIME_T
Definition: my_time.h:51
constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE
Don't allow zero day or zero month.
Definition: my_time.h:97
constexpr const int YY_PART_YEAR
Two-digit years < this are 20XX; >= this are 19XX.
Definition: my_time.h:58
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:392
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:352
void my_datetime_trunc(MYSQL_TIME *ltime, unsigned int decimals)
Alias for my_time_trunc.
Definition: my_time.h:505
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:111
constexpr const my_time_flags_t TIME_INVALID_DATES
Allow 2000-02-31.
Definition: my_time.h:103
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:341
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:327
constexpr const int MYSQL_TIME_NOTE_TRUNCATED
Definition: my_time.h:113
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:540
constexpr const int TIMESTAMP_MAX_YEAR
Definition: my_time.h:55
constexpr const int MYSQL_TIME_WARN_TRUNCATED
Conversion warnings.
Definition: my_time.h:109
constexpr const unsigned int WEEK_FIRST_WEEKDAY
Definition: my_time.h:151
constexpr const int MINS_PER_HOUR
Definition: my_time.h:137
constexpr const my_time_flags_t TIME_DATETIME_ONLY
Only allow full datetimes.
Definition: my_time.h:91
constexpr const int TIME_MAX_HOUR
Limits for the TIME data type.
Definition: my_time.h:121
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:150
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:66
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:302
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:100
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:134
constexpr const int MAX_TIME_ZONE_HOURS
Definition: my_time.h:146
constexpr const int MYSQL_TIME_WARN_DATETIME_OVERFLOW
Definition: my_time.h:115
constexpr const int HOURS_PER_DAY
Definition: my_time.h:138
constexpr const int TIME_MAX_MINUTE
Definition: my_time.h:122
bool check_fuzzy_date(const MYSQL_TIME &my_time, my_time_flags_t fuzzydate)
Predicate for fuzzyness of date.
Definition: my_time.h:528
constexpr const int64_t MAX_DAY_NUMBER
Daynumber from year 0 to 9999-12-31.
Definition: my_time.h:154
constexpr const int DAYS_PER_NYEAR
Definition: my_time.h:140
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:516
void my_datetime_packed_to_binary(long long int nr, unsigned char *ptr, unsigned int dec)
void datetime_to_date(MYSQL_TIME *ltime)
"Casts" MYSQL_TIME datetime to a MYSQL_TIME date.
Definition: my_time.h:577
constexpr const int SECS_PER_DAY
Definition: my_time.h:143
unsigned int year_2000_handling(unsigned int year)
constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE
Definition: my_time.h:114
unsigned int calc_week(const MYSQL_TIME &l_time, unsigned int week_behaviour, unsigned int *year)
constexpr const my_time_flags_t TIME_FUZZY_DATE
Allow zero day and zero month.
Definition: my_time.h:88
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:475
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:128
bool is_time_t_valid_for_timestamp(time_t x)
Check for valid my_time_t value.
Definition: my_time.h:251
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:131
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:118
constexpr const int TIME_MAX_SECOND
Definition: my_time.h:123
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:314
void datetime_to_time(MYSQL_TIME *ltime)
"Casts" MYSQL_TIME datetime to a MYSQL_TIME time.
Definition: my_time.h:563
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:281
constexpr const int MYTIME_MIN_VALUE
Zero represents the first time value we allow, i.e.
Definition: my_time.h:75
constexpr const std::int64_t TYPE_TIMESTAMP_MIN_VALUE
Definition: my_time.h:82
constexpr const my_time_flags_t TIME_NO_DATE_FRAC_WARN
Definition: my_time.h:94
void TIME_set_yymmdd(MYSQL_TIME *ltime, unsigned int yymmdd)
constexpr const int MYTIME_MAX_YEAR
Time handling defaults.
Definition: my_time.h:54
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:80
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:551
constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE
Definition: my_time.h:110
constexpr const int MONS_PER_YEAR
Definition: my_time.h:144
bool valid_period(long long int period)
unsigned int my_time_flags_t
Flags to str_to_datetime and number_to_datetime.
Definition: my_time.h:85
constexpr const unsigned int WEEK_MONDAY_FIRST
Flags for calc_week() function.
Definition: my_time.h:149
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:414
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:112
constexpr const int DAYS_PER_WEEK
Definition: my_time.h:139
constexpr const my_time_flags_t TIME_FRAC_TRUNCATE
Definition: my_time.h:93
interval_type
Available interval types used in any statement.
Definition: my_time.h:439
@ INTERVAL_HOUR_SECOND
Definition: my_time.h:454
@ INTERVAL_MONTH
Definition: my_time.h:442
@ INTERVAL_HOUR_MICROSECOND
Definition: my_time.h:457
@ INTERVAL_MINUTE
Definition: my_time.h:446
@ INTERVAL_HOUR_MINUTE
Definition: my_time.h:453
@ INTERVAL_DAY
Definition: my_time.h:444
@ INTERVAL_LAST
Definition: my_time.h:460
@ INTERVAL_MINUTE_MICROSECOND
Definition: my_time.h:458
@ INTERVAL_MINUTE_SECOND
Definition: my_time.h:455
@ INTERVAL_QUARTER
Definition: my_time.h:441
@ INTERVAL_YEAR
Definition: my_time.h:440
@ INTERVAL_WEEK
Definition: my_time.h:443
@ INTERVAL_DAY_MICROSECOND
Definition: my_time.h:456
@ INTERVAL_SECOND_MICROSECOND
Definition: my_time.h:459
@ INTERVAL_SECOND
Definition: my_time.h:447
@ INTERVAL_DAY_HOUR
Definition: my_time.h:450
@ INTERVAL_HOUR
Definition: my_time.h:445
@ INTERVAL_YEAR_MONTH
Definition: my_time.h:449
@ INTERVAL_DAY_SECOND
Definition: my_time.h:452
@ INTERVAL_MICROSECOND
Definition: my_time.h:448
@ INTERVAL_DAY_MINUTE
Definition: my_time.h:451
int my_timeval_to_str(const my_timeval *tm, char *to, unsigned int dec)
constexpr const int SECS_PER_MIN
Definition: my_time.h:136
constexpr const int SECS_PER_HOUR
Definition: my_time.h:142
constexpr const my_time_flags_t TIME_STRICT_COLON
Allow only HH:MM:SS or MM:SS time formats.
Definition: my_time.h:106
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:1078
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:68
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:219
bool neg
Definition: my_time.h:227
unsigned long long int second
Definition: my_time.h:225
unsigned long long int second_part
Definition: my_time.h:226
unsigned long int hour
Definition: my_time.h:223
unsigned long int day
Definition: my_time.h:222
unsigned long int month
Definition: my_time.h:221
unsigned long int year
Definition: my_time.h:220
unsigned long long int minute
Definition: my_time.h:224
Definition: my_time.h:165
DEPR_KIND
Definition: my_time.h:166
@ DP_SUPERFLUOUS
Definition: my_time.h:170
@ DP_WRONG_SPACE
Definition: my_time.h:169
@ DP_NONE
Definition: my_time.h:167
@ DP_WRONG_KIND
Definition: my_time.h:168
char m_delim_seen
Definition: my_time.h:172
char m_arg[40]
Definition: my_time.h:175
enum MYSQL_TIME_STATUS::DEPRECATION::DEPR_KIND DP_NONE
int m_position
Definition: my_time.h:174
bool m_colon
Definition: my_time.h:173
Structure to return status from str_to_datetime(), str_to_time(), number_to_datetime(),...
Definition: my_time.h:161
unsigned int nanoseconds
Definition: my_time.h:164
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:212
void set_deprecation(DEPRECATION::DEPR_KIND kind, const char *arg, const char *end, const char *delim, bool colon=false)
Definition: my_time.h:183
MYSQL_TIME_STATUS & operator=(const MYSQL_TIME_STATUS &b)
Assignment: don't clobber an existing deprecation, first one wins.
Definition: my_time.h:202
int warnings
Definition: my_time.h:162
unsigned int fractional_digits
Definition: my_time.h:163
MYSQL_TIME_STATUS(const MYSQL_TIME_STATUS &)=default
Definition: mysql_time.h:82
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.