MySQL 9.7.0
Source Code Documentation
my_temporal.h
Go to the documentation of this file.
1#ifndef MY_TEMPORAL_H
2#define MY_TEMPORAL_H
3
4/* Copyright (c) 2025, 2026, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27/**
28 @ingroup MY_TEMPORAL
29 @{
30
31 @file include/my_temporal.h
32
33 Server classes for temporal handling (DATE, TIME, DATETIME)
34*/
35
36#include <stdint.h> // for uint32_t, uint64_t, int64_t, int32_t, uint8_t
37#include <stdlib.h> // for abs, size_t
38#include <cassert> // for assert
39#include <string> // for string
40
41#include "my_byteorder.h" // int3store
42#include "my_time.h" // for SECS_PER_MIN, SECS_PER_HOUR, Interval, ...
43#include "myisampack.h" // mi_int2store
44#include "mysql_time.h" // for MYSQL_TIME, enum_mysql_timestamp_type
45
46/**
47 Time_val is a temporal type that represents only time.
48 It has constructors for creating time values from time components
49 (hour, minute, second and microseconds), and from seconds and microseconds.
50 It also has a constructor to create a value from a MYSQL_TIME value.
51
52 The range of values supported is from -838:59:59 to +838:59:59.
53 The negative values, and the values from 24:00:00 and up are dedicated
54 for use as a small-range interval type and should not be taken as a time
55 within a day.
56*/
57class Time_val {
58 public:
59 Time_val() = default;
60
61 Time_val(bool negative, uint32_t hour, uint32_t minute, uint32_t second,
62 uint32_t microsecond) {
63 assert(hour <= TIME_MAX_HOUR && minute <= TIME_MAX_MINUTE &&
65 m_value = (static_cast<uint64_t>(hour) << TIME_SHIFT_HOUR) |
66 (static_cast<uint64_t>(minute) << TIME_SHIFT_MINUTE) |
67 (static_cast<uint64_t>(second) << TIME_SHIFT_SECOND) |
69 if (negative) {
70 assert(hour != 0 || minute != 0 || second != 0 || microsecond != 0);
71 // Stored as one's complement, negate value and subtract one
72 m_value = (static_cast<uint64_t>(-static_cast<int64_t>(m_value)) &
74 1;
75 } else {
77 }
78 assert(is_valid());
79 }
80
81 Time_val(bool negative, uint32_t second, uint32_t microsecond)
82 : Time_val(negative, second / SECS_PER_HOUR,
84 microsecond) {}
85
86 explicit Time_val(const MYSQL_TIME &mtime)
87 : Time_val(mtime.neg, mtime.hour, mtime.minute, mtime.second,
88 mtime.second_part) {
89 assert(mtime.time_type == MYSQL_TIMESTAMP_TIME);
90 }
91
92 bool is_negative() const { return (m_value & BITS_SIGN) == 0; }
93 uint32_t hour() const {
94 return is_negative() ? 2047U - ((m_value & BITS_HOUR) >> TIME_SHIFT_HOUR)
96 }
97 uint32_t minute() const {
98 return is_negative() ? 63U - ((m_value & BITS_MINUTE) >> TIME_SHIFT_MINUTE)
100 }
101 uint32_t second() const {
102 return is_negative() ? 63U - ((m_value & BITS_SECOND) >> TIME_SHIFT_SECOND)
104 }
105 uint32_t microsecond() const {
108 }
109
110 /**
111 @returns whether the value is less than, equal to or greater than
112 the argument value.
113 */
114 int compare(const Time_val arg) const {
115 return m_value < arg.m_value ? -1 : m_value > arg.m_value ? 1 : 0;
116 }
117 /// @returns an integer value for comparison purposes
118 int64_t for_comparison() const { return m_value; }
119
120 /// Check against extreme values
121 bool is_extreme_value(bool positive) const {
122 return m_value == (positive ? MAX_TIME_VALUE : MIN_TIME_VALUE);
123 }
124
125 /// Set zero time
127
128 /// Set extreme value
129 void set_extreme_value(bool negative) {
131 }
132
133 bool operator==(const Time_val rhs) const { return m_value == rhs.m_value; }
134
135 bool operator<(const Time_val rhs) const { return m_value < rhs.m_value; }
136 /**
137 Add a time value to another time value, or subtract it
138
139 @param tv Time value to add or subtract
140 @param subtract If true, subtract the time value, otherwise add it.
141
142 @returns false if result is within valid time range, true otherwise.
143 */
144 bool add(Time_val tv, bool subtract);
145
146 /**
147 Add an interval to a time value, or subtract it
148
149 @param iv Interval to add or subtract
150 @param subtract If true, subtract the time value, otherwise add it.
151
152 @returns false if result is within valid time range, true otherwise.
153 */
154 bool add(Interval &iv, bool subtract);
155
156 /// Static functions for creation
157 /**
158 Creates Time_val with range check.
159
160 @returns false if valid range, true if outside valid range.
161 */
162 static bool make_time(bool negative, uint32_t hour, uint32_t minute,
163 uint32_t second, uint32_t microsecond, Time_val *time) {
164 if (hour > TIME_MAX_HOUR || (hour == TIME_MAX_HOUR && microsecond != 0) ||
167 return true;
168 }
169 *time = Time_val(negative, hour, minute, second, microsecond);
170 return false;
171 }
172 /// Creates a Time_val from a date_time by extracting only the time fields
173 static Time_val strip_date(const MYSQL_TIME &mt);
174
175 /// Convert time value to the generalized temporal time format.
176 explicit operator MYSQL_TIME() const;
177
178 /// @returns time value as number of seconds. Fraction seconds are ignored.
179 int32_t to_seconds() const {
180 return static_cast<int32_t>(unsigned_seconds(hour(), minute(), second())) *
181 (is_negative() ? -1 : 1);
182 }
183 /// @returns time value as number of microseconds.
184 int64_t to_microseconds() const {
185 return static_cast<int64_t>(
187 (is_negative() ? -1 : 1);
188 }
189 /**
190 base100 representation without microsecond, but rounded
191 '-12:34:56.999999' is returned as -123457
192 */
193 int64_t to_int_rounded() const;
194 /**
195 base100 representation without microsecond, '-12:34:56.999999' is
196 returned as -123456
197 */
198 int64_t to_int_truncated() const;
199 /**
200 base100 representation with microseconds, returned as double precision float
201 */
202 double to_double() const;
203
204 /// @returns true if value is adjusted to number of decimals in fraction
205 bool is_adjusted(uint32_t decimals) const;
206
207 /// @returns actual number of decimals in fraction
208 uint32_t actual_decimals() const;
209
210 // Mutators
211 void adjust_fraction(uint32_t decimals, bool round);
212
213 // Add nanoseconds to a time value, with rounding
214 bool add_nanoseconds_round(const int64_t nanoseconds) {
215 return nanoseconds < 0 ? add_microseconds((nanoseconds - 500) / 1000)
216 : add_microseconds((nanoseconds + 500) / 1000);
217 }
218
219 /**
220 Convert server time value to storage engine interface format
221
222 @param [out] ptr The buffer to put value at.
223 @param dec Precision.
224 */
225 void store_time(uint8_t *ptr, uint32_t dec) const;
226
227 /**
228 Convert from storage engine interface time format to server time value.
229
230 @param ptr The pointer to read the value at.
231 @param dec Precision.
232 @param[out] time Returned time value
233 */
234 static void load_time(const uint8_t *ptr, uint32_t dec, Time_val *time);
235
236 size_t to_string(char *buffer, uint32_t dec) const;
237
238 std::string to_string() const;
239
240 private:
241 explicit Time_val(int64_t val) : m_value(val) {}
242
243 /// Set microsecond part of time value
244 void set_microsecond(uint32_t fraction) {
245 m_value = (m_value & ~BITS_MICROSEC) |
246 (is_negative() ? (0xFFFFFFU - fraction) : fraction);
247 }
248
249 bool add_seconds(int32_t seconds) {
250 Time_val tv(seconds < 0, 0, 0, static_cast<uint8_t>(abs(seconds)), 0);
251 add(tv, false);
252 assert(is_valid());
253 return false;
254 }
255
256 bool add_microseconds(int64_t mu) {
257 int64_t signed_micro =
259 if (is_negative()) signed_micro = -signed_micro;
260 signed_micro += mu;
261 bool negative = signed_micro < 0;
262 uint64_t micro = negative ? -signed_micro : signed_micro;
263 if (micro > MAX_TIME_MICROSEC) {
264 return true;
265 }
266 uint32_t seconds = static_cast<uint32_t>(micro / TIME_MULT_SECOND);
267 micro %= TIME_MULT_SECOND;
268 *this = Time_val(negative, seconds, micro);
269 assert(is_valid());
270 return false;
271 }
272
273 bool is_valid() const {
274 return hour() <= TIME_MAX_HOUR && minute() <= TIME_MAX_MINUTE &&
276 m_value <= MAX_TIME_VALUE && m_value >= MIN_TIME_VALUE &&
277 m_value != 0x7fffffffffff;
278 }
279
280 static uint32_t unsigned_seconds(uint32_t hour, uint32_t minute,
281 uint32_t second) {
282 return (hour * SECS_PER_HOUR) + (minute * SECS_PER_MIN) + second;
283 }
284
285 static uint64_t unsigned_microsec(uint32_t hour, uint32_t minute,
286 uint32_t second, uint32_t microsec) {
287 return (hour * TIME_MULT_HOUR) + (minute * TIME_MULT_MINUTE) +
288 (second * TIME_MULT_SECOND) + microsec;
289 }
290
291 static constexpr const uint32_t TIME_MAX_HOUR = 838;
292 static constexpr const uint32_t TIME_MAX_MINUTE = 59;
293 static constexpr const uint32_t TIME_MAX_SECOND = 59;
294 static constexpr const uint32_t TIME_MAX_MICROSEC = 999999;
295
296 static constexpr uint64_t TIME_MULT_SECOND = 1000000;
297 static constexpr uint64_t TIME_MULT_MINUTE = 60000000;
298 static constexpr uint64_t TIME_MULT_HOUR = 3600000000;
299
300 static constexpr uint64_t BITS_MICROSEC = 0x0000000000FFFFFF;
301 static constexpr uint64_t BITS_SECOND = 0x000000003F000000;
302 static constexpr uint64_t BITS_MINUTE = 0x0000000FC0000000;
303 static constexpr uint64_t BITS_HOUR = 0x00007FF000000000;
304 static constexpr uint64_t BITS_SIGN = 0x0000800000000000;
305 static constexpr int TIME_SHIFT_SECOND = 24;
306 static constexpr int TIME_SHIFT_MINUTE = 30;
307 static constexpr int TIME_SHIFT_HOUR = 36;
308
309 static constexpr uint64_t MAX_TIME_VALUE =
310 BITS_SIGN | (static_cast<uint64_t>(TIME_MAX_HOUR) << TIME_SHIFT_HOUR) |
311 (static_cast<uint64_t>(TIME_MAX_MINUTE) << TIME_SHIFT_MINUTE) |
312 (static_cast<uint64_t>(TIME_MAX_SECOND) << TIME_SHIFT_SECOND);
313
314 static constexpr uint64_t MIN_TIME_VALUE =
315 (static_cast<uint64_t>(-static_cast<int64_t>(MAX_TIME_VALUE)) &
317 1;
318
319 // 838:59:59.000000
320 static constexpr uint64_t MAX_TIME_MICROSEC =
323
324 /**
325 A TIME value is stored in bit coded fields in a 64 bit unsigned value.
326 The format is efficient for comparison, storage, retrieval and movement.
327 The fields are stored in two's complement, but with a sign bit set for
328 non-negative values. This means that values can be compared using regular
329 unsigned integer logic. Note that the supplied default value is invalid,
330 and must be replaced with a valid one to avoid an assertion error.
331 Format:
332 Bits 0-23: microseconds (0-999999)
333 Bits 24-29: seconds (0-59)
334 Bits 30-35: minutes (0-59)
335 Bits 36-46: hours (0-838) (Theoretical range up to 2047)
336 Bits 47-47: Sign (1 for positive value, 0 for negative value)
337 */
338 uint64_t m_value = 0xffffffffffffffff;
339};
340
341class Datetime_val : public MYSQL_TIME {
342 public:
344 year = 0;
345 month = 0;
346 day = 0;
347 hour = 0;
348 minute = 0;
349 second = 0;
350 second_part = 0;
351 neg = false;
354 }
355 Datetime_val(uint32_t year_arg, uint32_t month_arg, uint32_t day_arg,
356 uint32_t hour_arg, uint32_t minute_arg, uint32_t second_arg,
357 uint32_t micro_arg) {
358 year = year_arg;
359 month = month_arg;
360 day = day_arg;
361 hour = hour_arg;
362 minute = minute_arg;
363 second = second_arg;
364 second_part = micro_arg;
365 neg = false;
368 }
369 Datetime_val(uint32_t year_arg, uint32_t month_arg, uint32_t day_arg,
370 uint32_t hour_arg, uint32_t minute_arg, uint32_t second_arg,
371 uint32_t micro_arg, int32_t time_zone_displacement_arg) {
372 year = year_arg;
373 month = month_arg;
374 day = day_arg;
375 hour = hour_arg;
376 minute = minute_arg;
377 second = second_arg;
378 second_part = micro_arg;
379 neg = false;
381 time_zone_displacement = time_zone_displacement_arg;
382 }
383 Datetime_val(uint32_t year_arg, uint32_t month_arg, uint32_t day_arg) {
384 year = year_arg;
385 month = month_arg;
386 day = day_arg;
387 hour = 0;
388 minute = 0;
389 second = 0;
390 second_part = 0;
391 neg = false;
394 }
395 explicit Datetime_val(const MYSQL_TIME &mtime)
396 : Datetime_val(mtime.year, mtime.month, mtime.day, mtime.hour,
397 mtime.minute, mtime.second, mtime.second_part) {
398 assert(mtime.time_type == MYSQL_TIMESTAMP_DATETIME);
399 }
400};
401
402/**
403 Date_val is a temporal type that represents dates within the range
404 0000-01-01 and 9999-12-31. In addition, dates with zero values for
405 date and month are supported, for use with certain relaxed SQL modes.
406 Furthermore, a date object may accept invalid dates, but only with
407 day values not greater than 31 and year and month values must be in the
408 supported range.
409
410 Date_val implements a proleptic Gregorian calendar, where the rules for
411 leap years are extended back to year 0, except that year 0 itself is not
412 a leap year, even though it matches the common rule. The latter is for
413 compatibility with older implementations.
414
415 The SQL standard is defined for years in range from 0 to 9999, thus
416 the range that MySQL supports is standard compliant.
417
418 The class has constructors for creating date values from date components
419 (year, month and day), and from MYSQL_TIME objects.
420*/
421class Date_val {
422 public:
423 Date_val() = default;
424
425 Date_val(uint32_t year, uint32_t month, uint32_t day) {
426 assert(year <= 9999 && month <= 12 && day <= 31);
428 }
429
430 explicit Date_val(const MYSQL_TIME &mtime)
431 : Date_val(mtime.year, mtime.month, mtime.day) {
432 assert(mtime.time_type == MYSQL_TIMESTAMP_DATE);
433 }
434
435 explicit Date_val(uint32_t day_number) {
436 assert(day_number > 0 && day_number <= DATE_LAST_DAY);
437 uint32_t year, month, day;
440 (day + 1);
441 }
442
443 uint32_t year() const {
445 }
446 uint32_t month() const {
448 }
449 uint32_t day() const { return (m_value & DATE_BITS_DAY); }
450
451 /// @returns true if date is the zero date (0000-00-00)
452 bool is_zero_date() const { return m_value == 0; }
453 /**
454 @returns whether the value is less than, equal to or greater than
455 the argument value.
456 */
457 int compare(const Date_val arg) const {
458 return m_value < arg.m_value ? -1 : m_value > arg.m_value ? 1 : 0;
459 }
460 /// @returns an integer value for comparison purposes
461 int32_t for_comparison() const { return m_value; }
462 /**
463 Check date for validity, according to calendar and validation flags.
464
465 @param flags validation flags
466
467 @returns = 0: date value is correct
468 = MYSQL_TIME_WARN_ZERO_DATE date is invalid zero date
469 = MYSQL_TIME_WARN_ZERO_IN_DATE date has invalid zero component
470 = MYSQL_TIME_WARN_OUT_OF_RANGE out-of range day value
471 */
473 /**
474 @returns day number of a date, January 1 of year 0 returns 1.
475
476 Date must have valid year, month and day values (month 0 and day 0 are
477 invalid), but there is no other validity check (e.g February 31 is allowed).
478 */
479 uint32_t day_number() const;
480
481 /// @returns last day number in range
482 static uint32_t last_day_number() { return DATE_LAST_DAY; }
483
484 /// Set zero date
485 inline void set_zero() { m_value = 0; }
486
487 bool operator==(const Date_val rhs) const { return m_value == rhs.m_value; }
488
489 bool operator<(const Date_val rhs) const { return m_value < rhs.m_value; }
490
491 /**
492 Add an interval to a date value, or subtract it
493
494 @param iv Interval to add or subtract
495 @param subtract If true, subtract the interval value, otherwise add it.
496
497 @returns false if result is within valid date range, true otherwise.
498 */
499 bool add(Interval &iv, bool subtract);
500 /**
501 Adjust date to have last day of month.
502 Setting last day of month zero is not a valid operation.
503 */
505 /**
506 Make date from year, month and day components, according to validation flags
507
508 @param year year component
509 @param month month component
510 @param day day component
511 @param flags flags for validation
512 @param[out] date constructed date, if date is valid
513
514 @returns = 0: values are valid
515 <> 0: value, out of range, zero component, or zero date
516 */
517 static int make_date(uint32_t year, uint32_t month, uint32_t day,
519
520 /// Creates a Date_val from a date_time by extracting only the date fields
521 static Date_val strip_time(const MYSQL_TIME &mtime);
522
523 /// Convert date value to the generalized temporal time format.
524 explicit operator MYSQL_TIME() const;
525
526 /// Convert date value to a datetime value, where time component is 00:00:00
527 explicit operator Datetime_val() const;
528
529 /// @returns base100 representation, '2025-02-29' is returned as 20250229
530 int32_t to_int() const;
531
532 /// @returns base100 representation, as double precision float
533 double to_double() const { return static_cast<double>(to_int()); }
534
535 /**
536 Convert server date value to storage engine interface format
537
538 @param [out] ptr The buffer to put value at.
539 */
540 void store_date(uint8_t *ptr) const { int3store(ptr, m_value); }
541
542 /**
543 Convert from storage engine interface date format to server date value.
544
545 @param ptr The pointer to read the value at.
546 @param[out] date Returned date value
547 */
548 static void load_date(const uint8_t *ptr, Date_val *date) {
549 date->m_value = uint3korr(ptr);
550 assert(date->is_valid());
551 }
552
553 size_t to_string(char *buffer) const;
554
555 std::string to_string() const;
556
557 private:
558 /// Internal date validity check. Zero date, invalid calendar dates are OK.
559 bool is_valid() const {
560 return year() <= DATE_MAX_YEAR && month() <= DATE_MAX_MONTH &&
561 day() <= DATE_MAX_DAY;
562 }
563
564 /**
565 @returns true if year is a leap year, false otherwise.
566
567 @note In this implementation, year zero is not a leap year,
568 even though it is so in ISO 8601.
569 */
570 static bool is_leap_year(uint32_t year) {
571 return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0) &&
572 year != 0;
573 }
574
575 /**
576 Convert day number to date. Day number 1 is date 0000-01-01.
577
578 @param daynr day number to convert
579 @param[out] year year of date, range is 0000 to 9999.
580 @param[out] month month of date (note: January is 0, February is 1, etc)
581 @param[out] day day of date, returned as a zero-based number
582 */
583 static void day_number_to_date(uint32_t daynr, uint32_t *year,
584 uint32_t *month, uint32_t *day);
585 static constexpr const uint32_t DATE_MAX_YEAR = 9999;
586 static constexpr const uint32_t DATE_MAX_MONTH = 12;
587 static constexpr const uint32_t DATE_MAX_DAY = 31;
588 static constexpr const uint32_t DATE_DAYS_IN_YEAR = 365;
589 static constexpr const uint32_t DATE_DAYS_IN_LEAP = 366;
590
591 static constexpr const uint32_t DATE_BITS_YEAR = 0x007FFE00;
592 static constexpr const uint32_t DATE_BITS_MONTH = 0x000001E0;
593 static constexpr const uint32_t DATE_BITS_DAY = 0x0000001F;
594 static constexpr const int DATE_SHIFT_YEAR = 9;
595 static constexpr const int DATE_SHIFT_MONTH = 5;
596
597 static constexpr const uint32_t DATE_LAST_DAY = 3652424;
598
599 /**
600 A DATE value is stored in bit coded fields in a 32 bit unsigned value.
601 The format is efficient for comparison, storage, retrieval and movement.
602 Values can be compared using regular unsigned integer logic.
603 The initial value is invalid, thus a separate initialization is required
604 for this member.
605 Format:
606 Bits 0- 4: day (0-31)
607 Bits 5- 8: month (0-12)
608 Bits 9-22: year (0-9999)
609 */
610 uint32_t m_value = 0xffffffff;
611};
612
613/**
614 @} (end of ingroup MY_TEMPORAL)
615*/
616#endif // MY_TEMPORAL_H
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
uint32_t year() const
Definition: my_temporal.h:443
Date_val()=default
uint32_t m_value
A DATE value is stored in bit coded fields in a 32 bit unsigned value.
Definition: my_temporal.h:610
static constexpr const uint32_t DATE_BITS_DAY
Definition: my_temporal.h:593
double to_double() const
Definition: my_temporal.h:533
Date_val(uint32_t year, uint32_t month, uint32_t day)
Definition: my_temporal.h:425
static constexpr const uint32_t DATE_BITS_MONTH
Definition: my_temporal.h:592
int32_t for_comparison() const
Definition: my_temporal.h:461
uint32_t day() const
Definition: my_temporal.h:449
Date_val(uint32_t day_number)
Definition: my_temporal.h:435
static constexpr const int DATE_SHIFT_YEAR
Definition: my_temporal.h:594
bool operator==(const Date_val rhs) const
Definition: my_temporal.h:487
static constexpr const uint32_t DATE_LAST_DAY
Definition: my_temporal.h:597
static constexpr const uint32_t DATE_DAYS_IN_LEAP
Definition: my_temporal.h:589
static uint32_t last_day_number()
Definition: my_temporal.h:482
void store_date(uint8_t *ptr) const
Convert server date value to storage engine interface format.
Definition: my_temporal.h:540
static bool is_leap_year(uint32_t year)
Definition: my_temporal.h:570
void set_zero()
Set zero date.
Definition: my_temporal.h:485
Date_val(const MYSQL_TIME &mtime)
Definition: my_temporal.h:430
bool is_zero_date() const
Definition: my_temporal.h:452
static constexpr const uint32_t DATE_MAX_MONTH
Definition: my_temporal.h:586
static void load_date(const uint8_t *ptr, Date_val *date)
Convert from storage engine interface date format to server date value.
Definition: my_temporal.h:548
static constexpr const uint32_t DATE_MAX_DAY
Definition: my_temporal.h:587
bool operator<(const Date_val rhs) const
Definition: my_temporal.h:489
uint32_t month() const
Definition: my_temporal.h:446
bool is_valid() const
Internal date validity check. Zero date, invalid calendar dates are OK.
Definition: my_temporal.h:559
int compare(const Date_val arg) const
Definition: my_temporal.h:457
static constexpr const uint32_t DATE_MAX_YEAR
Definition: my_temporal.h:585
static constexpr const int DATE_SHIFT_MONTH
Definition: my_temporal.h:595
static constexpr const uint32_t DATE_BITS_YEAR
Definition: my_temporal.h:591
static constexpr const uint32_t DATE_DAYS_IN_YEAR
Definition: my_temporal.h:588
Definition: my_temporal.h:341
Datetime_val(const MYSQL_TIME &mtime)
Definition: my_temporal.h:395
Datetime_val(uint32_t year_arg, uint32_t month_arg, uint32_t day_arg, uint32_t hour_arg, uint32_t minute_arg, uint32_t second_arg, uint32_t micro_arg, int32_t time_zone_displacement_arg)
Definition: my_temporal.h:369
Datetime_val()
Definition: my_temporal.h:343
Datetime_val(uint32_t year_arg, uint32_t month_arg, uint32_t day_arg)
Definition: my_temporal.h:383
Datetime_val(uint32_t year_arg, uint32_t month_arg, uint32_t day_arg, uint32_t hour_arg, uint32_t minute_arg, uint32_t second_arg, uint32_t micro_arg)
Definition: my_temporal.h:355
Time_val is a temporal type that represents only time.
Definition: my_temporal.h:57
uint32_t minute() const
Definition: my_temporal.h:97
uint32_t second() const
Definition: my_temporal.h:101
static constexpr int TIME_SHIFT_MINUTE
Definition: my_temporal.h:306
static constexpr int TIME_SHIFT_SECOND
Definition: my_temporal.h:305
Time_val(bool negative, uint32_t second, uint32_t microsecond)
Definition: my_temporal.h:81
void set_zero()
Set zero time.
Definition: my_temporal.h:126
static constexpr const uint32_t TIME_MAX_SECOND
Definition: my_temporal.h:293
bool is_extreme_value(bool positive) const
Check against extreme values.
Definition: my_temporal.h:121
Time_val(const MYSQL_TIME &mtime)
Definition: my_temporal.h:86
bool add_nanoseconds_round(const int64_t nanoseconds)
Definition: my_temporal.h:214
static constexpr uint64_t TIME_MULT_MINUTE
Definition: my_temporal.h:297
uint32_t microsecond() const
Definition: my_temporal.h:105
Time_val()=default
bool operator==(const Time_val rhs) const
Definition: my_temporal.h:133
int64_t for_comparison() const
Definition: my_temporal.h:118
static uint32_t unsigned_seconds(uint32_t hour, uint32_t minute, uint32_t second)
Definition: my_temporal.h:280
static constexpr uint64_t TIME_MULT_SECOND
Definition: my_temporal.h:296
Time_val(bool negative, uint32_t hour, uint32_t minute, uint32_t second, uint32_t microsecond)
Definition: my_temporal.h:61
static bool make_time(bool negative, uint32_t hour, uint32_t minute, uint32_t second, uint32_t microsecond, Time_val *time)
Static functions for creation.
Definition: my_temporal.h:162
static constexpr int TIME_SHIFT_HOUR
Definition: my_temporal.h:307
bool add_seconds(int32_t seconds)
Definition: my_temporal.h:249
bool add_microseconds(int64_t mu)
Definition: my_temporal.h:256
static constexpr uint64_t MAX_TIME_MICROSEC
Definition: my_temporal.h:320
static constexpr uint64_t MAX_TIME_VALUE
Definition: my_temporal.h:309
uint32_t hour() const
Definition: my_temporal.h:93
uint64_t m_value
A TIME value is stored in bit coded fields in a 64 bit unsigned value.
Definition: my_temporal.h:338
static constexpr uint64_t BITS_MINUTE
Definition: my_temporal.h:302
int compare(const Time_val arg) const
Definition: my_temporal.h:114
static constexpr uint64_t TIME_MULT_HOUR
Definition: my_temporal.h:298
Time_val(int64_t val)
Definition: my_temporal.h:241
static uint64_t unsigned_microsec(uint32_t hour, uint32_t minute, uint32_t second, uint32_t microsec)
Definition: my_temporal.h:285
void set_extreme_value(bool negative)
Set extreme value.
Definition: my_temporal.h:129
static constexpr uint64_t MIN_TIME_VALUE
Definition: my_temporal.h:314
void set_microsecond(uint32_t fraction)
Set microsecond part of time value.
Definition: my_temporal.h:244
int64_t to_microseconds() const
Definition: my_temporal.h:184
static constexpr const uint32_t TIME_MAX_MICROSEC
Definition: my_temporal.h:294
static constexpr uint64_t BITS_SIGN
Definition: my_temporal.h:304
static constexpr uint64_t BITS_SECOND
Definition: my_temporal.h:301
static constexpr uint64_t BITS_MICROSEC
Definition: my_temporal.h:300
static constexpr uint64_t BITS_HOUR
Definition: my_temporal.h:303
static constexpr const uint32_t TIME_MAX_HOUR
Definition: my_temporal.h:291
bool operator<(const Time_val rhs) const
Definition: my_temporal.h:135
bool is_negative() const
Definition: my_temporal.h:92
bool is_valid() const
Definition: my_temporal.h:273
int32_t to_seconds() const
Definition: my_temporal.h:179
static constexpr const uint32_t TIME_MAX_MINUTE
Definition: my_temporal.h:292
static const std::string dec("DECRYPTION")
static int make_date(uint32_t year, uint32_t month, uint32_t day, my_time_flags_t flags, Date_val *date)
Make date from year, month and day components, according to validation flags.
Definition: my_temporal.cc:310
std::string to_string() const
Definition: my_temporal.cc:468
void adjust_fraction(uint32_t decimals, bool round)
Definition: my_temporal.cc:66
static void day_number_to_date(uint32_t daynr, uint32_t *year, uint32_t *month, uint32_t *day)
Convert day number to date.
Definition: my_temporal.cc:346
bool add(Time_val tv, bool subtract)
Add a time value to another time value, or subtract it.
Definition: my_temporal.cc:96
static Time_val strip_date(const MYSQL_TIME &mt)
Creates a Time_val from a date_time by extracting only the time fields.
Definition: my_temporal.cc:166
static Date_val strip_time(const MYSQL_TIME &mtime)
Creates a Date_val from a date_time by extracting only the date fields.
Definition: my_temporal.cc:435
bool add(Interval &iv, bool subtract)
Add an interval to a date value, or subtract it.
Definition: my_temporal.cc:376
int64_t to_int_truncated() const
base100 representation without microsecond, '-12:34:56.999999' is returned as -123456
Definition: my_temporal.cc:276
int check_date(my_time_flags_t flags) const
Check date for validity, according to calendar and validation flags.
Definition: my_temporal.cc:320
int32_t to_int() const
Definition: my_temporal.cc:452
void set_last_day_of_month()
Adjust date to have last day of month.
Definition: my_temporal.cc:427
double to_double() const
base100 representation with microseconds, returned as double precision float
Definition: my_temporal.cc:281
void store_time(uint8_t *ptr, uint32_t dec) const
Convert server time value to storage engine interface format.
Definition: my_temporal.cc:186
uint32_t day_number() const
Definition: my_temporal.cc:456
uint32_t actual_decimals() const
Definition: my_temporal.cc:58
std::string to_string() const
Definition: my_temporal.cc:304
int64_t to_int_rounded() const
base100 representation without microsecond, but rounded '-12:34:56.999999' is returned as -123457
Definition: my_temporal.cc:269
static void load_time(const uint8_t *ptr, uint32_t dec, Time_val *time)
Convert from storage engine interface time format to server time value.
Definition: my_temporal.cc:228
bool is_adjusted(uint32_t decimals) const
Definition: my_temporal.cc:53
static int flags[50]
Definition: hp_test1.cc:40
@ MYSQL_TIMESTAMP_TIME
Stores hour, minute, second and microsecond.
Definition: mysql_time.h:60
@ MYSQL_TIMESTAMP_DATETIME_TZ
A temporary type for DATETIME or TIMESTAMP types equipped with time zone information.
Definition: mysql_time.h:67
@ 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
struct MYSQL_TIME MYSQL_TIME
Functions for reading and storing in machine-independent format.
void int3store(char *pT, uint A)
Definition: my_byteorder.h:176
uint32 uint3korr(const char *pT)
Definition: my_byteorder.h:144
Interface for low level time utilities.
constexpr const int MINS_PER_HOUR
Definition: my_time.h:149
unsigned int my_time_flags_t
Flags to str_to_datetime and int_to_datetime.
Definition: my_time.h:87
constexpr const int SECS_PER_MIN
Definition: my_time.h:148
constexpr const int SECS_PER_HOUR
Definition: my_time.h:154
Storing of values in high byte first order.
std::chrono::seconds seconds
Definition: authorize_manager.cc:70
ValueType abs(const ValueType v1, const ValueType v2)
Definition: gtid.h:75
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Struct representing a duration.
Definition: my_time.h:231
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