drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
temporal.cc
Go to the documentation of this file.
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2008 Sun Microsystems, Inc.
5 *
6 * Authors:
7 *
8 * Jay Pipes <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
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 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
36
37#include <config.h>
38
39#include <drizzled/charset.h>
40#include <drizzled/type/decimal.h>
41#include <drizzled/calendar.h>
42#include <drizzled/temporal.h>
44#include <drizzled/time_functions.h>
45#include "time.h"
46
47#include <drizzled/util/gmtime.h>
48
49#include <time.h>
50
51#include <cstdio>
52#include <ostream>
53#include <iomanip>
54#include <vector>
55#include <string.h>
56
57namespace drizzled {
58
59extern std::vector<TemporalFormat *> known_datetime_formats;
60extern std::vector<TemporalFormat *> known_date_formats;
61extern std::vector<TemporalFormat *> known_time_formats;
62
63Temporal::Temporal() :
64 _calendar(GREGORIAN),
65 _years(0),
66 _months(0),
67 _days(0),
68 _hours(0),
69 _minutes(0),
70 _seconds(0),
71 _epoch_seconds(0),
72 _useconds(0),
73 _nseconds(0),
74 _overflow(false)
75{}
76
78{
79 return (uint64_t) ((_hours * INT64_C(3600))
80 + (_minutes * INT64_C(60))
81 + _seconds);
82}
83
84
86{
87 /*
88 * If the temporal is in the range of a timestamp, set
89 * the epoch_seconds member variable
90 */
91 if (in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds))
92 {
93 time_t result_time;
94 struct tm broken_time;
95
96 broken_time.tm_sec= _seconds;
97 broken_time.tm_min= _minutes;
98 broken_time.tm_hour= _hours;
99 broken_time.tm_mday= _days; /* Drizzle format uses ordinal, standard tm does too! */
100 broken_time.tm_mon= _months - 1; /* Drizzle format uses ordinal, standard tm does NOT! */
101 broken_time.tm_year= _years - 1900; /* tm_year expects range of 70 - 38 */
102
103 result_time= timegm(&broken_time);
104
105 _epoch_seconds= result_time;
106 }
107}
108
109bool Date::from_string(const char *from, size_t from_len)
110{
111 _useconds= 0; // We may not match on it, so we need to make sure we zero it out.
112 for (TemporalFormat* it : known_date_formats)
113 {
114 if (not it->matches(from, from_len, this))
115 continue;
117 return is_valid();
118 }
119 return false;
120}
121
122bool DateTime::from_string(const char *from, size_t from_len)
123{
124 for (TemporalFormat* it : known_datetime_formats)
125 {
126 if (not it->matches(from, from_len, this))
127 continue;
129 return is_valid();
130 }
131 return false;
132
133}
134
135/*
136 * Comparison operators for Time against another Time
137 * are easy. We simply compare the cumulative time
138 * value of each.
139 */
140bool Time::operator==(const Time& rhs)
141{
142 return (
143 _hours == rhs._hours
144 && _minutes == rhs._minutes
145 && _seconds == rhs._seconds
146 && _useconds == rhs._useconds
147 && _nseconds == rhs._nseconds
148 );
149}
150bool Time::operator!=(const Time& rhs)
151{
152 return ! (*this == rhs);
153}
154bool Time::operator<(const Time& rhs)
155{
156 return (_cumulative_seconds_in_time() < rhs._cumulative_seconds_in_time());
157}
158bool Time::operator<=(const Time& rhs)
159{
160 return (_cumulative_seconds_in_time() <= rhs._cumulative_seconds_in_time());
161}
162bool Time::operator>(const Time& rhs)
163{
164 return (_cumulative_seconds_in_time() > rhs._cumulative_seconds_in_time());
165}
166bool Time::operator>=(const Time& rhs)
167{
168 return (_cumulative_seconds_in_time() >= rhs._cumulative_seconds_in_time());
169}
170
193const Time Time::operator-(const Time& rhs)
194{
195 Time result;
196
197 int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
198 result._hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
199 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
200 result._minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
201 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
202 result._seconds= (uint32_t) second_diff;
203
204 return result;
205}
206const Time Time::operator+(const Time& rhs)
207{
208 Time result;
209 int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
210 result._hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
211 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
212 result._minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
213 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
214 result._seconds= (uint32_t) second_diff;
219 return result;
220}
221
222/*
223 * Variation of + and - operator which returns a reference to the left-hand
224 * side Time object and adds the right-hand side to itself.
225 */
226Time& Time::operator+=(const Time& rhs)
227{
228 int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
229 _hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
230 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
231 _minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
232 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
233 _seconds= (uint32_t) second_diff;
238 return *this;
239}
240Time& Time::operator-=(const Time& rhs)
241{
242 int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
243 _hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
244 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
245 _minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
246 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
247 _seconds= (uint32_t) second_diff;
252 return *this;
253}
254
255/*
256 * Comparison operators for Date against another Date
257 * are easy. We simply compare the cumulative
258 * value of each.
259 */
260bool Date::operator==(const Date& rhs)
261{
262 return (
263 _years == rhs._years
264 && _months == rhs._months
265 && _days == rhs._days
266 );
267}
268bool Date::operator!=(const Date& rhs)
269{
270 return ! (*this == rhs);
271}
272bool Date::operator<(const Date& rhs)
273{
274 int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
275 int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
276 return (days_left < days_right);
277}
278bool Date::operator<=(const Date& rhs)
279{
280 int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
281 int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
282 return (days_left <= days_right);
283}
284bool Date::operator>(const Date& rhs)
285{
286 return ! (*this <= rhs);
287}
288bool Date::operator>=(const Date& rhs)
289{
290 return ! (*this < rhs);
291}
292
293/*
294 * Comparison operators for DateTime against another DateTime
295 * are easy. We simply compare the cumulative time
296 * value of each.
297 */
299{
300 return (
301 _years == rhs._years
302 && _months == rhs._months
303 && _days == rhs._days
304 && _hours == rhs._hours
305 && _minutes == rhs._minutes
306 && _seconds == rhs._seconds
307 && _useconds == rhs._useconds
308 && _nseconds == rhs._nseconds
309 );
310}
311bool Date::operator!=(const DateTime& rhs)
312{
313 return ! (*this == rhs);
314}
315bool Date::operator<(const DateTime& rhs)
316{
317 int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
318 int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
319 if (days_left < days_right)
320 return true;
321 else if (days_left > days_right)
322 return false;
323 /* Here if both dates are the same, so compare times */
324 return (_cumulative_seconds_in_time() < rhs._cumulative_seconds_in_time());
325}
326bool Date::operator<=(const DateTime& rhs)
327{
328 int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
329 int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
330 if (days_left < days_right)
331 return true;
332 else if (days_left > days_right)
333 return false;
334 /* Here if both dates are the same, so compare times */
335 return (_cumulative_seconds_in_time() <= rhs._cumulative_seconds_in_time());
336}
337bool Date::operator>(const DateTime& rhs)
338{
339 return ! (*this <= rhs);
340}
341bool Date::operator>=(const DateTime& rhs)
342{
343 return ! (*this < rhs);
344}
345
350const Date Date::operator-(const Time& rhs)
351{
352 DateTime result;
353
354 /*
355 * First, we set the resulting DATE pieces equal to our
356 * left-hand side DateTime's DATE components. Then, deal with
357 * the time components.
358 */
359 result._years= _years;
360 result._months= _months;
361 result._days= _days;
362
363 int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
364
365 /*
366 * The resulting diff might be negative. If it is, that means that
367 * we have subtracting a larger time piece from the datetime, like so:
368 *
369 * x = DateTime("2007-06-09 09:30:00") - Time("16:30:00");
370 *
371 * In these cases, we need to subtract a day from the resulting
372 * DateTime.
373 */
374 if (second_diff < 0)
375 result._days--;
376
377 result._hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
378 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
379 result._minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
380 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
381 result._seconds= (uint32_t) second_diff;
382
383 /* Handle the microsecond precision */
384 int64_t microsecond_diff= _useconds - rhs._useconds;
385 if (microsecond_diff < 0)
386 {
387 microsecond_diff= (-1 * microsecond_diff);
388 result._seconds--;
389 }
390 result._useconds= (uint32_t) microsecond_diff;
391
392 return result;
393}
394const Date Date::operator+(const Time& rhs)
395{
396 DateTime result;
397
398 /*
399 * First, we set the resulting DATE pieces equal to our
400 * left-hand side DateTime's DATE components. Then, deal with
401 * the time components.
402 */
403 result._years= _years;
404 result._months= _months;
405 result._days= _days;
406
407 int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
408
409 /*
410 * The resulting seconds might be more than a day. If do,
411 * adjust our resulting days up 1.
412 */
413 if (second_diff >= DRIZZLE_SECONDS_IN_DAY)
414 {
415 result._days++;
416 second_diff%= DRIZZLE_SECONDS_IN_DAY;
417 }
418
419 result._hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
420 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
421 result._minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
422 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
423 result._seconds= (uint32_t) second_diff;
424
425 /* Handle the microsecond precision */
426 int64_t microsecond_diff= _useconds - rhs._useconds;
427 if (microsecond_diff < 0)
428 {
429 microsecond_diff= (-1 * microsecond_diff);
430 result._seconds--;
431 }
432 result._useconds= (uint32_t) microsecond_diff;
433
434 return result;
435}
436
437/*
438 * Variation of + and - operator which returns a reference to the left-hand
439 * side DateTime object and adds the right-hand side Time to itself.
440 */
441Date& Date::operator+=(const Time& rhs)
442{
443 int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
444 /*
445 * The resulting seconds might be more than a day. If do,
446 * adjust our resulting days up 1.
447 */
448 if (second_diff >= DRIZZLE_SECONDS_IN_DAY)
449 {
450 _days++;
451 second_diff%= DRIZZLE_SECONDS_IN_DAY;
452 }
453
454 _hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
455 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
456 _minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
457 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
458 _seconds= (uint32_t) second_diff;
459
460 /* Handle the microsecond precision */
461 int64_t microsecond_diff= _useconds - rhs._useconds;
462 if (microsecond_diff < 0)
463 {
464 microsecond_diff= (-1 * microsecond_diff);
465 _seconds--;
466 }
467 _useconds= (uint32_t) microsecond_diff;
472 return *this;
473}
474Date& Date::operator-=(const Time& rhs)
475{
476 int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
477
478 /*
479 * The resulting diff might be negative. If it is, that means that
480 * we have subtracting a larger time piece from the datetime, like so:
481 *
482 * x = DateTime("2007-06-09 09:30:00");
483 * x-= Time("16:30:00");
484 *
485 * In these cases, we need to subtract a day from the resulting
486 * DateTime.
487 */
488 if (second_diff < 0)
489 _days--;
490
491 _hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
492 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
493 _minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
494 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
495 _seconds= (uint32_t) second_diff;
496
497 /* Handle the microsecond precision */
498 int64_t microsecond_diff= _useconds - rhs._useconds;
499 if (microsecond_diff < 0)
500 {
501 microsecond_diff= (-1 * microsecond_diff);
502 _seconds--;
503 }
504 _useconds= (uint32_t) microsecond_diff;
509 return *this;
510}
511
516const Date Date::operator-(const Date &rhs)
517{
518 /* Figure out the difference in days between the two dates */
519 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
520 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
521 int64_t day_diff= day_left - day_right;
522
523 Date result;
524 /* Now re-compose the Date's structure from the resulting Julian Day Number */
525 gregorian_date_from_julian_day_number(day_diff, &result._years, &result._months, &result._days);
526 return result;
527}
528const Date Date::operator+(const Date &rhs)
529{
530 /*
531 * Figure out the new Julian Day Number by adding the JDNs of both
532 * dates together.
533 */
534 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
535 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
536 int64_t day_diff= day_left + day_right;
537
539
540 Date result;
541 /* Now re-compose the Date's structure from the resulting Julian Day Number */
542 gregorian_date_from_julian_day_number(day_diff, &result._years, &result._months, &result._days);
543 return result;
544}
545/* Similar to the above, but we add/subtract the right side to this object itself */
546Date& Date::operator-=(const Date &rhs)
547{
548 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
549 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
550 int64_t day_diff= day_left - day_right;
551
552 /* Now re-compose the Date's structure from the resulting Julian Day Number */
553 gregorian_date_from_julian_day_number(day_diff, &_years, &_months, &_days);
554 return *this;
555}
556Date& Date::operator+=(const Date &rhs)
557{
558 /*
559 * Figure out the new Julian Day Number by adding the JDNs of both
560 * dates together.
561 */
562 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
563 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
564 int64_t day_diff= day_left + day_right;
565
567
568 /* Now re-compose the Date's structure from the resulting Julian Day Number */
569 gregorian_date_from_julian_day_number(day_diff, &_years, &_months, &_days);
570 return *this;
571}
572
573Date& Date::operator=(const DateTime &rhs)
574{
575 /* Only copy the Date components of the assigned DateTime... */
576 _years= rhs._years;
577 _months= rhs._months;
578 _days= rhs._days;
579 /* Zero-out everything else.. */
580 _hours= _minutes= _seconds= _useconds= _nseconds= 0;
581 return *this;
582}
583
588const Date Date::operator-(const DateTime &rhs)
589{
590 /* Figure out the difference in days between the two dates. */
591 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
592 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
593 int64_t day_diff= day_left - day_right;
594
595 DateTime result;
596 /* Now re-compose the Date's structure from the resulting Julian Day Number */
597 gregorian_date_from_julian_day_number(day_diff, &result._years, &result._months, &result._days);
598
599 /* And now handle the time components */
600 int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
601
602 /*
603 * The resulting diff might be negative. If it is, that means that
604 * we have subtracting a larger time piece from the datetime, like so:
605 *
606 * x = DateTime("2007-06-09 09:30:00");
607 * x-= Time("16:30:00");
608 *
609 * In these cases, we need to subtract a day from the resulting
610 * DateTime.
611 */
612 if (second_diff < 0)
613 _days--;
614
615 result._hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
616 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
617 result._minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
618 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
619 result._seconds= (uint32_t) second_diff;
620
621 /* Handle the microsecond precision */
622 int64_t microsecond_diff= _useconds - rhs._useconds;
623 if (microsecond_diff < 0)
624 {
625 microsecond_diff= (-1 * microsecond_diff);
626 result._seconds--;
627 }
628 result._useconds= (uint32_t) microsecond_diff;
629
630 return result;
631}
632const Date Date::operator+(const DateTime &rhs)
633{
634 /*
635 * Figure out the new Julian Day Number by adding the JDNs of both
636 * dates together.
637 */
638 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
639 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
640 int64_t day_diff= day_left + day_right;
641
643
644 DateTime result;
645 /* Now re-compose the Date's structure from the resulting Julian Day Number */
646 gregorian_date_from_julian_day_number(day_diff, &result._years, &result._months, &result._days);
647
648 /* And now handle the time components */
649 int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
650
651 /*
652 * The resulting seconds might be more than a day. If do,
653 * adjust our resulting days up 1.
654 */
655 if (second_diff >= DRIZZLE_SECONDS_IN_DAY)
656 {
657 result._days++;
658 second_diff%= DRIZZLE_SECONDS_IN_DAY;
659 }
660
661 result._hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
662 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
663 result._minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
664 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
665 result._seconds= (uint32_t) second_diff;
666
667 /* Handle the microsecond precision */
668 int64_t microsecond_diff= _useconds - rhs._useconds;
669 if (microsecond_diff < 0)
670 {
671 microsecond_diff= (-1 * microsecond_diff);
672 result._seconds--;
673 }
674 result._useconds= (uint32_t) microsecond_diff;
675
676 return result;
677}
678/* Similar to the above, but we add/subtract the right side to this object itself */
679Date& Date::operator-=(const DateTime &rhs)
680{
681 /* Figure out the difference in days between the two dates. */
682 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
683 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
684 int64_t day_diff= day_left - day_right;
685
686 /* Now re-compose the Date's structure from the ng Julian Day Number */
687 gregorian_date_from_julian_day_number(day_diff, &_years, &_months, &_days);
688
689 /* And now handle the time components */
690 int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
691
692 /*
693 * The resulting diff might be negative. If it is, that means that
694 * we have subtracting a larger time piece from the datetime, like so:
695 *
696 * x = DateTime("2007-06-09 09:30:00");
697 * x-= Time("16:30:00");
698 *
699 * In these cases, we need to subtract a day from the ng
700 * DateTime.
701 */
702 if (second_diff < 0)
703 _days--;
704
705 _hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
706 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
707 _minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
708 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
709 _seconds= (uint32_t) second_diff;
710
711 /* Handle the microsecond precision */
712 int64_t microsecond_diff= _useconds - rhs._useconds;
713 if (microsecond_diff < 0)
714 {
715 microsecond_diff= (-1 * microsecond_diff);
716 _seconds--;
717 }
718 _useconds= (uint32_t) microsecond_diff;
719
720 return *this;
721}
722Date& Date::operator+=(const DateTime &rhs)
723{
724 /*
725 * Figure out the new Julian Day Number by adding the JDNs of both
726 * dates together.
727 */
728 int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
729 int64_t day_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
730 int64_t day_diff= day_left + day_right;
731
733
734 /* Now re-compose the Date's structure from the ng Julian Day Number */
735 gregorian_date_from_julian_day_number(day_diff, &_years, &_months, &_days);
736
737 /* And now handle the time components */
738 int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
739
740 /*
741 * The resulting seconds might be more than a day. If do,
742 * adjust our ng days up 1.
743 */
744 if (second_diff >= DRIZZLE_SECONDS_IN_DAY)
745 {
746 _days++;
747 second_diff%= DRIZZLE_SECONDS_IN_DAY;
748 }
749
750 _hours= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_HOUR;
751 second_diff%= DRIZZLE_SECONDS_IN_HOUR;
752 _minutes= (uint32_t) second_diff / DRIZZLE_SECONDS_IN_MINUTE;
753 second_diff%= DRIZZLE_SECONDS_IN_MINUTE;
754 _seconds= (uint32_t) second_diff;
755
756 /* Handle the microsecond precision */
757 int64_t microsecond_diff= _useconds - rhs._useconds;
758 if (microsecond_diff < 0)
759 {
760 microsecond_diff= (-1 * microsecond_diff);
761 _seconds--;
762 }
763 _useconds= (uint32_t) microsecond_diff;
764
765 return *this;
766}
767
768/*
769 * Comparison operators between a Date and a Timestamp
770 */
771bool Date::operator==(const Timestamp& rhs)
772{
773 return (_years == rhs._years && _months == rhs._months && _days == rhs._days);
774}
775bool Date::operator!=(const Timestamp& rhs)
776{
777 return ! (*this == rhs);
778}
779bool Date::operator<(const Timestamp& rhs)
780{
781 if (_years < rhs._years)
782 return true;
783 if (_years > rhs._years)
784 return false;
785 /* In same year */
786 if (_months < rhs._months)
787 return true;
788 if (_months > rhs._months)
789 return false;
790 /* Same month */
791 return _days < rhs._days;
792}
793bool Date::operator<=(const Timestamp& rhs)
794{
795 return (*this < rhs || *this == rhs);
796}
797bool Date::operator>(const Timestamp& rhs)
798{
799 return ! (*this <= rhs);
800}
801bool Date::operator>=(const Timestamp& rhs)
802{
803 return ! (*this < rhs);
804}
805/*
806 * Comparison operators between a Timestamp and a Date
807 */
809{
810 return (_years == rhs._years && _months == rhs._months && _days == rhs._days);
811}
812bool Timestamp::operator!=(const Date& rhs)
813{
814 return ! (*this == rhs);
815}
816bool Timestamp::operator<(const Date& rhs)
817{
818 if (_years < rhs._years)
819 return true;
820 if (_years > rhs._years)
821 return false;
822 /* In same year */
823 if (_months < rhs._months)
824 return true;
825 if (_months > rhs._months)
826 return false;
827 /* Same month */
828 return _days < rhs._days;
829}
830bool Timestamp::operator<=(const Date& rhs)
831{
832 return (*this < rhs || *this == rhs);
833}
834bool Timestamp::operator>(const Date& rhs)
835{
836 return ! (*this <= rhs);
837}
838bool Timestamp::operator>=(const Date& rhs)
839{
840 return ! (*this < rhs);
841}
842/*
843 * Comparison operators between a Timestamp and a DateTime
844 */
845bool Timestamp::operator==(const DateTime& rhs)
846{
847 return (_years == rhs._years && _months == rhs._months && _days == rhs._days
848 && _hours == rhs._hours && _minutes == rhs._minutes && _seconds == rhs._seconds);
849}
850bool Timestamp::operator!=(const DateTime& rhs)
851{
852 return ! (*this == rhs);
853}
854bool Timestamp::operator<(const DateTime& rhs)
855{
856 if (_years < rhs._years)
857 return true;
858 if (_years > rhs._years)
859 return false;
860 /* In same year */
861 if (_months < rhs._months)
862 return true;
863 if (_months > rhs._months)
864 return false;
865 /* Same month */
866 if (_days < rhs._days)
867 return true;
868 if (_days > rhs._days)
869 return false;
870 /* Same day */
871 if (_hours < rhs._hours)
872 return true;
873 if (_hours > rhs._hours)
874 return false;
875 /* Same hour */
876 if (_minutes < rhs._minutes)
877 return true;
878 if (_minutes > rhs._minutes)
879 return false;
880 /* Same minute */
881 return _seconds < rhs._seconds;
882}
883bool Timestamp::operator<=(const DateTime& rhs)
884{
885 return (*this < rhs || *this == rhs);
886}
887bool Timestamp::operator>(const DateTime& rhs)
888{
889 return ! (*this <= rhs);
890}
891bool Timestamp::operator>=(const DateTime& rhs)
892{
893 return ! (*this < rhs);
894}
895/*
896 * Comparison operators between two Timestamps
897 */
898bool Timestamp::operator==(const Timestamp& rhs)
899{
900 return (_epoch_seconds == rhs._epoch_seconds);
901}
902bool Timestamp::operator!=(const Timestamp& rhs)
903{
904 return ! (*this == rhs);
905}
906bool Timestamp::operator<(const Timestamp& rhs)
907{
908 return (_epoch_seconds < rhs._epoch_seconds);
909}
910bool Timestamp::operator<=(const Timestamp& rhs)
911{
912 return (_epoch_seconds <= rhs._epoch_seconds);
913}
914bool Timestamp::operator>(const Timestamp& rhs)
915{
916 return ! (*this <= rhs);
917}
918bool Timestamp::operator>=(const Timestamp& rhs)
919{
920 return ! (*this < rhs);
921}
922
930std::ostream& operator<<(std::ostream& os, const Timestamp& subject)
931{
932 return os << subject.years() << '-'
933 << std::setw(2) << std::setfill('0') << subject.months() << '-'
934 << std::setw(2) << std::setfill('0') << subject.days() << ' '
935 << std::setw(2) << std::setfill('0') << subject.hours() << ':'
936 << std::setw(2) << std::setfill('0') << subject.minutes() << ':'
937 << std::setw(2) << std::setfill('0') << subject.seconds();
938}
939
940bool Time::from_string(const char *from, size_t from_len)
941{
942 for (TemporalFormat* it : known_time_formats)
943 {
944 if (not it->matches(from, from_len, this))
945 continue;
946 return is_fuzzy_valid();
947 }
948 return false;
949}
950
951int Time::to_string(char *to, size_t to_len) const
952{
953 return snprintf(to, to_len, "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32, _hours, _minutes, _seconds);
954}
955
956int Date::to_string(char *to, size_t to_len) const
957{
958 return snprintf(to, to_len, "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32, _years, _months, _days);
959}
960
961int DateTime::to_string(char *to, size_t to_len) const
962{
963 /* If the temporal has a microsecond component, use a slightly different output */
964 if (_useconds == 0)
965 {
966 return snprintf(to, to_len,
967 "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
968 _years, _months, _days, _hours, _minutes, _seconds);
969 }
970 else
971 {
972 return snprintf(to, to_len,
973 "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
974 _years, _months, _days, _hours, _minutes, _seconds, _useconds);
975 }
976}
977
978int MicroTimestamp::to_string(char *to, size_t to_len) const
979{
980 return snprintf(to, to_len,
981 "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
982 _years, _months, _days, _hours, _minutes, _seconds, _useconds);
983}
984
986{
987 int64_t time_portion= (((_hours * 100L) + _minutes) * 100L) + _seconds;
988 (void) int2_class_decimal(E_DEC_FATAL_ERROR, time_portion, false, to);
989 if (_useconds > 0)
990 {
991 to->buf[(to->intg-1) / 9 + 1]= _useconds * 1000;
992 to->frac= 6;
993 }
994}
995
997{
998 int64_t date_portion= (((_years * 100L) + _months) * 100L) + _days;
999 (void) int2_class_decimal(E_DEC_FATAL_ERROR, date_portion, false, to);
1000}
1001
1003{
1004 int64_t date_portion= (((_years * 100L) + _months) * 100L) + _days;
1005 int64_t time_portion= (((((date_portion * 100L) + _hours) * 100L) + _minutes) * 100L) + _seconds;
1006 (void) int2_class_decimal(E_DEC_FATAL_ERROR, time_portion, false, to);
1007 if (_useconds > 0)
1008 {
1009 to->buf[(to->intg-1) / 9 + 1]= _useconds * 1000;
1010 to->frac= 6;
1011 }
1012}
1013
1014void Date::to_int64_t(int64_t *to) const
1015{
1016 *to= (_years * INT32_C(10000)) + (_months * INT32_C(100)) + _days;
1017}
1018
1019void Date::to_int32_t(int32_t *to) const
1020{
1021 *to= (_years * INT32_C(10000)) + (_months * INT32_C(100)) + _days;
1022}
1023
1024void Time::to_int32_t(int32_t *to) const
1025{
1026 *to= (_hours * INT32_C(10000)) + (_minutes * INT32_C(100)) + _seconds;
1027}
1028
1029// We fill the structure based on just int
1030void Time::to_uint64_t(uint64_t &to) const
1031{
1032 to= (_hours * 60 * 60) + (_minutes * 60) + _seconds;
1033}
1034
1035void DateTime::to_int64_t(int64_t *to) const
1036{
1037 *to= ((
1038 (_years * INT64_C(10000))
1039 + (_months * INT64_C(100))
1040 + _days
1041 ) * INT64_C(1000000))
1042 + (
1043 (_hours * INT64_C(10000))
1044 + (_minutes * INT64_C(100) )
1045 + _seconds
1046 );
1047}
1048
1049void Date::to_tm(struct tm *to) const
1050{
1051 to->tm_sec= 0;
1052 to->tm_min= 0;
1053 to->tm_hour= 0;
1054 to->tm_mday= _days; /* Drizzle format uses ordinal, standard tm does too! */
1055 to->tm_mon= _months - 1; /* Drizzle format uses ordinal, standard tm does NOT! */
1056 to->tm_year= _years - 1900;
1057}
1058
1059void DateTime::to_tm(struct tm *to) const
1060{
1061 to->tm_sec= _seconds;
1062 to->tm_min= _minutes;
1063 to->tm_hour= _hours;
1064 to->tm_mday= _days; /* Drizzle format uses ordinal, standard tm does too! */
1065 to->tm_mon= _months - 1; /* Drizzle format uses ordinal, standard tm does NOT! */
1066 to->tm_year= _years - 1900;
1067}
1068
1069bool Date::from_julian_day_number(const int64_t from)
1070{
1071 gregorian_date_from_julian_day_number(from, &_years, &_months, &_days);
1072 return is_valid();
1073}
1074
1075void Date::to_julian_day_number(int64_t *to) const
1076{
1077 *to= julian_day_number_from_gregorian_date(_years, _months, _days);
1078}
1079
1083bool Date::from_int32_t(const int32_t from)
1084{
1085 return ((DateTime *) this)->from_int64_t((int64_t) from);
1086}
1087
1092bool Time::from_int32_t(const int32_t from)
1093{
1094 uint32_t copy_from= (uint32_t) from;
1095 _hours= copy_from / INT32_C(10000);
1096 _minutes= (copy_from % INT32_C(10000)) / INT32_C(100);
1097 _seconds= copy_from % INT32_C(100); /* Masks off all but last 2 digits */
1098 return is_valid();
1099}
1100
1106bool DateTime::from_int64_t(const int64_t from, bool convert)
1107{
1108 int64_t copy_from= from;
1109 int64_t part1;
1110 int64_t part2;
1111
1112 if (copy_from == 0LL)
1113 return false;
1114
1115 if (convert && copy_from < 10000101000000LL)
1116 {
1117 if (copy_from < 101)
1118 return false;
1119 else if (copy_from <= (DRIZZLE_YY_PART_YEAR-1)*10000L+1231L)
1120 copy_from= (copy_from+20000000L)*1000000L; /* YYMMDD, year: 2000-2069 */
1121 else if (copy_from < (DRIZZLE_YY_PART_YEAR)*10000L+101L)
1122 return false;
1123 else if (copy_from <= 991231L)
1124 copy_from= (copy_from+19000000L)*1000000L; /* YYMMDD, year: 1970-1999 */
1125 else if (copy_from < 10000101L)
1126 return false;
1127 else if (copy_from <= 99991231L)
1128 copy_from= copy_from*1000000L;
1129 else if (copy_from < 101000000L)
1130 return false;
1131 else if (copy_from <= (DRIZZLE_YY_PART_YEAR-1) * 10000000000LL + 1231235959LL)
1132 copy_from= copy_from + 20000000000000LL; /* YYMMDDHHMMSS, 2000-2069 */
1133 else if (copy_from < DRIZZLE_YY_PART_YEAR * 10000000000LL + 101000000LL)
1134 return false;
1135 else if (copy_from <= 991231235959LL)
1136 copy_from= copy_from + 19000000000000LL; /* YYMMDDHHMMSS, 1970-1999 */
1137 }
1138
1139 part1= (int64_t) (copy_from / 1000000LL);
1140 part2= (int64_t) (copy_from - (int64_t) part1 * 1000000LL);
1141 _years= (uint32_t) (part1/10000L);
1142
1143 part1%=10000L;
1144 _months= (uint32_t) part1 / 100;
1145 _days= (uint32_t) part1 % 100;
1146 _hours= (uint32_t) (part2/10000L);
1147
1148 part2%=10000L;
1149 _minutes= (uint32_t) part2 / 100;
1150 _seconds= (uint32_t) part2 % 100;
1151
1153 return is_valid();
1154}
1155
1156bool Date::in_unix_epoch() const
1157{
1158 return in_unix_epoch_range(_years, _months, _days, 0, 0, 0);
1159}
1160
1162{
1163 return in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds);
1164}
1165
1166bool Date::from_tm(const struct tm *from)
1167{
1168 _years= 1900 + from->tm_year;
1169 _months= 1 + from->tm_mon; /* Month is NOT ordinal for struct tm! */
1170 _days= from->tm_mday; /* Day IS ordinal for struct tm */
1171 _hours= from->tm_hour;
1172 _minutes= from->tm_min;
1173 _seconds= from->tm_sec;
1174 /* Set hires precision to zero */
1175 _useconds= 0;
1176 _nseconds= 0;
1177
1179 return is_valid();
1180}
1181
1182/*
1183 * We convert as if it's a Datetime, then simply
1184 * drop the date portions...
1185 */
1186bool Time::from_time_t(const time_t from)
1187{
1188 struct tm broken_time;
1189 struct tm *result;
1190
1191 result= util::gmtime(from, &broken_time);
1192 if (result != NULL)
1193 {
1194 _years= 0;
1195 _months= 0;
1196 _days= 0;
1197 _hours= broken_time.tm_hour;
1198 _minutes= broken_time.tm_min;
1199 _seconds= broken_time.tm_sec;
1200 _epoch_seconds= 0; /* Don't store the time_t, since we only use part of it */
1201 /* Set hires precision to zero */
1202 _useconds= 0;
1203 _nseconds= 0;
1204 return true; /* Always true... */
1205 }
1206 else
1207 return false;
1208}
1209
1210bool Date::from_time_t(const time_t from)
1211{
1212 struct tm broken_time;
1213 struct tm *result;
1214
1215 result= util::gmtime(from, &broken_time);
1216 if (result != NULL)
1217 {
1218 _years= 1900 + broken_time.tm_year;
1219 _months= 1 + broken_time.tm_mon; /* Month is NOT ordinal for struct tm! */
1220 _days= broken_time.tm_mday; /* Day IS ordinal for struct tm */
1221 _hours= 0;
1222 _minutes= 0;
1223 _seconds= 0;
1224 _epoch_seconds= 0; /* Don't store the time_t, since we only use part of it */
1225 /* Set hires precision to zero */
1226 _useconds= 0;
1227 _nseconds= 0;
1228 return is_valid();
1229 }
1230 else
1231 return false;
1232}
1233
1234bool DateTime::from_timeval(struct timeval &timeval_arg)
1235{
1236 struct tm broken_time;
1237 struct tm *result;
1238
1239 result= util::gmtime(timeval_arg.tv_sec, &broken_time);
1240 if (result != NULL)
1241 {
1242 _years= 1900 + broken_time.tm_year;
1243 _months= 1 + broken_time.tm_mon; /* Month is NOT ordinal for struct tm! */
1244 _days= broken_time.tm_mday; /* Day IS ordinal for struct tm */
1245 _hours= broken_time.tm_hour;
1246 _minutes= broken_time.tm_min;
1247 _seconds= broken_time.tm_sec;
1248 _epoch_seconds= timeval_arg.tv_sec;
1249 /* Set hires precision to zero */
1250 _useconds= timeval_arg.tv_usec;
1251 _nseconds= 0;
1252 return is_valid();
1253 }
1254 else
1255 {
1256 return false;
1257 }
1258}
1259
1260bool DateTime::from_time_t(const time_t from)
1261{
1262 struct tm broken_time;
1263 struct tm *result;
1264
1265 result= util::gmtime(from, &broken_time);
1266 if (result != NULL)
1267 {
1268 _years= 1900 + broken_time.tm_year;
1269 _months= 1 + broken_time.tm_mon; /* Month is NOT ordinal for struct tm! */
1270 _days= broken_time.tm_mday; /* Day IS ordinal for struct tm */
1271 _hours= broken_time.tm_hour;
1272 _minutes= broken_time.tm_min;
1273 _seconds= broken_time.tm_sec;
1274 _epoch_seconds= from;
1275 /* Set hires precision to zero */
1276 _useconds= 0;
1277 _nseconds= 0;
1278 return is_valid();
1279 }
1280 else
1281 {
1282 return false;
1283 }
1284}
1285
1286void Date::to_time_t(time_t &to) const
1287{
1288 if (in_unix_epoch())
1289 {
1290 to= _epoch_seconds;
1291 }
1292 else
1293 {
1294 to= 0;
1295 }
1296}
1297
1298void Timestamp::to_time_t(time_t &to) const
1299{
1300 to= _epoch_seconds;
1301}
1302
1303void MicroTimestamp::to_timeval(struct timeval &to) const
1304{
1305 to.tv_sec= _epoch_seconds;
1306 to.tv_usec= _useconds;
1307}
1308
1309void NanoTimestamp::to_timespec(struct timespec *to) const
1310{
1311 to->tv_sec= _epoch_seconds;
1312 to->tv_nsec= _nseconds;
1313}
1314
1315bool Date::is_valid() const
1316{
1317 return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1318 && (_months >= 1 && _months <= DRIZZLE_MAX_MONTHS)
1319 && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months));
1320}
1321
1322bool Time::is_valid() const
1323{
1324 return (_years == 0)
1325 && (_months == 0)
1326 && (_days == 0)
1327 && (_hours <= DRIZZLE_MAX_HOURS)
1328 && (_minutes <= DRIZZLE_MAX_MINUTES)
1329 && (_seconds <= DRIZZLE_MAX_SECONDS); /* No Leap second... TIME is for elapsed time... */
1330}
1331
1332bool Time::is_fuzzy_valid() const
1333{
1334 if (is_valid())
1335 return true;
1336
1337 return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1338 && (_months >= 1 && _months <= DRIZZLE_MAX_MONTHS)
1339 && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months))
1340 && (_hours <= DRIZZLE_MAX_HOURS)
1341 && (_minutes <= DRIZZLE_MAX_MINUTES)
1342 && (_seconds <= DRIZZLE_MAX_SECONDS); /* No Leap second... TIME is for elapsed time... */
1343}
1344
1346{
1347 return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1348 && (_months >= 1 && _months <= DRIZZLE_MAX_MONTHS)
1349 && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months))
1350 && (_hours <= DRIZZLE_MAX_HOURS)
1351 && (_minutes <= DRIZZLE_MAX_MINUTES)
1352 && (_seconds <= DRIZZLE_MAX_SECONDS_WITH_LEAP); /* Leap second... */
1353}
1354
1356{
1357 return DateTime::is_valid()
1358 && in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds)
1359 && (_seconds <= DRIZZLE_MAX_SECONDS);
1360}
1361
1363{
1364 return Timestamp::is_valid()
1365 && (_useconds <= UINT32_C(999999));
1366}
1367
1369{
1370 return Timestamp::is_valid()
1371 && (_useconds <= UINT32_C(999999))
1372 && (_nseconds <= UINT32_C(999999999));
1373}
1374
1375} /* namespace drizzled */
void to_tm(struct tm *to) const
Definition temporal.cc:1059
void to_decimal(type::Decimal *to) const
Definition temporal.cc:1002
virtual int to_string(char *to, size_t to_len) const
Definition temporal.cc:961
bool in_unix_epoch() const
Definition temporal.cc:1161
bool from_string(const char *from, size_t from_len)
Definition temporal.cc:122
bool from_int64_t(const int64_t from, bool convert)
Definition temporal.cc:1106
void to_int64_t(int64_t *to) const
Definition temporal.cc:1035
virtual bool is_valid() const
Definition temporal.cc:1345
bool from_time_t(const time_t from)
Definition temporal.cc:1260
virtual bool from_time_t(const time_t from)
Definition temporal.cc:1210
bool from_julian_day_number(const int64_t from)
Definition temporal.cc:1069
virtual void to_decimal(type::Decimal *to) const
Definition temporal.cc:996
virtual int to_string(char *to, size_t to_len) const
Definition temporal.cc:956
virtual void to_time_t(time_t &to) const
Definition temporal.cc:1286
virtual void to_int32_t(int32_t *to) const
Definition temporal.cc:1019
virtual void to_int64_t(int64_t *to) const
Definition temporal.cc:1014
const Date operator-(const Date &rhs)
Definition temporal.cc:516
virtual bool from_string(const char *from, size_t from_len)
Definition temporal.cc:109
void to_julian_day_number(int64_t *to) const
Definition temporal.cc:1075
virtual bool from_int32_t(const int32_t from)
Definition temporal.cc:1083
const Date operator+(const Date &rhs)
Definition temporal.cc:528
Date & operator+=(const Date &rhs)
Definition temporal.cc:556
virtual bool operator==(const Date &rhs)
Definition temporal.cc:260
Date & operator=(const DateTime &rhs)
Definition temporal.cc:573
virtual void to_tm(struct tm *to) const
Definition temporal.cc:1049
virtual bool from_tm(const struct tm *from)
Definition temporal.cc:1166
virtual bool is_valid() const
Definition temporal.cc:1315
int to_string(char *to, size_t to_len) const
Definition temporal.cc:978
void to_timeval(struct timeval &to) const
Definition temporal.cc:1303
void to_timespec(struct timespec *to) const
Definition temporal.cc:1309
friend class TemporalFormat
Definition temporal.h:184
uint32_t seconds() const
Definition temporal.h:130
uint32_t months() const
Definition temporal.h:146
uint32_t hours() const
Definition temporal.h:138
void set_epoch_seconds()
Definition temporal.cc:85
uint32_t minutes() const
Definition temporal.h:134
uint32_t years() const
Definition temporal.h:150
uint32_t days() const
Definition temporal.h:142
uint64_t _cumulative_seconds_in_time() const
Definition temporal.cc:77
bool is_valid() const
Definition temporal.cc:1322
bool from_time_t(const time_t from)
Definition temporal.cc:1186
void to_uint64_t(uint64_t &to) const
Definition temporal.cc:1030
bool operator==(const Time &rhs)
Definition temporal.cc:140
Time & operator+=(const Time &rhs)
Definition temporal.cc:226
const Time operator-(const Time &rhs)
Definition temporal.cc:193
void to_int32_t(int32_t *to) const
Definition temporal.cc:1024
void to_decimal(type::Decimal *to) const
Definition temporal.cc:985
const Time operator+(const Time &rhs)
Definition temporal.cc:206
Time & operator-=(const Time &rhs)
Definition temporal.cc:240
int to_string(char *to, size_t to_len) const
Definition temporal.cc:951
bool from_int32_t(const int32_t from)
Definition temporal.cc:1092
bool from_string(const char *from, size_t from_len)
Definition temporal.cc:940
bool operator==(const Date &rhs)
Definition temporal.cc:808
virtual bool is_valid() const
Definition temporal.cc:1355
void to_time_t(time_t &to) const
Definition temporal.cc:1298
TODO: Rename this file - func.h is stupid.
void gregorian_date_from_julian_day_number(int64_t julian_day, uint32_t *year_out, uint32_t *month_out, uint32_t *day_out)
Definition calendar.cc:140
int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition calendar.cc:93
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month)
Definition calendar.cc:309
bool in_unix_epoch_range(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t minute, uint32_t second)
Definition calendar.cc:328