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_,
62 const etl::chrono::month& m_,
63 const etl::chrono::day& d_) ETL_NOEXCEPT
64 : y(y_)
65 , m(m_)
66 , d(d_)
67 {
68 }
69
70 //*************************************************************************
72 //*************************************************************************
73 ETL_CONSTEXPR14 year_month_day(const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT;
74
75 //*************************************************************************
77 //*************************************************************************
78 ETL_CONSTEXPR14 year_month_day(const etl::chrono::sys_days& sd) ETL_NOEXCEPT
79 {
80 // Days since 1970-01-01
81 int days_since_epoch = static_cast<int>(sd.time_since_epoch().count());
82
83 // Start from 1970-01-01
84 etl::chrono::year current_year(1970);
85 etl::chrono::month current_month(1);
86
87 // Find the year
88 while (true)
89 {
90 int days_in_year = current_year.is_leap() ? 366 : 365;
91
92 if (days_since_epoch < days_in_year)
93 {
94 break;
95 }
96
97 days_since_epoch -= days_in_year;
98 ++current_year;
99 }
100
101 // Find the month
102 while (true)
103 {
104 unsigned char days_in_month = etl::chrono::private_chrono::days_in_month[current_month];
105 if (current_month == etl::chrono::February && current_year.is_leap())
106 {
107 ++days_in_month;
108 }
109
110 if (days_since_epoch < days_in_month)
111 {
112 break;
113 }
114
115 days_since_epoch -= days_in_month;
116 ++current_month;
117 }
118
119 // The remaining days are the day of the month (0-based)
120 y = current_year;
121 m = current_month;
122 d = etl::chrono::day(static_cast<unsigned>(days_since_epoch) + 1);
123 }
124
125 //*************************************************************************
127 //*************************************************************************
128 ETL_CONSTEXPR14 year_month_day(const etl::chrono::local_days& ld) ETL_NOEXCEPT
129 {
130 etl::chrono::year_month_day ymd = sys_days(ld.time_since_epoch());
131
132 y = ymd.year();
133 m = ymd.month();
134 d = ymd.day();
135 }
136
137 //*************************************************************************
139 //*************************************************************************
140 ETL_NODISCARD
141 ETL_CONSTEXPR14 etl::chrono::year year() const ETL_NOEXCEPT
142 {
143 return y;
144 }
145
146 //*************************************************************************
148 //*************************************************************************
149 ETL_NODISCARD
150 ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
151 {
152 return m;
153 }
154
155 //*************************************************************************
157 //*************************************************************************
158 ETL_NODISCARD
159 ETL_CONSTEXPR14 etl::chrono::day day() const ETL_NOEXCEPT
160 {
161 return d;
162 }
163
164 //*************************************************************************
166 //*************************************************************************
167 ETL_NODISCARD
168 ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
169 {
170 // Check if the year, month, and day are valid individually
171 return y.ok() &&
172 m.ok() &&
173 d.ok() &&
174 d <= max_day_for_month();
175 }
176
177 //*************************************************************************
179 //*************************************************************************
180 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator +=(const etl::chrono::years& dy) ETL_NOEXCEPT
181 {
182 y += dy;
183
184 return *this;
185 }
186
187 //*************************************************************************
189 //*************************************************************************
190 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator +=(const etl::chrono::months& dm) ETL_NOEXCEPT
191 {
192 m += dm;
193
194 return *this;
195 }
196
197 //*************************************************************************
199 //*************************************************************************
200 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator -=(const etl::chrono::years& dy) ETL_NOEXCEPT
201 {
202 y -= dy;
203
204 return *this;
205 }
206
207 //*************************************************************************
209 //*************************************************************************
210 ETL_CONSTEXPR14 etl::chrono::year_month_day& operator -=(const etl::chrono::months& dm) ETL_NOEXCEPT
211 {
212 m -= dm;
213
214 return *this;
215 }
216
217 //***********************************************************************
226 //***********************************************************************
227 ETL_NODISCARD
228 ETL_CONSTEXPR14 int compare(const year_month_day& other) const ETL_NOEXCEPT
229 {
230 if (y < other.y) return -1;
231 if (y > other.y) return 1;
232 if (m < other.m) return -1;
233 if (m > other.m) return 1;
234 if (d < other.d) return -1;
235 if (d > other.d) return 1;
236
237 return 0;
238 }
239
240 //***********************************************************************
242 //***********************************************************************
243 ETL_NODISCARD
244 ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
245 {
246 int day_count = 0;
247
248 // Add days for years since 1970
249 for (etl::chrono::year yr(1970); yr < this->year(); ++yr)
250 {
251 day_count += yr.is_leap() ? 366 : 365;
252 }
253
254 // Add days for months in the current year
255 for (etl::chrono::month mth(1); mth < this->month(); ++mth)
256 {
257 day_count += private_chrono::days_in_month[mth];
258
259 if (mth == etl::chrono::February && this->year().is_leap())
260 {
261 ++day_count; // Add one day for leap year February
262 }
263 }
264
265 // Add days for the current month
266 day_count += static_cast<unsigned>(this->day()) - 1;
267
268 return sys_days(etl::chrono::days(day_count));
269 }
270
271 //***********************************************************************
273 //***********************************************************************
274 ETL_NODISCARD
275 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[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,
312 const etl::chrono::years& dy) ETL_NOEXCEPT
313 {
314 return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day());
315 }
316
317 //*************************************************************************
319 //*************************************************************************
320 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::years& dy,
321 const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT
322 {
323 return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day());
324 }
325
326 //*************************************************************************
328 //*************************************************************************
329 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd,
330 const etl::chrono::months& dm) ETL_NOEXCEPT
331 {
332 return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day());
333 }
334
335 //*************************************************************************
337 //*************************************************************************
338 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::months& dm,
339 const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT
340 {
341 return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day());
342 }
343
344 //*************************************************************************
346 //*************************************************************************
347 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd,
348 const etl::chrono::years& dy) ETL_NOEXCEPT
349 {
350 return etl::chrono::year_month_day(ymd.year() - dy, ymd.month(), ymd.day());
351 }
352
353 //*************************************************************************
355 //*************************************************************************
356 inline ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd,
357 const etl::chrono::months& dm) ETL_NOEXCEPT
358 {
359 return etl::chrono::year_month_day(ymd.year(), ymd.month() - dm, ymd.day());
360 }
361
362 //*************************************************************************
364 //*************************************************************************
365 inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_day& lhs,
366 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
367 {
368 return (lhs.year() == rhs.year()) &&
369 (lhs.month() == rhs.month()) &&
370 (lhs.day() == rhs.day());
371 }
372
373 //*************************************************************************
375 //*************************************************************************
376 inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_day& lhs,
377 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
378 {
379 return !(lhs == rhs);
380 }
381
382 //*************************************************************************
384 //*************************************************************************
385 ETL_NODISCARD ETL_CONSTEXPR14
386 inline bool operator <(const etl::chrono::year_month_day& lhs,
387 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
388 {
389 if (lhs.year() < rhs.year())
390 {
391 return true;
392 }
393 else if (lhs.year() == rhs.year())
394 {
395 if (lhs.month() < rhs.month())
396 {
397 return true;
398 }
399 else if (lhs.month() == rhs.month())
400 {
401 return (lhs.day() < rhs.day());
402 }
403 else
404 {
405 return false;
406 }
407 }
408 else
409 {
410 return false;
411 }
412 }
413
414 //*************************************************************************
416 //*************************************************************************
417 ETL_NODISCARD ETL_CONSTEXPR14
418 inline bool operator <=(const etl::chrono::year_month_day& lhs,
419 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
420 {
421 return !(rhs < lhs);
422 }
423
424 //*************************************************************************
426 //*************************************************************************
427 ETL_NODISCARD ETL_CONSTEXPR14
428 inline bool operator >(const etl::chrono::year_month_day& lhs,
429 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
430 {
431 return rhs < lhs;
432 }
433
434 //*************************************************************************
436 //*************************************************************************
437 ETL_NODISCARD ETL_CONSTEXPR14
438 inline bool operator >=(const etl::chrono::year_month_day& lhs,
439 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
440 {
441 return !(lhs < rhs);
442 }
443
444 //***********************************************************************
446 //***********************************************************************
447#if ETL_USING_CPP20
448 [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::year_month_day& lhs,
449 const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT
450 {
451 auto cmp = lhs.year() <=> rhs.year();
452
453 if (cmp != 0)
454 {
455 return cmp;
456 }
457
458 cmp = lhs.month() <=> rhs.month();
459
460 if (cmp != 0)
461 {
462 return cmp;
463 }
464
465 return lhs.day() <=> rhs.day();
466 }
467#endif
468
469 //*************************************************************************
471 //*************************************************************************
472 class year_month_day_last
473 {
474 public:
475
476 //*************************************************************************
478 //*************************************************************************
479 ETL_CONSTEXPR14 year_month_day_last(const etl::chrono::year& y_,
480 const etl::chrono::month_day_last& mdl_) ETL_NOEXCEPT
481 : y(y_)
482 , m(mdl_.month())
483 {
484 }
485
486 //*************************************************************************
488 //*************************************************************************
489 ETL_NODISCARD
490 ETL_CONSTEXPR14 etl::chrono::year year() const ETL_NOEXCEPT
491 {
492 return y;
493 }
494
495 //*************************************************************************
497 //*************************************************************************
498 ETL_NODISCARD
499 ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
500 {
501 return m;
502 }
503
504 //*************************************************************************
506 //*************************************************************************
507 ETL_NODISCARD
508 ETL_CONSTEXPR14 etl::chrono::day day() const ETL_NOEXCEPT
509 {
510 etl::chrono::day d = etl::chrono::day(etl::chrono::private_chrono::days_in_month[m]);
511
512 return (d == 28) && y.is_leap() ? etl::chrono::day(29) : d;
513 }
514
515 //*************************************************************************
517 //*************************************************************************
518 ETL_NODISCARD
519 ETL_CONSTEXPR14 etl::chrono::month_day_last month_day_last() const ETL_NOEXCEPT
520 {
522 }
523
524 //*************************************************************************
526 //*************************************************************************
527 ETL_NODISCARD
528 ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
529 {
530 return y.ok() && m.ok();
531 }
532
533 //*************************************************************************
535 //*************************************************************************
536 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator +=(const etl::chrono::years& dy) ETL_NOEXCEPT
537 {
538 y += dy;
539
540 return *this;
541 }
542
543 //*************************************************************************
545 //*************************************************************************
546 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator +=(const etl::chrono::months& dm) ETL_NOEXCEPT
547 {
548 m += dm;
549
550 return *this;
551 }
552
553 //*************************************************************************
555 //*************************************************************************
556 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator -=(const etl::chrono::years& dy) ETL_NOEXCEPT
557 {
558 y -= dy;
559
560 return *this;
561 }
562
563 //*************************************************************************
565 //*************************************************************************
566 ETL_CONSTEXPR14 etl::chrono::year_month_day_last& operator -=(const etl::chrono::months& dm) ETL_NOEXCEPT
567 {
568 m -= dm;
569
570 return *this;
571 }
572
573 //***********************************************************************
580 //***********************************************************************
581 ETL_NODISCARD
582 ETL_CONSTEXPR14 int compare(const year_month_day_last& other) const ETL_NOEXCEPT
583 {
584 if (y < other.y) return -1;
585 if (y > other.y) return 1;
586 if (m < other.m) return -1;
587 if (m > other.m) return 1;
588
589 return 0;
590 }
591
592 //*************************************************************************
594 //*************************************************************************
595 ETL_NODISCARD
596 ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
597 {
598 etl::chrono::year_month_day ymd(year(), month(), day());
599
600 return etl::chrono::sys_days(ymd);
601 }
602
603 //*************************************************************************
605 //*************************************************************************
606 ETL_NODISCARD
607 ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT
608 {
609 return local_days(sys_days(*this).time_since_epoch());
610 }
611
612 private:
613
616 };
617
618 //*************************************************************************
620 //*************************************************************************
621 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl,
622 const etl::chrono::years& dy) ETL_NOEXCEPT
623 {
624 return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last());
625 }
626
627 //*************************************************************************
629 //*************************************************************************
630 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::years& dy,
631 const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT
632 {
633 return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last());
634 }
635
636 //*************************************************************************
638 //*************************************************************************
639 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl,
640 const etl::chrono::months& dm) ETL_NOEXCEPT
641 {
642 return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm));
643 }
644
645 //*************************************************************************
647 //*************************************************************************
648 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::months& dm,
649 const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT
650 {
651 return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm));
652 }
653
654 //*************************************************************************
656 //*************************************************************************
657 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl,
658 const etl::chrono::years& dy) ETL_NOEXCEPT
659 {
660 return etl::chrono::year_month_day_last(ymdl.year() - dy, ymdl.month_day_last());
661 }
662
663 //*************************************************************************
665 //*************************************************************************
666 inline ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl,
667 const etl::chrono::months& dm) ETL_NOEXCEPT
668 {
669 return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() - dm));
670 }
671
672 //*************************************************************************
674 //*************************************************************************
676 : y(ymdl.year())
677 , m(ymdl.month())
678 , d(ymdl.day())
679 {
680 }
681
682 //*************************************************************************
684 //*************************************************************************
685 inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::year_month_day_last& lhs,
686 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
687 {
688 return (lhs.year() == rhs.year()) &&
689 (lhs.month() == rhs.month());
690 }
691
692 //*************************************************************************
694 //*************************************************************************
695 inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::year_month_day_last& lhs,
696 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
697 {
698 return !(lhs == rhs);
699 }
700
701 //*************************************************************************
703 //*************************************************************************
704 ETL_NODISCARD ETL_CONSTEXPR14
705 inline bool operator <(const etl::chrono::year_month_day_last& lhs,
706 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
707 {
708 if (lhs.year() < rhs.year())
709 {
710 return true;
711 }
712 else if (lhs.year() == rhs.year())
713 {
714 return (lhs.month() < rhs.month());
715 }
716 else
717 {
718 return false;
719 }
720 }
721
722 //*************************************************************************
724 //*************************************************************************
725 ETL_NODISCARD ETL_CONSTEXPR14
726 inline bool operator <=(const etl::chrono::year_month_day_last& lhs,
727 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
728 {
729 return !(rhs < lhs);
730 }
731
732 //*************************************************************************
734 //*************************************************************************
735 ETL_NODISCARD ETL_CONSTEXPR14
736 inline bool operator >(const etl::chrono::year_month_day_last& lhs,
737 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
738 {
739 return rhs < lhs;
740 }
741
742 //*************************************************************************
744 //*************************************************************************
745 ETL_NODISCARD ETL_CONSTEXPR14
746 inline bool operator >=(const etl::chrono::year_month_day_last& lhs,
747 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
748 {
749 return !(lhs < rhs);
750 }
751
752 //***********************************************************************
754 //***********************************************************************
755#if ETL_USING_CPP20
756 [[nodiscard]] inline constexpr auto operator <=>(const etl::chrono::year_month_day_last& lhs,
757 const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT
758 {
759 auto cmp1 = lhs.year() <=> rhs.year();
760
761 if (cmp1 != 0)
762 {
763 return cmp1;
764 }
765 else
766 {
767 auto cmp2 = lhs.month() <=> rhs.month();
768
769 if (cmp2 != 0)
770 {
771 return cmp2;
772 }
773 else
774 {
775 return lhs.month() <=> rhs.month();
776 }
777 }
778 }
779#endif
780 }
781
782 //*************************************************************************
784 //*************************************************************************
785#if ETL_USING_8BIT_TYPES
786 template <>
787 struct hash<etl::chrono::year_month_day>
788 {
789 size_t operator()(const etl::chrono::year_month_day& ymd) const
790 {
791 etl::chrono::year::rep y = static_cast<etl::chrono::year::rep>(static_cast<unsigned>(ymd.year()));
792 etl::chrono::month::rep m = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(ymd.month()));
793 etl::chrono::day::rep d = static_cast<etl::chrono::day::rep>(static_cast<unsigned>(ymd.day()));
794
795 uint8_t buffer[sizeof(y) + sizeof(m) + sizeof(d)];
796
797 memcpy(buffer, &y, sizeof(y));
798 memcpy(buffer + sizeof(y), &m, sizeof(m));
799 memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d));
800
801 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(y) + sizeof(m) + sizeof(d));
802 }
803 };
804#endif
805
806 //*************************************************************************
808 //*************************************************************************
809#if ETL_USING_8BIT_TYPES
810 template <>
811 struct hash<etl::chrono::year_month_day_last>
812 {
813 size_t operator()(const etl::chrono::year_month_day_last& ymdl) const
814 {
815 etl::chrono::year::rep y = static_cast<etl::chrono::year::rep>(static_cast<unsigned>(ymdl.year()));
816 etl::chrono::month::rep m = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(ymdl.month()));
817 etl::chrono::day::rep d = static_cast<etl::chrono::day::rep>(static_cast<unsigned>(ymdl.day()));
818
819 uint8_t buffer[sizeof(y) + sizeof(m) + sizeof(d)];
820
821 memcpy(buffer, &y, sizeof(y));
822 memcpy(buffer + sizeof(y), &m, sizeof(m));
823 memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d));
824
825 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(y) + sizeof(m) + sizeof(d));
826 }
827 };
828#endif
829}
830
day
Definition day.h:43
Spaceship operator.
Definition month_day.h:215
ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Get the month.
Definition month_day.h:229
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 31 range.
Definition month.h:161
Spaceship operator.
Definition year_month_day.h:473
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::local_days() const ETL_NOEXCEPT
Converts to etl::chrono::local_days.
Definition year_month_day.h:607
ETL_NODISCARD ETL_CONSTEXPR14 int compare(const year_month_day_last &other) const ETL_NOEXCEPT
Definition year_month_day.h:582
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
Converts to etl::chrono::sys_days.
Definition year_month_day.h:596
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:228
ETL_NODISCARD ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT
Converts to etl::chrono::sys_days.
Definition year_month_day.h:244
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition year_month_day.h:150
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:159
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:78
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:141
ETL_CONSTEXPR14 year_month_day(const etl::chrono::local_days &ld) ETL_NOEXCEPT
Construct from local_days.
Definition year_month_day.h:128
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:175
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the year is within the valid -32767 to 32767 range.
Definition year.h:148
bitset_ext
Definition absolute.h:39