Dynalib Utils
julian.h
Go to the documentation of this file.
1 #ifndef JULIAN_H
2 #define JULIAN_H
3 
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2016 Howard Hinnant
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 //
26 // Our apologies. When the previous paragraph was written, lowercase had not yet
27 // been invented (that would involve another several millennia of evolution).
28 // We did not mean to shout.
29 
30 #include "date.h"
31 
32 namespace julian
33 {
34 
35 // durations
36 
37 using days = date::days;
38 
40 
41 using years = std::chrono::duration
42  <int, std::ratio_multiply<std::ratio<1461, 4>, days::period>>;
43 
44 using months = std::chrono::duration
45  <int, std::ratio_divide<years::period, std::ratio<12>>>;
46 
47 // time_point
48 
51 
52 // types
53 
54 struct last_spec
55 {
56  explicit last_spec() = default;
57 };
58 
59 class day;
60 class month;
61 class year;
62 
63 class weekday;
64 class weekday_indexed;
65 class weekday_last;
66 
67 class month_day;
68 class month_day_last;
69 class month_weekday;
70 class month_weekday_last;
71 
72 class year_month;
73 
74 class year_month_day;
76 class year_month_weekday;
78 
79 // date composition operators
80 
81 CONSTCD11 year_month operator/(const year& y, const month& m) NOEXCEPT;
82 CONSTCD11 year_month operator/(const year& y, int m) NOEXCEPT;
83 
84 CONSTCD11 month_day operator/(const day& d, const month& m) NOEXCEPT;
85 CONSTCD11 month_day operator/(const day& d, int m) NOEXCEPT;
86 CONSTCD11 month_day operator/(const month& m, const day& d) NOEXCEPT;
87 CONSTCD11 month_day operator/(const month& m, int d) NOEXCEPT;
88 CONSTCD11 month_day operator/(int m, const day& d) NOEXCEPT;
89 
94 
99 
104 
111 
112 CONSTCD11
114 CONSTCD11
116 CONSTCD11
118 CONSTCD11
120 CONSTCD11
122 
123 CONSTCD11
125 operator/(const year_month& ym, const weekday_indexed& wdi) NOEXCEPT;
126 
127 CONSTCD11
129 operator/(const year& y, const month_weekday& mwd) NOEXCEPT;
130 
131 CONSTCD11
133 operator/(int y, const month_weekday& mwd) NOEXCEPT;
134 
135 CONSTCD11
137 operator/(const month_weekday& mwd, const year& y) NOEXCEPT;
138 
139 CONSTCD11
141 operator/(const month_weekday& mwd, int y) NOEXCEPT;
142 
143 CONSTCD11
145 operator/(const year_month& ym, const weekday_last& wdl) NOEXCEPT;
146 
147 CONSTCD11
149 operator/(const year& y, const month_weekday_last& mwdl) NOEXCEPT;
150 
151 CONSTCD11
153 operator/(int y, const month_weekday_last& mwdl) NOEXCEPT;
154 
155 CONSTCD11
157 operator/(const month_weekday_last& mwdl, const year& y) NOEXCEPT;
158 
159 CONSTCD11
161 operator/(const month_weekday_last& mwdl, int y) NOEXCEPT;
162 
163 // Detailed interface
164 
165 // day
166 
167 class day
168 {
169  unsigned char d_;
170 
171 public:
172  explicit CONSTCD11 day(unsigned d) NOEXCEPT;
173 
174  CONSTCD14 day& operator++() NOEXCEPT;
175  CONSTCD14 day operator++(int) NOEXCEPT;
176  CONSTCD14 day& operator--() NOEXCEPT;
177  CONSTCD14 day operator--(int) NOEXCEPT;
178 
179  CONSTCD14 day& operator+=(const days& d) NOEXCEPT;
180  CONSTCD14 day& operator-=(const days& d) NOEXCEPT;
181 
182  CONSTCD11 explicit operator unsigned() const NOEXCEPT;
183  CONSTCD11 bool ok() const NOEXCEPT;
184 };
185 
186 CONSTCD11 bool operator==(const day& x, const day& y) NOEXCEPT;
187 CONSTCD11 bool operator!=(const day& x, const day& y) NOEXCEPT;
188 CONSTCD11 bool operator< (const day& x, const day& y) NOEXCEPT;
189 CONSTCD11 bool operator> (const day& x, const day& y) NOEXCEPT;
190 CONSTCD11 bool operator<=(const day& x, const day& y) NOEXCEPT;
191 CONSTCD11 bool operator>=(const day& x, const day& y) NOEXCEPT;
192 
193 CONSTCD11 day operator+(const day& x, const days& y) NOEXCEPT;
194 CONSTCD11 day operator+(const days& x, const day& y) NOEXCEPT;
195 CONSTCD11 day operator-(const day& x, const days& y) NOEXCEPT;
196 CONSTCD11 days operator-(const day& x, const day& y) NOEXCEPT;
197 
198 template<class CharT, class Traits>
199 std::basic_ostream<CharT, Traits>&
200 operator<<(std::basic_ostream<CharT, Traits>& os, const day& d);
201 
202 // month
203 
204 class month
205 {
206  unsigned char m_;
207 
208 public:
209  explicit CONSTCD11 month(unsigned m) NOEXCEPT;
210 
211  CONSTCD14 month& operator++() NOEXCEPT;
212  CONSTCD14 month operator++(int) NOEXCEPT;
213  CONSTCD14 month& operator--() NOEXCEPT;
214  CONSTCD14 month operator--(int) NOEXCEPT;
215 
217  CONSTCD14 month& operator-=(const months& m) NOEXCEPT;
218 
219  CONSTCD11 explicit operator unsigned() const NOEXCEPT;
220  CONSTCD11 bool ok() const NOEXCEPT;
221 };
222 
223 CONSTCD11 bool operator==(const month& x, const month& y) NOEXCEPT;
224 CONSTCD11 bool operator!=(const month& x, const month& y) NOEXCEPT;
225 CONSTCD11 bool operator< (const month& x, const month& y) NOEXCEPT;
226 CONSTCD11 bool operator> (const month& x, const month& y) NOEXCEPT;
227 CONSTCD11 bool operator<=(const month& x, const month& y) NOEXCEPT;
228 CONSTCD11 bool operator>=(const month& x, const month& y) NOEXCEPT;
229 
230 CONSTCD14 month operator+(const month& x, const months& y) NOEXCEPT;
231 CONSTCD14 month operator+(const months& x, const month& y) NOEXCEPT;
232 CONSTCD14 month operator-(const month& x, const months& y) NOEXCEPT;
233 CONSTCD14 months operator-(const month& x, const month& y) NOEXCEPT;
234 
235 template<class CharT, class Traits>
236 std::basic_ostream<CharT, Traits>&
237 operator<<(std::basic_ostream<CharT, Traits>& os, const month& m);
238 
239 // year
240 
241 class year
242 {
243  short y_;
244 
245 public:
246  explicit CONSTCD11 year(int y) NOEXCEPT;
247 
248  CONSTCD14 year& operator++() NOEXCEPT;
249  CONSTCD14 year operator++(int) NOEXCEPT;
250  CONSTCD14 year& operator--() NOEXCEPT;
251  CONSTCD14 year operator--(int) NOEXCEPT;
252 
254  CONSTCD14 year& operator-=(const years& y) NOEXCEPT;
255 
256  CONSTCD11 bool is_leap() const NOEXCEPT;
257 
258  CONSTCD11 explicit operator int() const NOEXCEPT;
259  CONSTCD11 bool ok() const NOEXCEPT;
260 
261  static CONSTCD11 year min() NOEXCEPT;
262  static CONSTCD11 year max() NOEXCEPT;
263 };
264 
265 CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
266 CONSTCD11 bool operator!=(const year& x, const year& y) NOEXCEPT;
267 CONSTCD11 bool operator< (const year& x, const year& y) NOEXCEPT;
268 CONSTCD11 bool operator> (const year& x, const year& y) NOEXCEPT;
269 CONSTCD11 bool operator<=(const year& x, const year& y) NOEXCEPT;
270 CONSTCD11 bool operator>=(const year& x, const year& y) NOEXCEPT;
271 
272 CONSTCD11 year operator+(const year& x, const years& y) NOEXCEPT;
273 CONSTCD11 year operator+(const years& x, const year& y) NOEXCEPT;
274 CONSTCD11 year operator-(const year& x, const years& y) NOEXCEPT;
275 CONSTCD11 years operator-(const year& x, const year& y) NOEXCEPT;
276 
277 template<class CharT, class Traits>
278 std::basic_ostream<CharT, Traits>&
279 operator<<(std::basic_ostream<CharT, Traits>& os, const year& y);
280 
281 // weekday
282 
283 class weekday
284 {
285  unsigned char wd_;
286 public:
287  explicit CONSTCD11 weekday(unsigned wd) NOEXCEPT;
288  explicit weekday(int) = delete;
289  CONSTCD11 weekday(const sys_days& dp) NOEXCEPT;
290  CONSTCD11 explicit weekday(const local_days& dp) NOEXCEPT;
291 
292  CONSTCD14 weekday& operator++() NOEXCEPT;
293  CONSTCD14 weekday operator++(int) NOEXCEPT;
294  CONSTCD14 weekday& operator--() NOEXCEPT;
295  CONSTCD14 weekday operator--(int) NOEXCEPT;
296 
298  CONSTCD14 weekday& operator-=(const days& d) NOEXCEPT;
299 
300  CONSTCD11 explicit operator unsigned() const NOEXCEPT;
301  CONSTCD11 bool ok() const NOEXCEPT;
302 
303  CONSTCD11 weekday_indexed operator[](unsigned index) const NOEXCEPT;
304  CONSTCD11 weekday_last operator[](last_spec) const NOEXCEPT;
305 
306 private:
307  static CONSTCD11 unsigned char weekday_from_days(int z) NOEXCEPT;
308 };
309 
310 CONSTCD11 bool operator==(const weekday& x, const weekday& y) NOEXCEPT;
311 CONSTCD11 bool operator!=(const weekday& x, const weekday& y) NOEXCEPT;
312 
313 CONSTCD14 weekday operator+(const weekday& x, const days& y) NOEXCEPT;
314 CONSTCD14 weekday operator+(const days& x, const weekday& y) NOEXCEPT;
315 CONSTCD14 weekday operator-(const weekday& x, const days& y) NOEXCEPT;
316 CONSTCD14 days operator-(const weekday& x, const weekday& y) NOEXCEPT;
317 
318 template<class CharT, class Traits>
319 std::basic_ostream<CharT, Traits>&
320 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday& wd);
321 
322 // weekday_indexed
323 
325 {
326  unsigned char wd_ : 4;
327  unsigned char index_ : 4;
328 
329 public:
330  CONSTCD11 weekday_indexed(const julian::weekday& wd, unsigned index) NOEXCEPT;
331 
333  CONSTCD11 unsigned index() const NOEXCEPT;
334  CONSTCD11 bool ok() const NOEXCEPT;
335 };
336 
339 
340 template<class CharT, class Traits>
341 std::basic_ostream<CharT, Traits>&
342 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_indexed& wdi);
343 
344 // weekday_last
345 
347 {
348  julian::weekday wd_;
349 
350 public:
351  explicit CONSTCD11 weekday_last(const julian::weekday& wd) NOEXCEPT;
352 
354  CONSTCD11 bool ok() const NOEXCEPT;
355 };
356 
357 CONSTCD11 bool operator==(const weekday_last& x, const weekday_last& y) NOEXCEPT;
358 CONSTCD11 bool operator!=(const weekday_last& x, const weekday_last& y) NOEXCEPT;
359 
360 template<class CharT, class Traits>
361 std::basic_ostream<CharT, Traits>&
362 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_last& wdl);
363 
364 // year_month
365 
367 {
368  julian::year y_;
369  julian::month m_;
370 
371 public:
373 
376 
378  CONSTCD14 year_month& operator-=(const months& dm) NOEXCEPT;
380  CONSTCD14 year_month& operator-=(const years& dy) NOEXCEPT;
381 
382  CONSTCD11 bool ok() const NOEXCEPT;
383 };
384 
385 CONSTCD11 bool operator==(const year_month& x, const year_month& y) NOEXCEPT;
386 CONSTCD11 bool operator!=(const year_month& x, const year_month& y) NOEXCEPT;
387 CONSTCD11 bool operator< (const year_month& x, const year_month& y) NOEXCEPT;
388 CONSTCD11 bool operator> (const year_month& x, const year_month& y) NOEXCEPT;
389 CONSTCD11 bool operator<=(const year_month& x, const year_month& y) NOEXCEPT;
390 CONSTCD11 bool operator>=(const year_month& x, const year_month& y) NOEXCEPT;
391 
395 
397 CONSTCD11 year_month operator+(const year_month& ym, const years& dy) NOEXCEPT;
398 CONSTCD11 year_month operator+(const years& dy, const year_month& ym) NOEXCEPT;
399 CONSTCD11 year_month operator-(const year_month& ym, const years& dy) NOEXCEPT;
400 
401 template<class CharT, class Traits>
402 std::basic_ostream<CharT, Traits>&
403 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month& ym);
404 
405 // month_day
406 
408 {
409  julian::month m_;
410  julian::day d_;
411 
412 public:
414 
417 
418  CONSTCD14 bool ok() const NOEXCEPT;
419 };
420 
421 CONSTCD11 bool operator==(const month_day& x, const month_day& y) NOEXCEPT;
422 CONSTCD11 bool operator!=(const month_day& x, const month_day& y) NOEXCEPT;
423 CONSTCD11 bool operator< (const month_day& x, const month_day& y) NOEXCEPT;
424 CONSTCD11 bool operator> (const month_day& x, const month_day& y) NOEXCEPT;
425 CONSTCD11 bool operator<=(const month_day& x, const month_day& y) NOEXCEPT;
426 CONSTCD11 bool operator>=(const month_day& x, const month_day& y) NOEXCEPT;
427 
428 template<class CharT, class Traits>
429 std::basic_ostream<CharT, Traits>&
430 operator<<(std::basic_ostream<CharT, Traits>& os, const month_day& md);
431 
432 // month_day_last
433 
435 {
436  julian::month m_;
437 
438 public:
439  CONSTCD11 explicit month_day_last(const julian::month& m) NOEXCEPT;
440 
442  CONSTCD11 bool ok() const NOEXCEPT;
443 };
444 
451 
452 template<class CharT, class Traits>
453 std::basic_ostream<CharT, Traits>&
454 operator<<(std::basic_ostream<CharT, Traits>& os, const month_day_last& mdl);
455 
456 // month_weekday
457 
459 {
460  julian::month m_;
462 public:
464  const julian::weekday_indexed& wdi) NOEXCEPT;
465 
468 
469  CONSTCD11 bool ok() const NOEXCEPT;
470 };
471 
472 CONSTCD11 bool operator==(const month_weekday& x, const month_weekday& y) NOEXCEPT;
473 CONSTCD11 bool operator!=(const month_weekday& x, const month_weekday& y) NOEXCEPT;
474 
475 template<class CharT, class Traits>
476 std::basic_ostream<CharT, Traits>&
477 operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday& mwd);
478 
479 // month_weekday_last
480 
482 {
483  julian::month m_;
485 
486 public:
488  const julian::weekday_last& wd) NOEXCEPT;
489 
492 
493  CONSTCD11 bool ok() const NOEXCEPT;
494 };
495 
496 CONSTCD11
497  bool operator==(const month_weekday_last& x, const month_weekday_last& y) NOEXCEPT;
498 CONSTCD11
499  bool operator!=(const month_weekday_last& x, const month_weekday_last& y) NOEXCEPT;
500 
501 template<class CharT, class Traits>
502 std::basic_ostream<CharT, Traits>&
503 operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday_last& mwdl);
504 
505 // class year_month_day
506 
508 {
509  julian::year y_;
510  julian::month m_;
511  julian::day d_;
512 
513 public:
515  const julian::day& d) NOEXCEPT;
517 
520 
522  CONSTCD14 year_month_day& operator-=(const months& m) NOEXCEPT;
524  CONSTCD14 year_month_day& operator-=(const years& y) NOEXCEPT;
525 
529 
530  CONSTCD14 operator sys_days() const NOEXCEPT;
531  CONSTCD14 explicit operator local_days() const NOEXCEPT;
532  CONSTCD14 bool ok() const NOEXCEPT;
533 
534 private:
535  static CONSTCD14 year_month_day from_days(days dp) NOEXCEPT;
536  CONSTCD14 days to_days() const NOEXCEPT;
537 };
538 
545 
552 
553 template<class CharT, class Traits>
554 std::basic_ostream<CharT, Traits>&
555 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day& ymd);
556 
557 // year_month_day_last
558 
560 {
561  julian::year y_;
563 
564 public:
566  const julian::month_day_last& mdl) NOEXCEPT;
567 
569  CONSTCD14 year_month_day_last& operator-=(const months& m) NOEXCEPT;
571  CONSTCD14 year_month_day_last& operator-=(const years& y) NOEXCEPT;
572 
577 
578  CONSTCD14 operator sys_days() const NOEXCEPT;
579  CONSTCD14 explicit operator local_days() const NOEXCEPT;
580  CONSTCD11 bool ok() const NOEXCEPT;
581 };
582 
583 CONSTCD11
585 CONSTCD11
587 CONSTCD11
589 CONSTCD11
591 CONSTCD11
593 CONSTCD11
595 
596 CONSTCD14
598 operator+(const year_month_day_last& ymdl, const months& dm) NOEXCEPT;
599 
600 CONSTCD14
602 operator+(const months& dm, const year_month_day_last& ymdl) NOEXCEPT;
603 
604 CONSTCD11
606 operator+(const year_month_day_last& ymdl, const years& dy) NOEXCEPT;
607 
608 CONSTCD11
610 operator+(const years& dy, const year_month_day_last& ymdl) NOEXCEPT;
611 
612 CONSTCD14
614 operator-(const year_month_day_last& ymdl, const months& dm) NOEXCEPT;
615 
616 CONSTCD11
618 operator-(const year_month_day_last& ymdl, const years& dy) NOEXCEPT;
619 
620 template<class CharT, class Traits>
621 std::basic_ostream<CharT, Traits>&
622 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day_last& ymdl);
623 
624 // year_month_weekday
625 
627 {
628  julian::year y_;
629  julian::month m_;
631 
632 public:
634  const julian::weekday_indexed& wdi) NOEXCEPT;
636  CONSTCD14 explicit year_month_weekday(const local_days& dp) NOEXCEPT;
637 
639  CONSTCD14 year_month_weekday& operator-=(const months& m) NOEXCEPT;
641  CONSTCD14 year_month_weekday& operator-=(const years& y) NOEXCEPT;
642 
646  CONSTCD11 unsigned index() const NOEXCEPT;
648 
649  CONSTCD14 operator sys_days() const NOEXCEPT;
650  CONSTCD14 explicit operator local_days() const NOEXCEPT;
651  CONSTCD14 bool ok() const NOEXCEPT;
652 
653 private:
654  static CONSTCD14 year_month_weekday from_days(days dp) NOEXCEPT;
655  CONSTCD14 days to_days() const NOEXCEPT;
656 };
657 
658 CONSTCD11
659  bool operator==(const year_month_weekday& x, const year_month_weekday& y) NOEXCEPT;
660 CONSTCD11
661  bool operator!=(const year_month_weekday& x, const year_month_weekday& y) NOEXCEPT;
662 
663 CONSTCD14
665 operator+(const year_month_weekday& ymwd, const months& dm) NOEXCEPT;
666 
667 CONSTCD14
669 operator+(const months& dm, const year_month_weekday& ymwd) NOEXCEPT;
670 
671 CONSTCD11
673 operator+(const year_month_weekday& ymwd, const years& dy) NOEXCEPT;
674 
675 CONSTCD11
677 operator+(const years& dy, const year_month_weekday& ymwd) NOEXCEPT;
678 
679 CONSTCD14
681 operator-(const year_month_weekday& ymwd, const months& dm) NOEXCEPT;
682 
683 CONSTCD11
685 operator-(const year_month_weekday& ymwd, const years& dy) NOEXCEPT;
686 
687 template<class CharT, class Traits>
688 std::basic_ostream<CharT, Traits>&
689 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwdi);
690 
691 // year_month_weekday_last
692 
694 {
695  julian::year y_;
696  julian::month m_;
698 
699 public:
701  const julian::weekday_last& wdl) NOEXCEPT;
702 
704  CONSTCD14 year_month_weekday_last& operator-=(const months& m) NOEXCEPT;
706  CONSTCD14 year_month_weekday_last& operator-=(const years& y) NOEXCEPT;
707 
712 
713  CONSTCD14 operator sys_days() const NOEXCEPT;
714  CONSTCD14 explicit operator local_days() const NOEXCEPT;
715  CONSTCD11 bool ok() const NOEXCEPT;
716 
717 private:
718  CONSTCD14 days to_days() const NOEXCEPT;
719 };
720 
721 CONSTCD11
722 bool
724 
725 CONSTCD11
726 bool
728 
729 CONSTCD14
731 operator+(const year_month_weekday_last& ymwdl, const months& dm) NOEXCEPT;
732 
733 CONSTCD14
735 operator+(const months& dm, const year_month_weekday_last& ymwdl) NOEXCEPT;
736 
737 CONSTCD11
739 operator+(const year_month_weekday_last& ymwdl, const years& dy) NOEXCEPT;
740 
741 CONSTCD11
743 operator+(const years& dy, const year_month_weekday_last& ymwdl) NOEXCEPT;
744 
745 CONSTCD14
747 operator-(const year_month_weekday_last& ymwdl, const months& dm) NOEXCEPT;
748 
749 CONSTCD11
751 operator-(const year_month_weekday_last& ymwdl, const years& dy) NOEXCEPT;
752 
753 template<class CharT, class Traits>
754 std::basic_ostream<CharT, Traits>&
755 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl);
756 
757 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
758 inline namespace literals
759 {
760 
761 CONSTCD11 julian::day operator "" _d(unsigned long long d) NOEXCEPT;
762 CONSTCD11 julian::year operator "" _y(unsigned long long y) NOEXCEPT;
763 
764 // CONSTDATA julian::month jan{1};
765 // CONSTDATA julian::month feb{2};
766 // CONSTDATA julian::month mar{3};
767 // CONSTDATA julian::month apr{4};
768 // CONSTDATA julian::month may{5};
769 // CONSTDATA julian::month jun{6};
770 // CONSTDATA julian::month jul{7};
771 // CONSTDATA julian::month aug{8};
772 // CONSTDATA julian::month sep{9};
773 // CONSTDATA julian::month oct{10};
774 // CONSTDATA julian::month nov{11};
775 // CONSTDATA julian::month dec{12};
776 
777 } // inline namespace literals
778 #endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
779 
780 //----------------+
781 // Implementation |
782 //----------------+
783 
784 // day
785 
786 CONSTCD11 inline day::day(unsigned d) NOEXCEPT : d_(static_cast<unsigned char>(d)) {}
787 CONSTCD14 inline day& day::operator++() NOEXCEPT {++d_; return *this;}
788 CONSTCD14 inline day day::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
789 CONSTCD14 inline day& day::operator--() NOEXCEPT {--d_; return *this;}
790 CONSTCD14 inline day day::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
791 CONSTCD14 inline day& day::operator+=(const days& d) NOEXCEPT {*this = *this + d; return *this;}
792 CONSTCD14 inline day& day::operator-=(const days& d) NOEXCEPT {*this = *this - d; return *this;}
793 CONSTCD11 inline day::operator unsigned() const NOEXCEPT {return d_;}
794 CONSTCD11 inline bool day::ok() const NOEXCEPT {return 1 <= d_ && d_ <= 31;}
795 
796 CONSTCD11
797 inline
798 bool
799 operator==(const day& x, const day& y) NOEXCEPT
800 {
801  return static_cast<unsigned>(x) == static_cast<unsigned>(y);
802 }
803 
804 CONSTCD11
805 inline
806 bool
807 operator!=(const day& x, const day& y) NOEXCEPT
808 {
809  return !(x == y);
810 }
811 
812 CONSTCD11
813 inline
814 bool
815 operator<(const day& x, const day& y) NOEXCEPT
816 {
817  return static_cast<unsigned>(x) < static_cast<unsigned>(y);
818 }
819 
820 CONSTCD11
821 inline
822 bool
823 operator>(const day& x, const day& y) NOEXCEPT
824 {
825  return y < x;
826 }
827 
828 CONSTCD11
829 inline
830 bool
831 operator<=(const day& x, const day& y) NOEXCEPT
832 {
833  return !(y < x);
834 }
835 
836 CONSTCD11
837 inline
838 bool
839 operator>=(const day& x, const day& y) NOEXCEPT
840 {
841  return !(x < y);
842 }
843 
844 CONSTCD11
845 inline
846 days
847 operator-(const day& x, const day& y) NOEXCEPT
848 {
849  return days{static_cast<days::rep>(static_cast<unsigned>(x)
850  - static_cast<unsigned>(y))};
851 }
852 
853 CONSTCD11
854 inline
855 day
856 operator+(const day& x, const days& y) NOEXCEPT
857 {
858  return day{static_cast<unsigned>(x) + static_cast<unsigned>(y.count())};
859 }
860 
861 CONSTCD11
862 inline
863 day
864 operator+(const days& x, const day& y) NOEXCEPT
865 {
866  return y + x;
867 }
868 
869 CONSTCD11
870 inline
871 day
872 operator-(const day& x, const days& y) NOEXCEPT
873 {
874  return x + -y;
875 }
876 
877 template<class CharT, class Traits>
878 inline
879 std::basic_ostream<CharT, Traits>&
880 operator<<(std::basic_ostream<CharT, Traits>& os, const day& d)
881 {
883  os.fill('0');
884  os.flags(std::ios::dec | std::ios::right);
885  os.width(2);
886  os << static_cast<unsigned>(d);
887  return os;
888 }
889 
890 // month
891 
892 CONSTCD11 inline month::month(unsigned m) NOEXCEPT : m_(static_cast<decltype(m_)>(m)) {}
893 CONSTCD14 inline month& month::operator++() NOEXCEPT {if (++m_ == 13) m_ = 1; return *this;}
894 CONSTCD14 inline month month::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
895 CONSTCD14 inline month& month::operator--() NOEXCEPT {if (--m_ == 0) m_ = 12; return *this;}
896 CONSTCD14 inline month month::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
897 
898 CONSTCD14
899 inline
900 month&
901 month::operator+=(const months& m) NOEXCEPT
902 {
903  *this = *this + m;
904  return *this;
905 }
906 
907 CONSTCD14
908 inline
909 month&
910 month::operator-=(const months& m) NOEXCEPT
911 {
912  *this = *this - m;
913  return *this;
914 }
915 
916 CONSTCD11 inline month::operator unsigned() const NOEXCEPT {return m_;}
917 CONSTCD11 inline bool month::ok() const NOEXCEPT {return 1 <= m_ && m_ <= 12;}
918 
919 CONSTCD11
920 inline
921 bool
922 operator==(const month& x, const month& y) NOEXCEPT
923 {
924  return static_cast<unsigned>(x) == static_cast<unsigned>(y);
925 }
926 
927 CONSTCD11
928 inline
929 bool
930 operator!=(const month& x, const month& y) NOEXCEPT
931 {
932  return !(x == y);
933 }
934 
935 CONSTCD11
936 inline
937 bool
938 operator<(const month& x, const month& y) NOEXCEPT
939 {
940  return static_cast<unsigned>(x) < static_cast<unsigned>(y);
941 }
942 
943 CONSTCD11
944 inline
945 bool
946 operator>(const month& x, const month& y) NOEXCEPT
947 {
948  return y < x;
949 }
950 
951 CONSTCD11
952 inline
953 bool
954 operator<=(const month& x, const month& y) NOEXCEPT
955 {
956  return !(y < x);
957 }
958 
959 CONSTCD11
960 inline
961 bool
962 operator>=(const month& x, const month& y) NOEXCEPT
963 {
964  return !(x < y);
965 }
966 
967 CONSTCD14
968 inline
969 months
970 operator-(const month& x, const month& y) NOEXCEPT
971 {
972  auto const d = static_cast<unsigned>(x) - static_cast<unsigned>(y);
973  return months(d <= 11 ? d : d + 12);
974 }
975 
976 CONSTCD14
977 inline
978 month
979 operator+(const month& x, const months& y) NOEXCEPT
980 {
981  auto const mu = static_cast<long long>(static_cast<unsigned>(x)) - 1 + y.count();
982  auto const yr = (mu >= 0 ? mu : mu-11) / 12;
983  return month{static_cast<unsigned>(mu - yr * 12 + 1)};
984 }
985 
986 CONSTCD14
987 inline
988 month
989 operator+(const months& x, const month& y) NOEXCEPT
990 {
991  return y + x;
992 }
993 
994 CONSTCD14
995 inline
996 month
997 operator-(const month& x, const months& y) NOEXCEPT
998 {
999  return x + -y;
1000 }
1001 
1002 template<class CharT, class Traits>
1003 inline
1004 std::basic_ostream<CharT, Traits>&
1005 operator<<(std::basic_ostream<CharT, Traits>& os, const month& m)
1006 {
1007  switch (static_cast<unsigned>(m))
1008  {
1009  case 1:
1010  os << "Jan";
1011  break;
1012  case 2:
1013  os << "Feb";
1014  break;
1015  case 3:
1016  os << "Mar";
1017  break;
1018  case 4:
1019  os << "Apr";
1020  break;
1021  case 5:
1022  os << "May";
1023  break;
1024  case 6:
1025  os << "Jun";
1026  break;
1027  case 7:
1028  os << "Jul";
1029  break;
1030  case 8:
1031  os << "Aug";
1032  break;
1033  case 9:
1034  os << "Sep";
1035  break;
1036  case 10:
1037  os << "Oct";
1038  break;
1039  case 11:
1040  os << "Nov";
1041  break;
1042  case 12:
1043  os << "Dec";
1044  break;
1045  default:
1046  os << static_cast<unsigned>(m) << " is not a valid month";
1047  break;
1048  }
1049  return os;
1050 }
1051 
1052 // year
1053 
1054 CONSTCD11 inline year::year(int y) NOEXCEPT : y_(static_cast<decltype(y_)>(y)) {}
1055 CONSTCD14 inline year& year::operator++() NOEXCEPT {++y_; return *this;}
1056 CONSTCD14 inline year year::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
1057 CONSTCD14 inline year& year::operator--() NOEXCEPT {--y_; return *this;}
1058 CONSTCD14 inline year year::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
1059 CONSTCD14 inline year& year::operator+=(const years& y) NOEXCEPT {*this = *this + y; return *this;}
1060 CONSTCD14 inline year& year::operator-=(const years& y) NOEXCEPT {*this = *this - y; return *this;}
1061 
1062 CONSTCD11
1063 inline
1064 bool
1065 year::is_leap() const NOEXCEPT
1066 {
1067  return y_ % 4 == 0;
1068 }
1069 
1070 CONSTCD11 inline year::operator int() const NOEXCEPT {return y_;}
1071 CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;}
1072 
1073 CONSTCD11
1074 inline
1075 year
1076 year::min() NOEXCEPT
1077 {
1078  return year{std::numeric_limits<short>::min()};
1079 }
1080 
1081 CONSTCD11
1082 inline
1083 year
1084 year::max() NOEXCEPT
1085 {
1086  return year{std::numeric_limits<short>::max()};
1087 }
1088 
1089 CONSTCD11
1090 inline
1091 bool
1092 operator==(const year& x, const year& y) NOEXCEPT
1093 {
1094  return static_cast<int>(x) == static_cast<int>(y);
1095 }
1096 
1097 CONSTCD11
1098 inline
1099 bool
1100 operator!=(const year& x, const year& y) NOEXCEPT
1101 {
1102  return !(x == y);
1103 }
1104 
1105 CONSTCD11
1106 inline
1107 bool
1108 operator<(const year& x, const year& y) NOEXCEPT
1109 {
1110  return static_cast<int>(x) < static_cast<int>(y);
1111 }
1112 
1113 CONSTCD11
1114 inline
1115 bool
1116 operator>(const year& x, const year& y) NOEXCEPT
1117 {
1118  return y < x;
1119 }
1120 
1121 CONSTCD11
1122 inline
1123 bool
1124 operator<=(const year& x, const year& y) NOEXCEPT
1125 {
1126  return !(y < x);
1127 }
1128 
1129 CONSTCD11
1130 inline
1131 bool
1132 operator>=(const year& x, const year& y) NOEXCEPT
1133 {
1134  return !(x < y);
1135 }
1136 
1137 CONSTCD11
1138 inline
1139 years
1140 operator-(const year& x, const year& y) NOEXCEPT
1141 {
1142  return years{static_cast<int>(x) - static_cast<int>(y)};
1143 }
1144 
1145 CONSTCD11
1146 inline
1147 year
1148 operator+(const year& x, const years& y) NOEXCEPT
1149 {
1150  return year{static_cast<int>(x) + y.count()};
1151 }
1152 
1153 CONSTCD11
1154 inline
1155 year
1156 operator+(const years& x, const year& y) NOEXCEPT
1157 {
1158  return y + x;
1159 }
1160 
1161 CONSTCD11
1162 inline
1163 year
1164 operator-(const year& x, const years& y) NOEXCEPT
1165 {
1166  return year{static_cast<int>(x) - y.count()};
1167 }
1168 
1169 template<class CharT, class Traits>
1170 inline
1171 std::basic_ostream<CharT, Traits>&
1172 operator<<(std::basic_ostream<CharT, Traits>& os, const year& y)
1173 {
1175  os.fill('0');
1176  os.flags(std::ios::dec | std::ios::internal);
1177  os.width(4 + (y < year{0}));
1178  os << static_cast<int>(y);
1179  return os;
1180 }
1181 
1182 // weekday
1183 
1184 CONSTCD11
1185 inline
1186 unsigned char
1187 weekday::weekday_from_days(int z) NOEXCEPT
1188 {
1189  return static_cast<unsigned char>(static_cast<unsigned>(
1190  z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6));
1191 }
1192 
1193 CONSTCD11
1194 inline
1196  : wd_(static_cast<decltype(wd_)>(wd))
1197  {}
1198 
1199 CONSTCD11
1200 inline
1202  : wd_(weekday_from_days(dp.time_since_epoch().count()))
1203  {}
1204 
1205 CONSTCD11
1206 inline
1208  : wd_(weekday_from_days(dp.time_since_epoch().count()))
1209  {}
1210 
1211 CONSTCD14 inline weekday& weekday::operator++() NOEXCEPT {if (++wd_ == 7) wd_ = 0; return *this;}
1212 CONSTCD14 inline weekday weekday::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
1213 CONSTCD14 inline weekday& weekday::operator--() NOEXCEPT {if (wd_-- == 0) wd_ = 6; return *this;}
1214 CONSTCD14 inline weekday weekday::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
1215 
1216 CONSTCD14
1217 inline
1218 weekday&
1219 weekday::operator+=(const days& d) NOEXCEPT
1220 {
1221  *this = *this + d;
1222  return *this;
1223 }
1224 
1225 CONSTCD14
1226 inline
1227 weekday&
1228 weekday::operator-=(const days& d) NOEXCEPT
1229 {
1230  *this = *this - d;
1231  return *this;
1232 }
1233 
1234 CONSTCD11
1235 inline
1236 weekday::operator unsigned() const NOEXCEPT
1237 {
1238  return static_cast<unsigned>(wd_);
1239 }
1240 
1241 CONSTCD11 inline bool weekday::ok() const NOEXCEPT {return wd_ <= 6;}
1242 
1243 CONSTCD11
1244 inline
1245 bool
1246 operator==(const weekday& x, const weekday& y) NOEXCEPT
1247 {
1248  return static_cast<unsigned>(x) == static_cast<unsigned>(y);
1249 }
1250 
1251 CONSTCD11
1252 inline
1253 bool
1254 operator!=(const weekday& x, const weekday& y) NOEXCEPT
1255 {
1256  return !(x == y);
1257 }
1258 
1259 CONSTCD14
1260 inline
1261 days
1262 operator-(const weekday& x, const weekday& y) NOEXCEPT
1263 {
1264  auto const diff = static_cast<unsigned>(x) - static_cast<unsigned>(y);
1265  return days{diff <= 6 ? diff : diff + 7};
1266 }
1267 
1268 CONSTCD14
1269 inline
1270 weekday
1271 operator+(const weekday& x, const days& y) NOEXCEPT
1272 {
1273  auto const wdu = static_cast<long long>(static_cast<unsigned>(x)) + y.count();
1274  auto const wk = (wdu >= 0 ? wdu : wdu-6) / 7;
1275  return weekday{static_cast<unsigned>(wdu - wk * 7)};
1276 }
1277 
1278 CONSTCD14
1279 inline
1280 weekday
1281 operator+(const days& x, const weekday& y) NOEXCEPT
1282 {
1283  return y + x;
1284 }
1285 
1286 CONSTCD14
1287 inline
1288 weekday
1289 operator-(const weekday& x, const days& y) NOEXCEPT
1290 {
1291  return x + -y;
1292 }
1293 
1294 template<class CharT, class Traits>
1295 inline
1296 std::basic_ostream<CharT, Traits>&
1297 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday& wd)
1298 {
1299  switch (static_cast<unsigned>(wd))
1300  {
1301  case 0:
1302  os << "Sun";
1303  break;
1304  case 1:
1305  os << "Mon";
1306  break;
1307  case 2:
1308  os << "Tue";
1309  break;
1310  case 3:
1311  os << "Wed";
1312  break;
1313  case 4:
1314  os << "Thu";
1315  break;
1316  case 5:
1317  os << "Fri";
1318  break;
1319  case 6:
1320  os << "Sat";
1321  break;
1322  default:
1323  os << static_cast<unsigned>(wd) << " is not a valid weekday";
1324  break;
1325  }
1326  return os;
1327 }
1328 
1329 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1330 inline namespace literals
1331 {
1332 
1333 CONSTCD11
1334 inline
1336 operator "" _d(unsigned long long d) NOEXCEPT
1337 {
1338  return julian::day{static_cast<unsigned>(d)};
1339 }
1340 
1341 CONSTCD11
1342 inline
1344 operator "" _y(unsigned long long y) NOEXCEPT
1345 {
1346  return julian::year(static_cast<int>(y));
1347 }
1348 #endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
1349 
1351 
1364 
1372 
1373 #if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1374 } // inline namespace literals
1375 #endif
1376 
1377 // weekday_indexed
1378 
1379 CONSTCD11
1380 inline
1381 weekday
1383 {
1384  return julian::weekday{static_cast<unsigned>(wd_)};
1385 }
1386 
1387 CONSTCD11 inline unsigned weekday_indexed::index() const NOEXCEPT {return index_;}
1388 
1389 CONSTCD11
1390 inline
1391 bool
1392 weekday_indexed::ok() const NOEXCEPT
1393 {
1394  return weekday().ok() && 1 <= index_ && index_ <= 5;
1395 }
1396 
1397 CONSTCD11
1398 inline
1400  : wd_(static_cast<decltype(wd_)>(static_cast<unsigned>(wd)))
1401  , index_(static_cast<decltype(index_)>(index))
1402  {}
1403 
1404 template<class CharT, class Traits>
1405 inline
1406 std::basic_ostream<CharT, Traits>&
1407 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_indexed& wdi)
1408 {
1409  return os << wdi.weekday() << '[' << wdi.index() << ']';
1410 }
1411 
1412 CONSTCD11
1413 inline
1415 weekday::operator[](unsigned index) const NOEXCEPT
1416 {
1417  return {*this, index};
1418 }
1419 
1420 CONSTCD11
1421 inline
1422 bool
1423 operator==(const weekday_indexed& x, const weekday_indexed& y) NOEXCEPT
1424 {
1425  return x.weekday() == y.weekday() && x.index() == y.index();
1426 }
1427 
1428 CONSTCD11
1429 inline
1430 bool
1431 operator!=(const weekday_indexed& x, const weekday_indexed& y) NOEXCEPT
1432 {
1433  return !(x == y);
1434 }
1435 
1436 // weekday_last
1437 
1438 CONSTCD11 inline julian::weekday weekday_last::weekday() const NOEXCEPT {return wd_;}
1439 CONSTCD11 inline bool weekday_last::ok() const NOEXCEPT {return wd_.ok();}
1441 
1442 CONSTCD11
1443 inline
1444 bool
1445 operator==(const weekday_last& x, const weekday_last& y) NOEXCEPT
1446 {
1447  return x.weekday() == y.weekday();
1448 }
1449 
1450 CONSTCD11
1451 inline
1452 bool
1453 operator!=(const weekday_last& x, const weekday_last& y) NOEXCEPT
1454 {
1455  return !(x == y);
1456 }
1457 
1458 template<class CharT, class Traits>
1459 inline
1460 std::basic_ostream<CharT, Traits>&
1461 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_last& wdl)
1462 {
1463  return os << wdl.weekday() << "[last]";
1464 }
1465 
1466 CONSTCD11
1467 inline
1470 {
1471  return weekday_last{*this};
1472 }
1473 
1474 // year_month
1475 
1476 CONSTCD11
1477 inline
1479  : y_(y)
1480  , m_(m)
1481  {}
1482 
1483 CONSTCD11 inline year year_month::year() const NOEXCEPT {return y_;}
1484 CONSTCD11 inline month year_month::month() const NOEXCEPT {return m_;}
1485 CONSTCD11 inline bool year_month::ok() const NOEXCEPT {return y_.ok() && m_.ok();}
1486 
1487 CONSTCD14
1488 inline
1489 year_month&
1490 year_month::operator+=(const months& dm) NOEXCEPT
1491 {
1492  *this = *this + dm;
1493  return *this;
1494 }
1495 
1496 CONSTCD14
1497 inline
1498 year_month&
1499 year_month::operator-=(const months& dm) NOEXCEPT
1500 {
1501  *this = *this - dm;
1502  return *this;
1503 }
1504 
1505 CONSTCD14
1506 inline
1507 year_month&
1508 year_month::operator+=(const years& dy) NOEXCEPT
1509 {
1510  *this = *this + dy;
1511  return *this;
1512 }
1513 
1514 CONSTCD14
1515 inline
1516 year_month&
1517 year_month::operator-=(const years& dy) NOEXCEPT
1518 {
1519  *this = *this - dy;
1520  return *this;
1521 }
1522 
1523 CONSTCD11
1524 inline
1525 bool
1526 operator==(const year_month& x, const year_month& y) NOEXCEPT
1527 {
1528  return x.year() == y.year() && x.month() == y.month();
1529 }
1530 
1531 CONSTCD11
1532 inline
1533 bool
1534 operator!=(const year_month& x, const year_month& y) NOEXCEPT
1535 {
1536  return !(x == y);
1537 }
1538 
1539 CONSTCD11
1540 inline
1541 bool
1542 operator<(const year_month& x, const year_month& y) NOEXCEPT
1543 {
1544  return x.year() < y.year() ? true
1545  : (x.year() > y.year() ? false
1546  : (x.month() < y.month()));
1547 }
1548 
1549 CONSTCD11
1550 inline
1551 bool
1552 operator>(const year_month& x, const year_month& y) NOEXCEPT
1553 {
1554  return y < x;
1555 }
1556 
1557 CONSTCD11
1558 inline
1559 bool
1560 operator<=(const year_month& x, const year_month& y) NOEXCEPT
1561 {
1562  return !(y < x);
1563 }
1564 
1565 CONSTCD11
1566 inline
1567 bool
1568 operator>=(const year_month& x, const year_month& y) NOEXCEPT
1569 {
1570  return !(x < y);
1571 }
1572 
1573 CONSTCD14
1574 inline
1575 year_month
1576 operator+(const year_month& ym, const months& dm) NOEXCEPT
1577 {
1578  auto dmi = static_cast<int>(static_cast<unsigned>(ym.month())) - 1 + dm.count();
1579  auto dy = (dmi >= 0 ? dmi : dmi-11) / 12;
1580  dmi = dmi - dy * 12 + 1;
1581  return (ym.year() + years(dy)) / month(static_cast<unsigned>(dmi));
1582 }
1583 
1584 CONSTCD14
1585 inline
1586 year_month
1587 operator+(const months& dm, const year_month& ym) NOEXCEPT
1588 {
1589  return ym + dm;
1590 }
1591 
1592 CONSTCD14
1593 inline
1594 year_month
1595 operator-(const year_month& ym, const months& dm) NOEXCEPT
1596 {
1597  return ym + -dm;
1598 }
1599 
1600 CONSTCD11
1601 inline
1602 months
1603 operator-(const year_month& x, const year_month& y) NOEXCEPT
1604 {
1605  return (x.year() - y.year()) +
1606  months(static_cast<unsigned>(x.month()) - static_cast<unsigned>(y.month()));
1607 }
1608 
1609 CONSTCD11
1610 inline
1611 year_month
1612 operator+(const year_month& ym, const years& dy) NOEXCEPT
1613 {
1614  return (ym.year() + dy) / ym.month();
1615 }
1616 
1617 CONSTCD11
1618 inline
1619 year_month
1620 operator+(const years& dy, const year_month& ym) NOEXCEPT
1621 {
1622  return ym + dy;
1623 }
1624 
1625 CONSTCD11
1626 inline
1627 year_month
1628 operator-(const year_month& ym, const years& dy) NOEXCEPT
1629 {
1630  return ym + -dy;
1631 }
1632 
1633 template<class CharT, class Traits>
1634 inline
1635 std::basic_ostream<CharT, Traits>&
1636 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month& ym)
1637 {
1638  return os << ym.year() << '/' << ym.month();
1639 }
1640 
1641 // month_day
1642 
1643 CONSTCD11
1644 inline
1646  : m_(m)
1647  , d_(d)
1648  {}
1649 
1650 CONSTCD11 inline julian::month month_day::month() const NOEXCEPT {return m_;}
1651 CONSTCD11 inline julian::day month_day::day() const NOEXCEPT {return d_;}
1652 
1653 CONSTCD14
1654 inline
1655 bool
1656 month_day::ok() const NOEXCEPT
1657 {
1658  CONSTDATA julian::day d[] =
1659  {31_d, 29_d, 31_d, 30_d, 31_d, 30_d, 31_d, 31_d, 30_d, 31_d, 30_d, 31_d};
1660  return m_.ok() && 1_d <= d_ && d_ <= d[static_cast<unsigned>(m_)-1];
1661 }
1662 
1663 CONSTCD11
1664 inline
1665 bool
1666 operator==(const month_day& x, const month_day& y) NOEXCEPT
1667 {
1668  return x.month() == y.month() && x.day() == y.day();
1669 }
1670 
1671 CONSTCD11
1672 inline
1673 bool
1674 operator!=(const month_day& x, const month_day& y) NOEXCEPT
1675 {
1676  return !(x == y);
1677 }
1678 
1679 CONSTCD11
1680 inline
1681 bool
1682 operator<(const month_day& x, const month_day& y) NOEXCEPT
1683 {
1684  return x.month() < y.month() ? true
1685  : (x.month() > y.month() ? false
1686  : (x.day() < y.day()));
1687 }
1688 
1689 CONSTCD11
1690 inline
1691 bool
1692 operator>(const month_day& x, const month_day& y) NOEXCEPT
1693 {
1694  return y < x;
1695 }
1696 
1697 CONSTCD11
1698 inline
1699 bool
1700 operator<=(const month_day& x, const month_day& y) NOEXCEPT
1701 {
1702  return !(y < x);
1703 }
1704 
1705 CONSTCD11
1706 inline
1707 bool
1708 operator>=(const month_day& x, const month_day& y) NOEXCEPT
1709 {
1710  return !(x < y);
1711 }
1712 
1713 template<class CharT, class Traits>
1714 inline
1715 std::basic_ostream<CharT, Traits>&
1716 operator<<(std::basic_ostream<CharT, Traits>& os, const month_day& md)
1717 {
1718  return os << md.month() << '/' << md.day();
1719 }
1720 
1721 // month_day_last
1722 
1723 CONSTCD11 inline month month_day_last::month() const NOEXCEPT {return m_;}
1724 CONSTCD11 inline bool month_day_last::ok() const NOEXCEPT {return m_.ok();}
1726 
1727 CONSTCD11
1728 inline
1729 bool
1730 operator==(const month_day_last& x, const month_day_last& y) NOEXCEPT
1731 {
1732  return x.month() == y.month();
1733 }
1734 
1735 CONSTCD11
1736 inline
1737 bool
1738 operator!=(const month_day_last& x, const month_day_last& y) NOEXCEPT
1739 {
1740  return !(x == y);
1741 }
1742 
1743 CONSTCD11
1744 inline
1745 bool
1746 operator<(const month_day_last& x, const month_day_last& y) NOEXCEPT
1747 {
1748  return x.month() < y.month();
1749 }
1750 
1751 CONSTCD11
1752 inline
1753 bool
1754 operator>(const month_day_last& x, const month_day_last& y) NOEXCEPT
1755 {
1756  return y < x;
1757 }
1758 
1759 CONSTCD11
1760 inline
1761 bool
1762 operator<=(const month_day_last& x, const month_day_last& y) NOEXCEPT
1763 {
1764  return !(y < x);
1765 }
1766 
1767 CONSTCD11
1768 inline
1769 bool
1770 operator>=(const month_day_last& x, const month_day_last& y) NOEXCEPT
1771 {
1772  return !(x < y);
1773 }
1774 
1775 template<class CharT, class Traits>
1776 inline
1777 std::basic_ostream<CharT, Traits>&
1778 operator<<(std::basic_ostream<CharT, Traits>& os, const month_day_last& mdl)
1779 {
1780  return os << mdl.month() << "/last";
1781 }
1782 
1783 // month_weekday
1784 
1785 CONSTCD11
1786 inline
1788  const julian::weekday_indexed& wdi) NOEXCEPT
1789  : m_(m)
1790  , wdi_(wdi)
1791  {}
1792 
1793 CONSTCD11 inline month month_weekday::month() const NOEXCEPT {return m_;}
1794 
1795 CONSTCD11
1796 inline
1799 {
1800  return wdi_;
1801 }
1802 
1803 CONSTCD11
1804 inline
1805 bool
1806 month_weekday::ok() const NOEXCEPT
1807 {
1808  return m_.ok() && wdi_.ok();
1809 }
1810 
1811 CONSTCD11
1812 inline
1813 bool
1814 operator==(const month_weekday& x, const month_weekday& y) NOEXCEPT
1815 {
1816  return x.month() == y.month() && x.weekday_indexed() == y.weekday_indexed();
1817 }
1818 
1819 CONSTCD11
1820 inline
1821 bool
1822 operator!=(const month_weekday& x, const month_weekday& y) NOEXCEPT
1823 {
1824  return !(x == y);
1825 }
1826 
1827 template<class CharT, class Traits>
1828 inline
1829 std::basic_ostream<CharT, Traits>&
1830 operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday& mwd)
1831 {
1832  return os << mwd.month() << '/' << mwd.weekday_indexed();
1833 }
1834 
1835 // month_weekday_last
1836 
1837 CONSTCD11
1838 inline
1840  const julian::weekday_last& wdl) NOEXCEPT
1841  : m_(m)
1842  , wdl_(wdl)
1843  {}
1844 
1845 CONSTCD11 inline month month_weekday_last::month() const NOEXCEPT {return m_;}
1846 
1847 CONSTCD11
1848 inline
1851 {
1852  return wdl_;
1853 }
1854 
1855 CONSTCD11
1856 inline
1857 bool
1858 month_weekday_last::ok() const NOEXCEPT
1859 {
1860  return m_.ok() && wdl_.ok();
1861 }
1862 
1863 CONSTCD11
1864 inline
1865 bool
1867 {
1868  return x.month() == y.month() && x.weekday_last() == y.weekday_last();
1869 }
1870 
1871 CONSTCD11
1872 inline
1873 bool
1875 {
1876  return !(x == y);
1877 }
1878 
1879 template<class CharT, class Traits>
1880 inline
1881 std::basic_ostream<CharT, Traits>&
1882 operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday_last& mwdl)
1883 {
1884  return os << mwdl.month() << '/' << mwdl.weekday_last();
1885 }
1886 
1887 // year_month_day_last
1888 
1889 CONSTCD11
1890 inline
1892  const julian::month_day_last& mdl) NOEXCEPT
1893  : y_(y)
1894  , mdl_(mdl)
1895  {}
1896 
1897 CONSTCD14
1898 inline
1901 {
1902  *this = *this + m;
1903  return *this;
1904 }
1905 
1906 CONSTCD14
1907 inline
1910 {
1911  *this = *this - m;
1912  return *this;
1913 }
1914 
1915 CONSTCD14
1916 inline
1919 {
1920  *this = *this + y;
1921  return *this;
1922 }
1923 
1924 CONSTCD14
1925 inline
1928 {
1929  *this = *this - y;
1930  return *this;
1931 }
1932 
1933 CONSTCD11 inline year year_month_day_last::year() const NOEXCEPT {return y_;}
1934 CONSTCD11 inline month year_month_day_last::month() const NOEXCEPT {return mdl_.month();}
1935 
1936 CONSTCD11
1937 inline
1940 {
1941  return mdl_;
1942 }
1943 
1944 CONSTCD14
1945 inline
1946 day
1948 {
1949  CONSTDATA julian::day d[] =
1950  {31_d, 28_d, 31_d, 30_d, 31_d, 30_d, 31_d, 31_d, 30_d, 31_d, 30_d, 31_d};
1951  return month() != feb || !y_.is_leap() ? d[static_cast<unsigned>(month())-1] : 29_d;
1952 }
1953 
1954 CONSTCD14
1955 inline
1956 year_month_day_last::operator sys_days() const NOEXCEPT
1957 {
1958  return sys_days(year()/month()/day());
1959 }
1960 
1961 CONSTCD14
1962 inline
1963 year_month_day_last::operator local_days() const NOEXCEPT
1964 {
1965  return local_days(year()/month()/day());
1966 }
1967 
1968 CONSTCD11
1969 inline
1970 bool
1971 year_month_day_last::ok() const NOEXCEPT
1972 {
1973  return y_.ok() && mdl_.ok();
1974 }
1975 
1976 CONSTCD11
1977 inline
1978 bool
1980 {
1981  return x.year() == y.year() && x.month_day_last() == y.month_day_last();
1982 }
1983 
1984 CONSTCD11
1985 inline
1986 bool
1988 {
1989  return !(x == y);
1990 }
1991 
1992 CONSTCD11
1993 inline
1994 bool
1996 {
1997  return x.year() < y.year() ? true
1998  : (x.year() > y.year() ? false
1999  : (x.month_day_last() < y.month_day_last()));
2000 }
2001 
2002 CONSTCD11
2003 inline
2004 bool
2006 {
2007  return y < x;
2008 }
2009 
2010 CONSTCD11
2011 inline
2012 bool
2014 {
2015  return !(y < x);
2016 }
2017 
2018 CONSTCD11
2019 inline
2020 bool
2022 {
2023  return !(x < y);
2024 }
2025 
2026 template<class CharT, class Traits>
2027 inline
2028 std::basic_ostream<CharT, Traits>&
2029 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day_last& ymdl)
2030 {
2031  return os << ymdl.year() << '/' << ymdl.month_day_last();
2032 }
2033 
2034 CONSTCD14
2035 inline
2037 operator+(const year_month_day_last& ymdl, const months& dm) NOEXCEPT
2038 {
2039  return (ymdl.year() / ymdl.month() + dm) / last;
2040 }
2041 
2042 CONSTCD14
2043 inline
2045 operator+(const months& dm, const year_month_day_last& ymdl) NOEXCEPT
2046 {
2047  return ymdl + dm;
2048 }
2049 
2050 CONSTCD14
2051 inline
2053 operator-(const year_month_day_last& ymdl, const months& dm) NOEXCEPT
2054 {
2055  return ymdl + (-dm);
2056 }
2057 
2058 CONSTCD11
2059 inline
2061 operator+(const year_month_day_last& ymdl, const years& dy) NOEXCEPT
2062 {
2063  return {ymdl.year()+dy, ymdl.month_day_last()};
2064 }
2065 
2066 CONSTCD11
2067 inline
2069 operator+(const years& dy, const year_month_day_last& ymdl) NOEXCEPT
2070 {
2071  return ymdl + dy;
2072 }
2073 
2074 CONSTCD11
2075 inline
2077 operator-(const year_month_day_last& ymdl, const years& dy) NOEXCEPT
2078 {
2079  return ymdl + (-dy);
2080 }
2081 
2082 // year_month_day
2083 
2084 CONSTCD11
2085 inline
2087  const julian::day& d) NOEXCEPT
2088  : y_(y)
2089  , m_(m)
2090  , d_(d)
2091  {}
2092 
2093 CONSTCD14
2094 inline
2096  : y_(ymdl.year())
2097  , m_(ymdl.month())
2098  , d_(ymdl.day())
2099  {}
2100 
2101 CONSTCD14
2102 inline
2104  : year_month_day(from_days(dp.time_since_epoch()))
2105  {}
2106 
2107 CONSTCD14
2108 inline
2110  : year_month_day(from_days(dp.time_since_epoch()))
2111  {}
2112 
2113 CONSTCD11 inline year year_month_day::year() const NOEXCEPT {return y_;}
2114 CONSTCD11 inline month year_month_day::month() const NOEXCEPT {return m_;}
2115 CONSTCD11 inline day year_month_day::day() const NOEXCEPT {return d_;}
2116 
2117 CONSTCD14
2118 inline
2121 {
2122  *this = *this + m;
2123  return *this;
2124 }
2125 
2126 CONSTCD14
2127 inline
2130 {
2131  *this = *this - m;
2132  return *this;
2133 }
2134 
2135 CONSTCD14
2136 inline
2139 {
2140  *this = *this + y;
2141  return *this;
2142 }
2143 
2144 CONSTCD14
2145 inline
2148 {
2149  *this = *this - y;
2150  return *this;
2151 }
2152 
2153 CONSTCD14
2154 inline
2155 days
2156 year_month_day::to_days() const NOEXCEPT
2157 {
2158  static_assert(std::numeric_limits<unsigned>::digits >= 18,
2159  "This algorithm has not been ported to a 16 bit unsigned integer");
2160  static_assert(std::numeric_limits<int>::digits >= 20,
2161  "This algorithm has not been ported to a 16 bit signed integer");
2162  auto const y = static_cast<int>(y_) - (m_ <= feb);
2163  auto const m = static_cast<unsigned>(m_);
2164  auto const d = static_cast<unsigned>(d_);
2165  auto const era = (y >= 0 ? y : y-3) / 4;
2166  auto const yoe = static_cast<unsigned>(y - era * 4); // [0, 3]
2167  auto const doy = (153*(m > 2 ? m-3 : m+9) + 2)/5 + d-1; // [0, 365]
2168  auto const doe = yoe * 365 + doy; // [0, 1460]
2169  return days{era * 1461 + static_cast<int>(doe) - 719470};
2170 }
2171 
2172 CONSTCD14
2173 inline
2174 year_month_day::operator sys_days() const NOEXCEPT
2175 {
2176  return sys_days{to_days()};
2177 }
2178 
2179 CONSTCD14
2180 inline
2181 year_month_day::operator local_days() const NOEXCEPT
2182 {
2183  return local_days{to_days()};
2184 }
2185 
2186 CONSTCD14
2187 inline
2188 bool
2189 year_month_day::ok() const NOEXCEPT
2190 {
2191  if (!(y_.ok() && m_.ok()))
2192  return false;
2193  return 1_d <= d_ && d_ <= (y_/m_/last).day();
2194 }
2195 
2196 CONSTCD11
2197 inline
2198 bool
2199 operator==(const year_month_day& x, const year_month_day& y) NOEXCEPT
2200 {
2201  return x.year() == y.year() && x.month() == y.month() && x.day() == y.day();
2202 }
2203 
2204 CONSTCD11
2205 inline
2206 bool
2207 operator!=(const year_month_day& x, const year_month_day& y) NOEXCEPT
2208 {
2209  return !(x == y);
2210 }
2211 
2212 CONSTCD11
2213 inline
2214 bool
2215 operator<(const year_month_day& x, const year_month_day& y) NOEXCEPT
2216 {
2217  return x.year() < y.year() ? true
2218  : (x.year() > y.year() ? false
2219  : (x.month() < y.month() ? true
2220  : (x.month() > y.month() ? false
2221  : (x.day() < y.day()))));
2222 }
2223 
2224 CONSTCD11
2225 inline
2226 bool
2227 operator>(const year_month_day& x, const year_month_day& y) NOEXCEPT
2228 {
2229  return y < x;
2230 }
2231 
2232 CONSTCD11
2233 inline
2234 bool
2235 operator<=(const year_month_day& x, const year_month_day& y) NOEXCEPT
2236 {
2237  return !(y < x);
2238 }
2239 
2240 CONSTCD11
2241 inline
2242 bool
2243 operator>=(const year_month_day& x, const year_month_day& y) NOEXCEPT
2244 {
2245  return !(x < y);
2246 }
2247 
2248 template<class CharT, class Traits>
2249 inline
2250 std::basic_ostream<CharT, Traits>&
2251 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day& ymd)
2252 {
2254  os.fill('0');
2255  os.flags(std::ios::dec | std::ios::right);
2256  os << ymd.year() << '-';
2257  os.width(2);
2258  os << static_cast<unsigned>(ymd.month()) << '-';
2259  os << ymd.day();
2260  return os;
2261 }
2262 
2263 CONSTCD14
2264 inline
2266 year_month_day::from_days(days dp) NOEXCEPT
2267 {
2268  static_assert(std::numeric_limits<unsigned>::digits >= 18,
2269  "This algorithm has not been ported to a 16 bit unsigned integer");
2270  static_assert(std::numeric_limits<int>::digits >= 20,
2271  "This algorithm has not been ported to a 16 bit signed integer");
2272  auto const z = dp.count() + 719470;
2273  auto const era = (z >= 0 ? z : z - 1460) / 1461;
2274  auto const doe = static_cast<unsigned>(z - era * 1461); // [0, 1460]
2275  auto const yoe = (doe - doe/1460) / 365; // [0, 3]
2276  auto const y = static_cast<sys_days::rep>(yoe) + era * 4;
2277  auto const doy = doe - 365*yoe; // [0, 365]
2278  auto const mp = (5*doy + 2)/153; // [0, 11]
2279  auto const d = doy - (153*mp+2)/5 + 1; // [1, 31]
2280  auto const m = mp < 10 ? mp+3 : mp-9; // [1, 12]
2281  return year_month_day{julian::year{y + (m <= 2)}, julian::month(m), julian::day(d)};
2282 }
2283 
2284 CONSTCD14
2285 inline
2287 operator+(const year_month_day& ymd, const months& dm) NOEXCEPT
2288 {
2289  return (ymd.year() / ymd.month() + dm) / ymd.day();
2290 }
2291 
2292 CONSTCD14
2293 inline
2295 operator+(const months& dm, const year_month_day& ymd) NOEXCEPT
2296 {
2297  return ymd + dm;
2298 }
2299 
2300 CONSTCD14
2301 inline
2303 operator-(const year_month_day& ymd, const months& dm) NOEXCEPT
2304 {
2305  return ymd + (-dm);
2306 }
2307 
2308 CONSTCD11
2309 inline
2311 operator+(const year_month_day& ymd, const years& dy) NOEXCEPT
2312 {
2313  return (ymd.year() + dy) / ymd.month() / ymd.day();
2314 }
2315 
2316 CONSTCD11
2317 inline
2319 operator+(const years& dy, const year_month_day& ymd) NOEXCEPT
2320 {
2321  return ymd + dy;
2322 }
2323 
2324 CONSTCD11
2325 inline
2327 operator-(const year_month_day& ymd, const years& dy) NOEXCEPT
2328 {
2329  return ymd + (-dy);
2330 }
2331 
2332 // year_month_weekday
2333 
2334 CONSTCD11
2335 inline
2337  const julian::weekday_indexed& wdi)
2338  NOEXCEPT
2339  : y_(y)
2340  , m_(m)
2341  , wdi_(wdi)
2342  {}
2343 
2344 CONSTCD14
2345 inline
2347  : year_month_weekday(from_days(dp.time_since_epoch()))
2348  {}
2349 
2350 CONSTCD14
2351 inline
2353  : year_month_weekday(from_days(dp.time_since_epoch()))
2354  {}
2355 
2356 CONSTCD14
2357 inline
2360 {
2361  *this = *this + m;
2362  return *this;
2363 }
2364 
2365 CONSTCD14
2366 inline
2369 {
2370  *this = *this - m;
2371  return *this;
2372 }
2373 
2374 CONSTCD14
2375 inline
2378 {
2379  *this = *this + y;
2380  return *this;
2381 }
2382 
2383 CONSTCD14
2384 inline
2387 {
2388  *this = *this - y;
2389  return *this;
2390 }
2391 
2392 CONSTCD11 inline year year_month_weekday::year() const NOEXCEPT {return y_;}
2393 CONSTCD11 inline month year_month_weekday::month() const NOEXCEPT {return m_;}
2394 
2395 CONSTCD11
2396 inline
2397 weekday
2399 {
2400  return wdi_.weekday();
2401 }
2402 
2403 CONSTCD11
2404 inline
2405 unsigned
2407 {
2408  return wdi_.index();
2409 }
2410 
2411 CONSTCD11
2412 inline
2415 {
2416  return wdi_;
2417 }
2418 
2419 CONSTCD14
2420 inline
2421 year_month_weekday::operator sys_days() const NOEXCEPT
2422 {
2423  return sys_days{to_days()};
2424 }
2425 
2426 CONSTCD14
2427 inline
2428 year_month_weekday::operator local_days() const NOEXCEPT
2429 {
2430  return local_days{to_days()};
2431 }
2432 
2433 CONSTCD14
2434 inline
2435 bool
2436 year_month_weekday::ok() const NOEXCEPT
2437 {
2438  if (!y_.ok() || !m_.ok() || !wdi_.weekday().ok() || wdi_.index() < 1)
2439  return false;
2440  if (wdi_.index() <= 4)
2441  return true;
2442  auto d2 = wdi_.weekday() - julian::weekday(y_/m_/1) + days((wdi_.index()-1)*7 + 1);
2443  return static_cast<unsigned>(d2.count()) <= static_cast<unsigned>((y_/m_/last).day());
2444 }
2445 
2446 CONSTCD14
2447 inline
2449 year_month_weekday::from_days(days d) NOEXCEPT
2450 {
2451  sys_days dp{d};
2452  auto const wd = julian::weekday(dp);
2453  auto const ymd = year_month_day(dp);
2454  return {ymd.year(), ymd.month(), wd[(static_cast<unsigned>(ymd.day())-1)/7+1]};
2455 }
2456 
2457 CONSTCD14
2458 inline
2459 days
2460 year_month_weekday::to_days() const NOEXCEPT
2461 {
2462  auto d = sys_days(y_/m_/1);
2463  return (d + (wdi_.weekday() - julian::weekday(d) + days{(wdi_.index()-1)*7})
2464  ).time_since_epoch();
2465 }
2466 
2467 CONSTCD11
2468 inline
2469 bool
2471 {
2472  return x.year() == y.year() && x.month() == y.month() &&
2473  x.weekday_indexed() == y.weekday_indexed();
2474 }
2475 
2476 CONSTCD11
2477 inline
2478 bool
2480 {
2481  return !(x == y);
2482 }
2483 
2484 template<class CharT, class Traits>
2485 inline
2486 std::basic_ostream<CharT, Traits>&
2487 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwdi)
2488 {
2489  return os << ymwdi.year() << '/' << ymwdi.month()
2490  << '/' << ymwdi.weekday_indexed();
2491 }
2492 
2493 CONSTCD14
2494 inline
2496 operator+(const year_month_weekday& ymwd, const months& dm) NOEXCEPT
2497 {
2498  return (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed();
2499 }
2500 
2501 CONSTCD14
2502 inline
2504 operator+(const months& dm, const year_month_weekday& ymwd) NOEXCEPT
2505 {
2506  return ymwd + dm;
2507 }
2508 
2509 CONSTCD14
2510 inline
2512 operator-(const year_month_weekday& ymwd, const months& dm) NOEXCEPT
2513 {
2514  return ymwd + (-dm);
2515 }
2516 
2517 CONSTCD11
2518 inline
2520 operator+(const year_month_weekday& ymwd, const years& dy) NOEXCEPT
2521 {
2522  return {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()};
2523 }
2524 
2525 CONSTCD11
2526 inline
2528 operator+(const years& dy, const year_month_weekday& ymwd) NOEXCEPT
2529 {
2530  return ymwd + dy;
2531 }
2532 
2533 CONSTCD11
2534 inline
2536 operator-(const year_month_weekday& ymwd, const years& dy) NOEXCEPT
2537 {
2538  return ymwd + (-dy);
2539 }
2540 
2541 // year_month_weekday_last
2542 
2543 CONSTCD11
2544 inline
2546  const julian::month& m,
2547  const julian::weekday_last& wdl) NOEXCEPT
2548  : y_(y)
2549  , m_(m)
2550  , wdl_(wdl)
2551  {}
2552 
2553 CONSTCD14
2554 inline
2557 {
2558  *this = *this + m;
2559  return *this;
2560 }
2561 
2562 CONSTCD14
2563 inline
2566 {
2567  *this = *this - m;
2568  return *this;
2569 }
2570 
2571 CONSTCD14
2572 inline
2575 {
2576  *this = *this + y;
2577  return *this;
2578 }
2579 
2580 CONSTCD14
2581 inline
2584 {
2585  *this = *this - y;
2586  return *this;
2587 }
2588 
2589 CONSTCD11 inline year year_month_weekday_last::year() const NOEXCEPT {return y_;}
2590 CONSTCD11 inline month year_month_weekday_last::month() const NOEXCEPT {return m_;}
2591 
2592 CONSTCD11
2593 inline
2594 weekday
2596 {
2597  return wdl_.weekday();
2598 }
2599 
2600 CONSTCD11
2601 inline
2604 {
2605  return wdl_;
2606 }
2607 
2608 CONSTCD14
2609 inline
2610 year_month_weekday_last::operator sys_days() const NOEXCEPT
2611 {
2612  return sys_days{to_days()};
2613 }
2614 
2615 CONSTCD14
2616 inline
2617 year_month_weekday_last::operator local_days() const NOEXCEPT
2618 {
2619  return local_days{to_days()};
2620 }
2621 
2622 CONSTCD11
2623 inline
2624 bool
2626 {
2627  return y_.ok() && m_.ok() && wdl_.ok();
2628 }
2629 
2630 CONSTCD14
2631 inline
2632 days
2633 year_month_weekday_last::to_days() const NOEXCEPT
2634 {
2635  auto const d = sys_days(y_/m_/last);
2636  return (d - (julian::weekday{d} - wdl_.weekday())).time_since_epoch();
2637 }
2638 
2639 CONSTCD11
2640 inline
2641 bool
2643 {
2644  return x.year() == y.year() && x.month() == y.month() &&
2645  x.weekday_last() == y.weekday_last();
2646 }
2647 
2648 CONSTCD11
2649 inline
2650 bool
2652 {
2653  return !(x == y);
2654 }
2655 
2656 template<class CharT, class Traits>
2657 inline
2658 std::basic_ostream<CharT, Traits>&
2659 operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl)
2660 {
2661  return os << ymwdl.year() << '/' << ymwdl.month() << '/' << ymwdl.weekday_last();
2662 }
2663 
2664 CONSTCD14
2665 inline
2667 operator+(const year_month_weekday_last& ymwdl, const months& dm) NOEXCEPT
2668 {
2669  return (ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last();
2670 }
2671 
2672 CONSTCD14
2673 inline
2675 operator+(const months& dm, const year_month_weekday_last& ymwdl) NOEXCEPT
2676 {
2677  return ymwdl + dm;
2678 }
2679 
2680 CONSTCD14
2681 inline
2683 operator-(const year_month_weekday_last& ymwdl, const months& dm) NOEXCEPT
2684 {
2685  return ymwdl + (-dm);
2686 }
2687 
2688 CONSTCD11
2689 inline
2691 operator+(const year_month_weekday_last& ymwdl, const years& dy) NOEXCEPT
2692 {
2693  return {ymwdl.year()+dy, ymwdl.month(), ymwdl.weekday_last()};
2694 }
2695 
2696 CONSTCD11
2697 inline
2699 operator+(const years& dy, const year_month_weekday_last& ymwdl) NOEXCEPT
2700 {
2701  return ymwdl + dy;
2702 }
2703 
2704 CONSTCD11
2705 inline
2707 operator-(const year_month_weekday_last& ymwdl, const years& dy) NOEXCEPT
2708 {
2709  return ymwdl + (-dy);
2710 }
2711 
2712 // year_month from operator/()
2713 
2714 CONSTCD11
2715 inline
2716 year_month
2717 operator/(const year& y, const month& m) NOEXCEPT
2718 {
2719  return {y, m};
2720 }
2721 
2722 CONSTCD11
2723 inline
2724 year_month
2725 operator/(const year& y, int m) NOEXCEPT
2726 {
2727  return y / month(static_cast<unsigned>(m));
2728 }
2729 
2730 // month_day from operator/()
2731 
2732 CONSTCD11
2733 inline
2734 month_day
2735 operator/(const month& m, const day& d) NOEXCEPT
2736 {
2737  return {m, d};
2738 }
2739 
2740 CONSTCD11
2741 inline
2742 month_day
2743 operator/(const day& d, const month& m) NOEXCEPT
2744 {
2745  return m / d;
2746 }
2747 
2748 CONSTCD11
2749 inline
2750 month_day
2751 operator/(const month& m, int d) NOEXCEPT
2752 {
2753  return m / day(static_cast<unsigned>(d));
2754 }
2755 
2756 CONSTCD11
2757 inline
2758 month_day
2759 operator/(int m, const day& d) NOEXCEPT
2760 {
2761  return month(static_cast<unsigned>(m)) / d;
2762 }
2763 
2764 CONSTCD11 inline month_day operator/(const day& d, int m) NOEXCEPT {return m / d;}
2765 
2766 // month_day_last from operator/()
2767 
2768 CONSTCD11
2769 inline
2771 operator/(const month& m, last_spec) NOEXCEPT
2772 {
2773  return month_day_last{m};
2774 }
2775 
2776 CONSTCD11
2777 inline
2779 operator/(last_spec, const month& m) NOEXCEPT
2780 {
2781  return m/last;
2782 }
2783 
2784 CONSTCD11
2785 inline
2787 operator/(int m, last_spec) NOEXCEPT
2788 {
2789  return month(static_cast<unsigned>(m))/last;
2790 }
2791 
2792 CONSTCD11
2793 inline
2795 operator/(last_spec, int m) NOEXCEPT
2796 {
2797  return m/last;
2798 }
2799 
2800 // month_weekday from operator/()
2801 
2802 CONSTCD11
2803 inline
2805 operator/(const month& m, const weekday_indexed& wdi) NOEXCEPT
2806 {
2807  return {m, wdi};
2808 }
2809 
2810 CONSTCD11
2811 inline
2813 operator/(const weekday_indexed& wdi, const month& m) NOEXCEPT
2814 {
2815  return m / wdi;
2816 }
2817 
2818 CONSTCD11
2819 inline
2821 operator/(int m, const weekday_indexed& wdi) NOEXCEPT
2822 {
2823  return month(static_cast<unsigned>(m)) / wdi;
2824 }
2825 
2826 CONSTCD11
2827 inline
2829 operator/(const weekday_indexed& wdi, int m) NOEXCEPT
2830 {
2831  return m / wdi;
2832 }
2833 
2834 // month_weekday_last from operator/()
2835 
2836 CONSTCD11
2837 inline
2839 operator/(const month& m, const weekday_last& wdl) NOEXCEPT
2840 {
2841  return {m, wdl};
2842 }
2843 
2844 CONSTCD11
2845 inline
2847 operator/(const weekday_last& wdl, const month& m) NOEXCEPT
2848 {
2849  return m / wdl;
2850 }
2851 
2852 CONSTCD11
2853 inline
2855 operator/(int m, const weekday_last& wdl) NOEXCEPT
2856 {
2857  return month(static_cast<unsigned>(m)) / wdl;
2858 }
2859 
2860 CONSTCD11
2861 inline
2863 operator/(const weekday_last& wdl, int m) NOEXCEPT
2864 {
2865  return m / wdl;
2866 }
2867 
2868 // year_month_day from operator/()
2869 
2870 CONSTCD11
2871 inline
2873 operator/(const year_month& ym, const day& d) NOEXCEPT
2874 {
2875  return {ym.year(), ym.month(), d};
2876 }
2877 
2878 CONSTCD11
2879 inline
2881 operator/(const year_month& ym, int d) NOEXCEPT
2882 {
2883  return ym / day(static_cast<unsigned>(d));
2884 }
2885 
2886 CONSTCD11
2887 inline
2889 operator/(const year& y, const month_day& md) NOEXCEPT
2890 {
2891  return y / md.month() / md.day();
2892 }
2893 
2894 CONSTCD11
2895 inline
2897 operator/(int y, const month_day& md) NOEXCEPT
2898 {
2899  return year(y) / md;
2900 }
2901 
2902 CONSTCD11
2903 inline
2905 operator/(const month_day& md, const year& y) NOEXCEPT
2906 {
2907  return y / md;
2908 }
2909 
2910 CONSTCD11
2911 inline
2913 operator/(const month_day& md, int y) NOEXCEPT
2914 {
2915  return year(y) / md;
2916 }
2917 
2918 // year_month_day_last from operator/()
2919 
2920 CONSTCD11
2921 inline
2923 operator/(const year_month& ym, last_spec) NOEXCEPT
2924 {
2925  return {ym.year(), month_day_last{ym.month()}};
2926 }
2927 
2928 CONSTCD11
2929 inline
2931 operator/(const year& y, const month_day_last& mdl) NOEXCEPT
2932 {
2933  return {y, mdl};
2934 }
2935 
2936 CONSTCD11
2937 inline
2939 operator/(int y, const month_day_last& mdl) NOEXCEPT
2940 {
2941  return year(y) / mdl;
2942 }
2943 
2944 CONSTCD11
2945 inline
2947 operator/(const month_day_last& mdl, const year& y) NOEXCEPT
2948 {
2949  return y / mdl;
2950 }
2951 
2952 CONSTCD11
2953 inline
2955 operator/(const month_day_last& mdl, int y) NOEXCEPT
2956 {
2957  return year(y) / mdl;
2958 }
2959 
2960 // year_month_weekday from operator/()
2961 
2962 CONSTCD11
2963 inline
2965 operator/(const year_month& ym, const weekday_indexed& wdi) NOEXCEPT
2966 {
2967  return {ym.year(), ym.month(), wdi};
2968 }
2969 
2970 CONSTCD11
2971 inline
2973 operator/(const year& y, const month_weekday& mwd) NOEXCEPT
2974 {
2975  return {y, mwd.month(), mwd.weekday_indexed()};
2976 }
2977 
2978 CONSTCD11
2979 inline
2981 operator/(int y, const month_weekday& mwd) NOEXCEPT
2982 {
2983  return year(y) / mwd;
2984 }
2985 
2986 CONSTCD11
2987 inline
2989 operator/(const month_weekday& mwd, const year& y) NOEXCEPT
2990 {
2991  return y / mwd;
2992 }
2993 
2994 CONSTCD11
2995 inline
2997 operator/(const month_weekday& mwd, int y) NOEXCEPT
2998 {
2999  return year(y) / mwd;
3000 }
3001 
3002 // year_month_weekday_last from operator/()
3003 
3004 CONSTCD11
3005 inline
3007 operator/(const year_month& ym, const weekday_last& wdl) NOEXCEPT
3008 {
3009  return {ym.year(), ym.month(), wdl};
3010 }
3011 
3012 CONSTCD11
3013 inline
3015 operator/(const year& y, const month_weekday_last& mwdl) NOEXCEPT
3016 {
3017  return {y, mwdl.month(), mwdl.weekday_last()};
3018 }
3019 
3020 CONSTCD11
3021 inline
3023 operator/(int y, const month_weekday_last& mwdl) NOEXCEPT
3024 {
3025  return year(y) / mwdl;
3026 }
3027 
3028 CONSTCD11
3029 inline
3031 operator/(const month_weekday_last& mwdl, const year& y) NOEXCEPT
3032 {
3033  return y / mwdl;
3034 }
3035 
3036 CONSTCD11
3037 inline
3039 operator/(const month_weekday_last& mwdl, int y) NOEXCEPT
3040 {
3041  return year(y) / mwdl;
3042 }
3043 
3044 } // namespace julian
3045 
3046 #endif // JULIAN_H
CONSTCD11 bool operator>(const day &x, const day &y) NOEXCEPT
Definition: julian.h:823
CONSTDATA julian::month jun
Definition: julian.h:1357
CONSTDATA julian::month oct
Definition: julian.h:1361
Definition: julian.h:346
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:1650
CONSTCD14 year_month_weekday_last & operator-=(const months &m) NOEXCEPT
Definition: julian.h:2565
CONSTCD11 month(unsigned m) NOEXCEPT
Definition: julian.h:892
Definition: julian.h:626
CONSTCD11 day operator+(const day &x, const days &y) NOEXCEPT
Definition: julian.h:856
CONSTCD14 month & operator+=(const months &m) NOEXCEPT
Definition: julian.h:901
CONSTCD14 year_month_day & operator+=(const months &m) NOEXCEPT
Definition: julian.h:2120
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:1793
CONSTCD11 unsigned index() const NOEXCEPT
Definition: julian.h:2406
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1485
CONSTCD14 day & operator-=(const days &d) NOEXCEPT
Definition: julian.h:792
std::chrono::duration< int, std::ratio_divide< years::period, std::ratio< 12 > >> months
Definition: julian.h:45
local_time< days > local_days
Definition: date.h:172
CONSTCD11 julian::year year() const NOEXCEPT
Definition: julian.h:2392
CONSTCD11 year_month_day(const julian::year &y, const julian::month &m, const julian::day &d) NOEXCEPT
Definition: julian.h:2086
CONSTCD14 month & operator--() NOEXCEPT
Definition: julian.h:895
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:2625
#define NOEXCEPT
Definition: date.h:124
CONSTCD14 julian::day day() const NOEXCEPT
Definition: julian.h:1947
Definition: julian.h:167
CONSTCD11 julian::year year() const NOEXCEPT
Definition: julian.h:2589
CONSTDATA julian::weekday mon
Definition: julian.h:1366
CONSTCD14 day & operator++() NOEXCEPT
Definition: julian.h:787
CONSTCD14 year_month_weekday_last & operator+=(const months &m) NOEXCEPT
Definition: julian.h:2556
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:917
date::days days
Definition: julian.h:37
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:1723
Definition: julian.h:407
Definition: julian.h:693
CONSTCD11 unsigned index() const NOEXCEPT
Definition: julian.h:1387
CONSTCD11 julian::year year() const NOEXCEPT
Definition: julian.h:2113
CONSTDATA julian::month jan
Definition: julian.h:1352
CONSTDATA julian::month apr
Definition: julian.h:1355
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1439
CONSTCD14 weekday & operator-=(const days &d) NOEXCEPT
Definition: julian.h:1228
CONSTCD14 weekday & operator++() NOEXCEPT
Definition: julian.h:1211
date::local_days local_days
Definition: julian.h:50
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:794
CONSTDATA julian::month sep
Definition: julian.h:1360
CONSTCD11 year_month(const julian::year &y, const julian::month &m) NOEXCEPT
Definition: julian.h:1478
sys_time< days > sys_days
Definition: date.h:163
Definition: julian.h:324
CONSTCD14 year_month_weekday & operator+=(const months &m) NOEXCEPT
Definition: julian.h:2359
CONSTCD14 year_month_day & operator-=(const months &m) NOEXCEPT
Definition: julian.h:2129
CONSTDATA julian::weekday fri
Definition: julian.h:1370
CONSTCD11 julian::year year() const NOEXCEPT
Definition: julian.h:1483
CONSTCD11 weekday(unsigned wd) NOEXCEPT
Definition: julian.h:1195
std::chrono::duration< int, std::ratio_multiply< std::ratio< 7 >, days::period > > weeks
Definition: date.h:150
CONSTCD14 year & operator+=(const years &y) NOEXCEPT
Definition: julian.h:1059
CONSTCD14 day & operator+=(const days &d) NOEXCEPT
Definition: julian.h:791
CONSTCD14 year_month_day_last & operator-=(const months &m) NOEXCEPT
Definition: julian.h:1909
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:2590
CONSTDATA julian::weekday thu
Definition: julian.h:1369
CONSTCD14 year_month_day_last & operator+=(const months &m) NOEXCEPT
Definition: julian.h:1900
CONSTDATA julian::weekday wed
Definition: julian.h:1368
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1392
CONSTCD11 julian::month_day_last month_day_last() const NOEXCEPT
Definition: julian.h:1939
CONSTCD14 year & operator--() NOEXCEPT
Definition: julian.h:1057
date::sys_days sys_days
Definition: julian.h:49
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:2114
CONSTCD11 year_month_day_last(const julian::year &y, const julian::month_day_last &mdl) NOEXCEPT
Definition: julian.h:1891
CONSTCD11 bool is_leap() const NOEXCEPT
Definition: julian.h:1065
CONSTCD11 weekday_indexed(const julian::weekday &wd, unsigned index) NOEXCEPT
Definition: julian.h:1399
std::chrono::duration< int, std::ratio_multiply< std::ratio< 1461, 4 >, days::period > > years
Definition: julian.h:42
Definition: julian.h:283
CONSTCD11 julian::weekday_last weekday_last() const NOEXCEPT
Definition: julian.h:1850
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1858
CONSTCD11 weekday_last(const julian::weekday &wd) NOEXCEPT
Definition: julian.h:1440
Definition: julian.h:32
CONSTCD14 year_month_weekday & operator-=(const months &m) NOEXCEPT
Definition: julian.h:2368
CONSTDATA julian::month may
Definition: julian.h:1356
std::chrono::duration< int, std::ratio_multiply< std::ratio< 24 >, std::chrono::hours::period > > days
Definition: date.h:147
CONSTCD14 day & operator--() NOEXCEPT
Definition: julian.h:789
Definition: julian.h:458
CONSTCD14 year_month & operator-=(const months &dm) NOEXCEPT
Definition: julian.h:1499
Definition: julian.h:204
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:1484
CONSTDATA julian::last_spec last
Definition: julian.h:1350
#define CONSTDATA
Definition: date.h:121
CONSTCD11 day operator-(const day &x, const days &y) NOEXCEPT
Definition: julian.h:872
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1806
CONSTCD14 month & operator++() NOEXCEPT
Definition: julian.h:893
CONSTCD11 year_month operator/(const year &y, const month &m) NOEXCEPT
Definition: julian.h:2717
static CONSTCD11 year max() NOEXCEPT
Definition: julian.h:1084
CONSTCD11 julian::weekday weekday() const NOEXCEPT
Definition: julian.h:1382
CONSTCD11 bool operator<(const day &x, const day &y) NOEXCEPT
Definition: julian.h:815
CONSTCD11 bool operator==(const day &x, const day &y) NOEXCEPT
Definition: julian.h:799
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:1934
Definition: julian.h:366
CONSTCD11 julian::weekday weekday() const NOEXCEPT
Definition: julian.h:2398
CONSTCD11 bool operator<=(const day &x, const day &y) NOEXCEPT
Definition: julian.h:831
CONSTCD14 bool ok() const NOEXCEPT
Definition: julian.h:2436
static CONSTCD11 year min() NOEXCEPT
Definition: julian.h:1076
CONSTCD11 julian::year year() const NOEXCEPT
Definition: julian.h:1933
last_spec()=default
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:2393
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1971
Definition: julian.h:241
#define CONSTCD14
Definition: date.h:123
CONSTDATA julian::month jul
Definition: julian.h:1358
auto operator+=(std::string &lhs, StringRef const &sr) -> std::string &
CONSTCD11 julian::day day() const NOEXCEPT
Definition: julian.h:1651
CONSTCD11 julian::weekday weekday() const NOEXCEPT
Definition: julian.h:2595
CONSTDATA julian::month nov
Definition: julian.h:1362
CONSTDATA julian::month aug
Definition: julian.h:1359
CONSTCD11 month_day(const julian::month &m, const julian::day &d) NOEXCEPT
Definition: julian.h:1645
CONSTCD14 bool ok() const NOEXCEPT
Definition: julian.h:2189
CONSTDATA julian::weekday sat
Definition: julian.h:1371
Definition: julian.h:507
Definition: julian.h:54
Definition: julian.h:559
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1241
Definition: julian.h:434
CONSTCD11 year_month_weekday_last(const julian::year &y, const julian::month &m, const julian::weekday_last &wdl) NOEXCEPT
Definition: julian.h:2545
CONSTCD11 julian::day day() const NOEXCEPT
Definition: julian.h:2115
CONSTCD14 year & operator-=(const years &y) NOEXCEPT
Definition: julian.h:1060
CONSTDATA julian::month dec
Definition: julian.h:1363
CONSTCD14 year_month & operator+=(const months &dm) NOEXCEPT
Definition: julian.h:1490
CONSTCD11 bool operator>=(const day &x, const day &y) NOEXCEPT
Definition: julian.h:839
CONSTCD11 bool operator!=(const day &x, const day &y) NOEXCEPT
Definition: julian.h:807
CONSTDATA julian::month mar
Definition: julian.h:1354
CONSTCD14 year & operator++() NOEXCEPT
Definition: julian.h:1055
Definition: date.h:945
CONSTCD11 month_day_last(const julian::month &m) NOEXCEPT
Definition: julian.h:1725
CONSTCD11 julian::weekday_indexed weekday_indexed() const NOEXCEPT
Definition: julian.h:1798
Definition: julian.h:481
CONSTCD11 year(int y) NOEXCEPT
Definition: julian.h:1054
CONSTCD11 julian::weekday_indexed weekday_indexed() const NOEXCEPT
Definition: julian.h:2414
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1724
CONSTCD14 weekday & operator+=(const days &d) NOEXCEPT
Definition: julian.h:1219
CONSTCD14 month & operator-=(const months &m) NOEXCEPT
Definition: julian.h:910
date::weeks weeks
Definition: julian.h:39
CONSTCD11 julian::weekday_last weekday_last() const NOEXCEPT
Definition: julian.h:2603
CONSTCD11 bool ok() const NOEXCEPT
Definition: julian.h:1071
CONSTCD14 weekday & operator--() NOEXCEPT
Definition: julian.h:1213
CONSTCD11 weekday_indexed operator[](unsigned index) const NOEXCEPT
Definition: julian.h:1415
CONSTCD11 julian::month month() const NOEXCEPT
Definition: julian.h:1845
CONSTCD11 month_weekday(const julian::month &m, const julian::weekday_indexed &wdi) NOEXCEPT
Definition: julian.h:1787
CONSTCD11 day(unsigned d) NOEXCEPT
Definition: julian.h:786
CONSTDATA julian::month feb
Definition: julian.h:1353
CONSTDATA julian::weekday sun
Definition: julian.h:1365
CONSTCD14 bool ok() const NOEXCEPT
Definition: julian.h:1656
CONSTDATA julian::weekday tue
Definition: julian.h:1367
CONSTCD11 month_weekday_last(const julian::month &m, const julian::weekday_last &wd) NOEXCEPT
Definition: julian.h:1839
CONSTCD11 julian::weekday weekday() const NOEXCEPT
Definition: julian.h:1438
CONSTCD11 year_month_weekday(const julian::year &y, const julian::month &m, const julian::weekday_indexed &wdi) NOEXCEPT
Definition: julian.h:2336
#define CONSTCD11
Definition: date.h:122