Embedded Template Library 1.0
Loading...
Searching...
No Matches
year_month_day.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2025 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_IN_CHRONO_H
32 #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
33#endif
34
35namespace etl
36{
37 namespace chrono
38 {
40
41 //*************************************************************************
43 //*************************************************************************
45 {
46 public:
47
48 //*************************************************************************
50 //*************************************************************************
51 ETL_CONSTEXPR year_month_day()
52 : y()
53 , m()
54 , d()
55 {
56 }
57
58 //*************************************************************************
60 //*************************************************************************
61 ETL_CONSTEXPR14 year_month_day(const etl::chrono::year& y_, const etl::chrono::month& m_, const etl::chrono::day& d_) ETL_NOEXCEPT
62 : y(y_)
63 , m(m_)
64 , d(d_)
65 {
66 }
67
68 //*************************************************************************
70 //*************************************************************************
71 ETL_CONSTEXPR14 year_month_day(const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT;
72
73 //*************************************************************************
75 //*************************************************************************
76 ETL_CONSTEXPR14 year_month_day(const etl::chrono::sys_days& sd) ETL_NOEXCEPT
77 : y(0)
78 , m(0U)
79 , d(0U)
80 {
81 // Days since 1970-01-01
82 int days_since_epoch = static_cast<int>(sd.time_since_epoch().count());
83
84 // Start from 1970-01-01
85 etl::chrono::year current_year(1970);
86 etl::chrono::month current_month(1);
87
88 // Find the year
89 while (true)
90 {
91 int days_in_year = current_year.is_leap() ? 366 : 365;
92
93 if (days_since_epoch < days_in_year)
94 {
95 break;
96 }
97
98 days_since_epoch -= days_in_year;
99 ++current_year;
100 }
101
102 // Find the month
103 while (true)
104 {
105 unsigned char days_in_month = etl::chrono::private_chrono::days_in_month[static_cast<unsigned>(current_month)];
106 if (current_month == etl::chrono::February && current_year.is_leap())
107 {
108 ++days_in_month;
109 }
110
111 if (days_since_epoch < days_in_month)
112 {
113 break;
114 }
115
116 days_since_epoch -= days_in_month;
117 ++current_month;
118 }
119
120 // The remaining days are the day of the month (0-based)
121 y = current_year;
122 m = current_month;
123 d = etl::chrono::day(static_cast<unsigned>(days_since_epoch) + 1);
124 }
125
126 //*************************************************************************
128 //*************************************************************************
129 ETL_CONSTEXPR14 year_month_day(const etl::chrono::local_days& ld) ETL_NOEXCEPT
130 : y(0)
131 , m(0)
132 , d(0)
133 {
134 etl::chrono::year_month_day ymd = sys_days(ld.time_since_epoch());
135
136 y = ymd.year();
137 m = ymd.month();
138 d = ymd.day();
139 }
140
141 //*************************************************************************
143 //*************************************************************************
144 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::year year() const ETL_NOEXCEPT
145 {
146 return y;
147 }
148
149 //*************************************************************************
151 //*************************************************************************
152 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
153 {
154 return m;
155 }
156
157 //*************************************************************************
159 //*************************************************************************
160 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::day day() const ETL_NOEXCEPT
161 {
162 return d;
163 }
164
165 //*************************************************************************
167 //*************************************************************************
168 ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
169 {
170 // Check if the year, month, and day are valid individually
171 return y.ok() && m.ok() && d.ok() && d <= max_day_for_month();
172 }
173
174 //*************************************************************************
176 //*************************************************************************
177 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator+=(const etl::chrono::years& dy) ETL_NOEXCEPT
178 {
179 y += dy;
180
181 return *this;
182 }
183
184 //*************************************************************************
186 //*************************************************************************
187 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator+=(const etl::chrono::months& dm) ETL_NOEXCEPT
188 {
189 m += dm;
190
191 return *this;
192 }
193
194 //*************************************************************************
196 //*************************************************************************
197 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator-=(const etl::chrono::years& dy) ETL_NOEXCEPT
198 {
199 y -= dy;
200
201 return *this;
202 }
203
204 //*************************************************************************
206 //*************************************************************************
207 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator-=(const etl::chrono::months& dm) ETL_NOEXCEPT
208 {
209 m -= dm;
210
211 return *this;
212 }
213
214 //***********************************************************************
223 //***********************************************************************
224 ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day& other) const ETL_NOEXCEPT
225 {
226 if (y < other.y)
227 return -1;
228 if (y > other.y)
229 return 1;
230 if (m < other.m)
231 return -1;
232 if (m > other.m)
233 return 1;
234 if (d < other.d)
235 return -1;
236 if (d > other.d)
237 return 1;
238
239 return 0;
240 }
241
242 //***********************************************************************
244 //***********************************************************************
245 ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
246 {
247 int day_count = 0;
248
249 // Add days for years since 1970
250 for (etl::chrono::year yr(1970); yr < this->year(); ++yr)
251 {
252 day_count += yr.is_leap() ? 366 : 365;
253 }
254
255 // Add days for months in the current year
256 for (etl::chrono::month mth(1); mth < this->month(); ++mth)
257 {
258 day_count += private_chrono::days_in_month[static_cast<unsigned>(mth)];
259
260 if (mth == etl::chrono::February && this->year().is_leap())
261 {
262 ++day_count; // Add one day for leap year February
263 }
264 }
265
266 // Add days for the current month
267 day_count += static_cast<int>(static_cast<unsigned>(this->day()) - 1);
268
269 return sys_days(etl::chrono::days(day_count));
270 }
271
272 //***********************************************************************
274 //***********************************************************************
275 ETL_NODISCARD ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT
276 {
277 return local_days(sys_days(*this).time_since_epoch());
278 }
279
280 private:
281
282 //***********************************************************************
285 //***********************************************************************
286 ETL_CONSTEXPR14 etl::chrono::day max_day_for_month() const
287 {
288 unsigned char count = 0;
289
290 if (y.ok() && m.ok())
291 {
292 count = private_chrono::days_in_month[static_cast<unsigned>(m)];
293
294 if (y.is_leap() && (m == February))
295 {
296 ++count;
297 }
298 }
299
300 return etl::chrono::day(count);
301 }
302
303 etl::chrono::year y;
304 etl::chrono::month m;
305 etl::chrono::day d;
306 };
307
308 //*************************************************************************
310 //*************************************************************************
311 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator+(const etl::chrono::year_month_day& ymd, const etl::chrono::years& dy) ETL_NOEXCEPT
312 {
313 return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day());
314 }
315
316 //*************************************************************************
318 //*************************************************************************
319 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator+(const etl::chrono::years& dy, const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT
320 {
321 return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day());
322 }
323
324 //*************************************************************************
326 //*************************************************************************
327 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator+(const etl::chrono::year_month_day& ymd, const etl::chrono::months& dm) ETL_NOEXCEPT
328 {
329 return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day());
330 }
331
332 //*************************************************************************
334 //*************************************************************************
335 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator+(const etl::chrono::months& dm, const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT
336 {
337 return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day());
338 }
339
340 //*************************************************************************
342 //*************************************************************************
343 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator-(const etl::chrono::year_month_day& ymd, const etl::chrono::years& dy) ETL_NOEXCEPT
344 {
345 return etl::chrono::year_month_day(ymd.year() - dy, ymd.month(), ymd.day());
346 }
347
348 //*************************************************************************
350 //*************************************************************************
351 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator-(const etl::chrono::year_month_day& ymd, const etl::chrono::months& dm) ETL_NOEXCEPT
352 {
353 return etl::chrono::year_month_day(ymd.year(), ymd.month() - dm, ymd.day());
354 }
355
356 //*************************************************************************
358 //*************************************************************************
359 inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
360 {
361 return (lhs.year() == rhs.year()) && (lhs.month() == rhs.month()) && (lhs.day() == rhs.day());
362 }
363
364 //*************************************************************************
366 //*************************************************************************
367 inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
368 {
369 return !(lhs == rhs);
370 }
371
372 //*************************************************************************
374 //*************************************************************************
375 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator<(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
376 {
377 if (lhs.year() < rhs.year())
378 {
379 return true;
380 }
381 else if (lhs.year() == rhs.year())
382 {
383 if (lhs.month() < rhs.month())
384 {
385 return true;
386 }
387 else if (lhs.month() == rhs.month())
388 {
389 return (lhs.day() < rhs.day());
390 }
391 else
392 {
393 return false;
394 }
395 }
396 else
397 {
398 return false;
399 }
400 }
401
402 //*************************************************************************
404 //*************************************************************************
405 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator<=(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
406 {
407 return !(rhs < lhs);
408 }
409
410 //*************************************************************************
412 //*************************************************************************
413 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator>(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
414 {
415 return rhs < lhs;
416 }
417
418 //*************************************************************************
420 //*************************************************************************
421 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator>=(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
422 {
423 return !(lhs < rhs);
424 }
425
426 //***********************************************************************
428 //***********************************************************************
429#if ETL_USING_CPP20
430 [[nodiscard]]
431 inline constexpr auto operator<=>(const etl::chrono::year_month_day& lhs, const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
432 {
433 auto cmp = lhs.year() <=> rhs.year();
434
435 if (cmp != 0)
436 {
437 return cmp;
438 }
439
440 cmp = lhs.month() <=> rhs.month();
441
442 if (cmp != 0)
443 {
444 return cmp;
445 }
446
447 return lhs.day() <=> rhs.day();
448 }
449#endif
450
451 //*************************************************************************
453 //*************************************************************************
454 class year_month_day_last
455 {
456 public:
457
458 //*************************************************************************
460 //*************************************************************************
461 ETL_CONSTEXPR14 year_month_day_last(const etl::chrono::year& y_, const etl::chrono::month_day_last& mdl_) ETL_NOEXCEPT
462 : y(y_)
463 , m(mdl_.month())
464 {
465 }
466
467 //*************************************************************************
469 //*************************************************************************
470 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::year year() const ETL_NOEXCEPT
471 {
472 return y;
473 }
474
475 //*************************************************************************
477 //*************************************************************************
478 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
479 {
480 return m;
481 }
482
483 //*************************************************************************
485 //*************************************************************************
486 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::day day() const ETL_NOEXCEPT
487 {
488 etl::chrono::day d = etl::chrono::day(etl::chrono::private_chrono::days_in_month[static_cast<unsigned>(m)]);
489
490 return (d == etl::chrono::day(28)) && y.is_leap() ? etl::chrono::day(29) : d;
491 }
492
493 //*************************************************************************
495 //*************************************************************************
496 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month_day_last month_day_last() const ETL_NOEXCEPT
497 {
499 }
500
501 //*************************************************************************
503 //*************************************************************************
504 ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
505 {
506 return y.ok() && m.ok();
507 }
508
509 //*************************************************************************
511 //*************************************************************************
512 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator+=(const etl::chrono::years& dy) ETL_NOEXCEPT
513 {
514 y += dy;
515
516 return *this;
517 }
518
519 //*************************************************************************
521 //*************************************************************************
522 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator+=(const etl::chrono::months& dm) ETL_NOEXCEPT
523 {
524 m += dm;
525
526 return *this;
527 }
528
529 //*************************************************************************
531 //*************************************************************************
532 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator-=(const etl::chrono::years& dy) ETL_NOEXCEPT
533 {
534 y -= dy;
535
536 return *this;
537 }
538
539 //*************************************************************************
541 //*************************************************************************
542 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator-=(const etl::chrono::months& dm) ETL_NOEXCEPT
543 {
544 m -= dm;
545
546 return *this;
547 }
548
549 //***********************************************************************
556 //***********************************************************************
557 ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day_last& other) const ETL_NOEXCEPT
558 {
559 if (y < other.y)
560 return -1;
561 if (y > other.y)
562 return 1;
563 if (m < other.m)
564 return -1;
565 if (m > other.m)
566 return 1;
567
568 return 0;
569 }
570
571 //*************************************************************************
573 //*************************************************************************
574 ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
575 {
576 etl::chrono::year_month_day ymd(year(), month(), day());
577
578 return etl::chrono::sys_days(ymd);
579 }
580
581 //*************************************************************************
583 //*************************************************************************
584 ETL_NODISCARD ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT
585 {
586 return local_days(sys_days(*this).time_since_epoch());
587 }
588
589 private:
590
593 };
594
595 //*************************************************************************
597 //*************************************************************************
598 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator+(const etl::chrono::year_month_day_last& ymdl, const etl::chrono::years& dy)
599 ETL_NOEXCEPT
600 {
601 return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last());
602 }
603
604 //*************************************************************************
606 //*************************************************************************
607 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator+(const etl::chrono::years& dy, const etl::chrono::year_month_day_last& ymdl)
608 ETL_NOEXCEPT
609 {
610 return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last());
611 }
612
613 //*************************************************************************
615 //*************************************************************************
616 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator+(const etl::chrono::year_month_day_last& ymdl, const etl::chrono::months& dm)
617 ETL_NOEXCEPT
618 {
619 return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm));
620 }
621
622 //*************************************************************************
624 //*************************************************************************
625 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator+(const etl::chrono::months& dm, const etl::chrono::year_month_day_last& ymdl)
626 ETL_NOEXCEPT
627 {
628 return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm));
629 }
630
631 //*************************************************************************
633 //*************************************************************************
634 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator-(const etl::chrono::year_month_day_last& ymdl, const etl::chrono::years& dy)
635 ETL_NOEXCEPT
636 {
637 return etl::chrono::year_month_day_last(ymdl.year() - dy, ymdl.month_day_last());
638 }
639
640 //*************************************************************************
642 //*************************************************************************
643 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator-(const etl::chrono::year_month_day_last& ymdl, const etl::chrono::months& dm)
644 ETL_NOEXCEPT
645 {
646 return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() - dm));
647 }
648
649 //*************************************************************************
651 //*************************************************************************
653 : y(ymdl.year())
654 , m(ymdl.month())
655 , d(ymdl.day())
656 {
657 }
658
659 //*************************************************************************
661 //*************************************************************************
662 inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
663 {
664 return (lhs.year() == rhs.year()) && (lhs.month() == rhs.month());
665 }
666
667 //*************************************************************************
669 //*************************************************************************
670 inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
671 {
672 return !(lhs == rhs);
673 }
674
675 //*************************************************************************
677 //*************************************************************************
678 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator<(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs)
679 ETL_NOEXCEPT
680 {
681 if (lhs.year() < rhs.year())
682 {
683 return true;
684 }
685 else if (lhs.year() == rhs.year())
686 {
687 return (lhs.month() < rhs.month());
688 }
689 else
690 {
691 return false;
692 }
693 }
694
695 //*************************************************************************
697 //*************************************************************************
698 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator<=(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs)
699 ETL_NOEXCEPT
700 {
701 return !(rhs < lhs);
702 }
703
704 //*************************************************************************
706 //*************************************************************************
707 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator>(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs)
708 ETL_NOEXCEPT
709 {
710 return rhs < lhs;
711 }
712
713 //*************************************************************************
715 //*************************************************************************
716 ETL_NODISCARD ETL_CONSTEXPR14 inline bool operator>=(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs)
717 ETL_NOEXCEPT
718 {
719 return !(lhs < rhs);
720 }
721
722 //***********************************************************************
724 //***********************************************************************
725#if ETL_USING_CPP20
726 [[nodiscard]]
727 inline constexpr auto operator<=>(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
728 {
729 auto cmp1 = lhs.year() <=> rhs.year();
730
731 if (cmp1 != 0)
732 {
733 return cmp1;
734 }
735 else
736 {
737 auto cmp2 = lhs.month() <=> rhs.month();
738
739 if (cmp2 != 0)
740 {
741 return cmp2;
742 }
743 else
744 {
745 return lhs.month() <=> rhs.month();
746 }
747 }
748 }
749#endif
750 } // namespace chrono
751
752 //*************************************************************************
754 //*************************************************************************
755#if ETL_USING_8BIT_TYPES
756 template <>
757 struct hash<etl::chrono::year_month_day>
758 {
759 size_t operator()(const etl::chrono::year_month_day& ymd) const
760 {
761 etl::chrono::year::rep y = static_cast<etl::chrono::year::rep>(static_cast<int>(ymd.year()));
762 etl::chrono::month::rep m = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(ymd.month()));
763 etl::chrono::day::rep d = static_cast<etl::chrono::day::rep>(static_cast<unsigned>(ymd.day()));
764
765 uint8_t buffer[sizeof(y) + sizeof(m) + sizeof(d)];
766
767 memcpy(buffer, &y, sizeof(y));
768 memcpy(buffer + sizeof(y), &m, sizeof(m));
769 memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d));
770
771 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(y) + sizeof(m) + sizeof(d));
772 }
773 };
774#endif
775
776 //*************************************************************************
778 //*************************************************************************
779#if ETL_USING_8BIT_TYPES
780 template <>
781 struct hash<etl::chrono::year_month_day_last>
782 {
783 size_t operator()(const etl::chrono::year_month_day_last& ymdl) const
784 {
785 etl::chrono::year::rep y = static_cast<etl::chrono::year::rep>(static_cast<int>(ymdl.year()));
786 etl::chrono::month::rep m = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(ymdl.month()));
787 etl::chrono::day::rep d = static_cast<etl::chrono::day::rep>(static_cast<unsigned>(ymdl.day()));
788
789 uint8_t buffer[sizeof(y) + sizeof(m) + sizeof(d)];
790
791 memcpy(buffer, &y, sizeof(y));
792 memcpy(buffer + sizeof(y), &m, sizeof(m));
793 memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d));
794
795 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(y) + sizeof(m) + sizeof(d));
796 }
797 };
798#endif
799} // namespace etl
day
Definition day.h:43
Spaceship operator.
Definition month_day.h:202
ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Get the month.
Definition month_day.h:216
month
Definition month.h:54
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the month is within the valid 1 to 12 range.
Definition month.h:142
Spaceship operator.
Definition year_month_day.h:455
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::local_days() const ETL_NOEXCEPT
Converts to etl::chrono::local_days.
Definition year_month_day.h:584
ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day_last &other) const ETL_NOEXCEPT
Definition year_month_day.h:557
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
Converts to etl::chrono::sys_days.
Definition year_month_day.h:574
year_month_day
Definition year_month_day.h:45
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::local_days() const ETL_NOEXCEPT
Converts to etl::chrono::local_days.
Definition year_month_day.h:275
ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day &other) const ETL_NOEXCEPT
Definition year_month_day.h:224
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
Converts to etl::chrono::sys_days.
Definition year_month_day.h:245
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition year_month_day.h:152
ETL_CONSTEXPR year_month_day()
Default constructor.
Definition year_month_day.h:51
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::day day() const ETL_NOEXCEPT
Returns the day.
Definition year_month_day.h:160
ETL_CONSTEXPR14 year_month_day(const etl::chrono::year &y_, const etl::chrono::month &m_, const etl::chrono::day &d_) ETL_NOEXCEPT
Construct from month and day.
Definition year_month_day.h:61
ETL_CONSTEXPR14 year_month_day(const etl::chrono::sys_days &sd) ETL_NOEXCEPT
Construct from sys_days.
Definition year_month_day.h:76
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the year/month/day is valid.
Definition year_month_day.h:168
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::year year() const ETL_NOEXCEPT
Returns the year.
Definition year_month_day.h:144
ETL_CONSTEXPR14 year_month_day(const etl::chrono::local_days &ld) ETL_NOEXCEPT
Construct from local_days.
Definition year_month_day.h:129
year
Definition year.h:43
ETL_NODISCARD ETL_CONSTEXPR14 bool is_leap() const ETL_NOEXCEPT
Returns true if the year is a leap year.
Definition year.h:156
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Definition year.h:130
ETL_CONSTEXPR14 etl::chrono::day operator+(const etl::chrono::day &d, const etl::chrono::days &ds) ETL_NOEXCEPT
Spaceship operator.
Definition day.h:226
ETL_CONSTEXPR14 etl::chrono::day operator-(const etl::chrono::day &d, const etl::chrono::days &ds) ETL_NOEXCEPT
Definition day.h:252
ETL_CONSTEXPR14 bool operator<(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Less-than operator.
Definition day.h:182
ETL_CONSTEXPR14 bool operator>=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Greater-than-or-equal operator.
Definition day.h:206
ETL_CONSTEXPR14 bool operator==(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Equality operator.
Definition day.h:166
ETL_CONSTEXPR14 bool operator<=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Less-than-or-equal operator.
Definition day.h:190
ETL_CONSTEXPR14 bool operator!=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Inequality operator.
Definition day.h:174
ETL_CONSTEXPR14 bool operator>(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Greater-than operator.
Definition day.h:198
bitset_ext
Definition absolute.h:40