NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
solar_hijri.h
Go to the documentation of this file.
1#ifndef SOLAR_HIJRI_H
2#define SOLAR_HIJRI_H
3
4// The MIT License (MIT)
5//
6// Copyright (c) 2016 Howard Hinnant
7// Copyright (c) 2019 Asad. Gharighi
8//
9// Calculations are based on:
10// https://www.timeanddate.com/calendar/persian-calendar.html
11// and follow <date.h> style
12//
13// Permission is hereby granted, free of charge, to any person obtaining a copy
14// of this software and associated documentation files (the "Software"), to deal
15// in the Software without restriction, including without limitation the rights
16// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17// copies of the Software, and to permit persons to whom the Software is
18// furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included in all
21// copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29// SOFTWARE.
30//
31// Our apologies. When the previous paragraph was written, lowercase had not yet
32// been invented (that would involve another several millennia of evolution).
33// We did not mean to shout.
34
35#include "date.h"
36
37namespace solar_hijri
38{
39
40namespace internal
41{
42static const auto epoch = static_cast<unsigned>(2121446);
43static const auto days_in_era = static_cast<unsigned>(1029983);
44static const auto years_in_era = static_cast<unsigned>(2820);
45static const auto unix_time_shift = static_cast<unsigned>(2440588);
46auto const years_in_first_cycle = static_cast<unsigned>(29);
47auto const years_in_other_cycles = static_cast<int>(33);
48auto const years_in_period = static_cast<int>(128); // 29 + 3*33
49auto const days_in_first_cycle = static_cast<unsigned>(10592); // 28/4 + 29*365
50auto const days_in_other_cycles = static_cast<unsigned>(12053); // 32/4 + 33*365
51auto const days_in_period = static_cast<unsigned>(46751); // days_in_first_cycle + 3*days_in_other_cycles;
52}
53
54// durations
55
57
59
60using years = std::chrono::duration
62
63using months = std::chrono::duration
65
66// time_point
67
70
71// types
72
74{
75 explicit last_spec() = default;
76};
77
78class day;
79class month;
80class year;
81
82class weekday;
83class weekday_indexed;
84class weekday_last;
85
86class month_day;
87class month_day_last;
88class month_weekday;
90
91class year_month;
92
93class year_month_day;
97
98// date composition operators
99
100CONSTCD11 year_month operator/(const year& y, const month& m) NOEXCEPT;
102
103CONSTCD11 month_day operator/(const day& d, const month& m) NOEXCEPT;
104CONSTCD11 month_day operator/(const day& d, int m) NOEXCEPT;
105CONSTCD11 month_day operator/(const month& m, const day& d) NOEXCEPT;
107CONSTCD11 month_day operator/(int m, const day& d) NOEXCEPT;
108
113
118
123
130
141
144operator/(const year_month& ym, const weekday_indexed& wdi) NOEXCEPT;
145
148operator/(const year& y, const month_weekday& mwd) NOEXCEPT;
149
152operator/(int y, const month_weekday& mwd) NOEXCEPT;
153
156operator/(const month_weekday& mwd, const year& y) NOEXCEPT;
157
160operator/(const month_weekday& mwd, int y) NOEXCEPT;
161
164operator/(const year_month& ym, const weekday_last& wdl) NOEXCEPT;
165
168operator/(const year& y, const month_weekday_last& mwdl) NOEXCEPT;
169
172operator/(int y, const month_weekday_last& mwdl) NOEXCEPT;
173
176operator/(const month_weekday_last& mwdl, const year& y) NOEXCEPT;
177
180operator/(const month_weekday_last& mwdl, int y) NOEXCEPT;
181
182// Detailed interface
183
184// day
185
186class day
187{
188 unsigned char d_;
189
190public:
191 day() = default;
192 explicit CONSTCD11 day(unsigned d) NOEXCEPT;
193
195 CONSTCD14 day operator++(int) NOEXCEPT;
196 CONSTCD14 day& operator--() NOEXCEPT;
197 CONSTCD14 day operator--(int) NOEXCEPT;
198
199 CONSTCD14 day& operator+=(const days& d) NOEXCEPT;
200 CONSTCD14 day& operator-=(const days& d) NOEXCEPT;
201
202 CONSTCD11 explicit operator unsigned() const NOEXCEPT;
203 CONSTCD11 bool ok() const NOEXCEPT;
204};
205
206CONSTCD11 bool operator==(const day& x, const day& y) NOEXCEPT;
207CONSTCD11 bool operator!=(const day& x, const day& y) NOEXCEPT;
208CONSTCD11 bool operator< (const day& x, const day& y) NOEXCEPT;
209CONSTCD11 bool operator> (const day& x, const day& y) NOEXCEPT;
210CONSTCD11 bool operator<=(const day& x, const day& y) NOEXCEPT;
211CONSTCD11 bool operator>=(const day& x, const day& y) NOEXCEPT;
212
213CONSTCD11 day operator+(const day& x, const days& y) NOEXCEPT;
214CONSTCD11 day operator+(const days& x, const day& y) NOEXCEPT;
215CONSTCD11 day operator-(const day& x, const days& y) NOEXCEPT;
216CONSTCD11 days operator-(const day& x, const day& y) NOEXCEPT;
217
218template<class CharT, class Traits>
219std::basic_ostream<CharT, Traits>&
220operator<<(std::basic_ostream<CharT, Traits>& os, const day& d);
221
222// month
223
224class month
225{
226 unsigned char m_;
227
228public:
229 month() = default;
230 explicit CONSTCD11 month(unsigned m) NOEXCEPT;
231
233 CONSTCD14 month operator++(int) NOEXCEPT;
234 CONSTCD14 month& operator--() NOEXCEPT;
235 CONSTCD14 month operator--(int) NOEXCEPT;
236
237 CONSTCD14 month& operator+=(const months& m) NOEXCEPT;
238 CONSTCD14 month& operator-=(const months& m) NOEXCEPT;
239
240 CONSTCD11 explicit operator unsigned() const NOEXCEPT;
241 CONSTCD11 bool ok() const NOEXCEPT;
242};
243
244CONSTCD11 bool operator==(const month& x, const month& y) NOEXCEPT;
245CONSTCD11 bool operator!=(const month& x, const month& y) NOEXCEPT;
246CONSTCD11 bool operator< (const month& x, const month& y) NOEXCEPT;
247CONSTCD11 bool operator> (const month& x, const month& y) NOEXCEPT;
248CONSTCD11 bool operator<=(const month& x, const month& y) NOEXCEPT;
249CONSTCD11 bool operator>=(const month& x, const month& y) NOEXCEPT;
250
251CONSTCD14 month operator+(const month& x, const months& y) NOEXCEPT;
252CONSTCD14 month operator+(const months& x, const month& y) NOEXCEPT;
253CONSTCD14 month operator-(const month& x, const months& y) NOEXCEPT;
254CONSTCD14 months operator-(const month& x, const month& y) NOEXCEPT;
255
256template<class CharT, class Traits>
257std::basic_ostream<CharT, Traits>&
258operator<<(std::basic_ostream<CharT, Traits>& os, const month& m);
259
260// year
261
262class year
263{
264 short y_;
265
266public:
267 year() = default;
268 explicit CONSTCD11 year(int y) NOEXCEPT;
269
271 CONSTCD14 year operator++(int) NOEXCEPT;
272 CONSTCD14 year& operator--() NOEXCEPT;
273 CONSTCD14 year operator--(int) NOEXCEPT;
274
275 CONSTCD14 year& operator+=(const years& y) NOEXCEPT;
276 CONSTCD14 year& operator-=(const years& y) NOEXCEPT;
277
278 CONSTCD14 bool is_leap() const NOEXCEPT;
279
280 CONSTCD11 explicit operator int() const NOEXCEPT;
281 CONSTCD11 bool ok() const NOEXCEPT;
282
283 static CONSTCD11 year min() NOEXCEPT;
284 static CONSTCD11 year max() NOEXCEPT;
285};
286
287CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
288CONSTCD11 bool operator!=(const year& x, const year& y) NOEXCEPT;
289CONSTCD11 bool operator< (const year& x, const year& y) NOEXCEPT;
290CONSTCD11 bool operator> (const year& x, const year& y) NOEXCEPT;
291CONSTCD11 bool operator<=(const year& x, const year& y) NOEXCEPT;
292CONSTCD11 bool operator>=(const year& x, const year& y) NOEXCEPT;
293
294CONSTCD11 year operator+(const year& x, const years& y) NOEXCEPT;
295CONSTCD11 year operator+(const years& x, const year& y) NOEXCEPT;
296CONSTCD11 year operator-(const year& x, const years& y) NOEXCEPT;
297CONSTCD11 years operator-(const year& x, const year& y) NOEXCEPT;
298
299template<class CharT, class Traits>
300std::basic_ostream<CharT, Traits>&
301operator<<(std::basic_ostream<CharT, Traits>& os, const year& y);
302
303// weekday
304
306{
307 unsigned char wd_;
308public:
309 weekday() = default;
310 explicit CONSTCD11 weekday(unsigned wd) NOEXCEPT;
311 explicit weekday(int) = delete;
313 CONSTCD11 explicit weekday(const local_days& dp) NOEXCEPT;
314
316 CONSTCD14 weekday operator++(int) NOEXCEPT;
317 CONSTCD14 weekday& operator--() NOEXCEPT;
318 CONSTCD14 weekday operator--(int) NOEXCEPT;
319
320 CONSTCD14 weekday& operator+=(const days& d) NOEXCEPT;
321 CONSTCD14 weekday& operator-=(const days& d) NOEXCEPT;
322
323 CONSTCD11 explicit operator unsigned() const NOEXCEPT;
324 CONSTCD11 bool ok() const NOEXCEPT;
325
326 CONSTCD11 weekday_indexed operator[](unsigned index) const NOEXCEPT;
327 CONSTCD11 weekday_last operator[](last_spec) const NOEXCEPT;
328
329private:
330 static CONSTCD11 unsigned char weekday_from_days(int z) NOEXCEPT;
331};
332
333CONSTCD11 bool operator==(const weekday& x, const weekday& y) NOEXCEPT;
334CONSTCD11 bool operator!=(const weekday& x, const weekday& y) NOEXCEPT;
335
336CONSTCD14 weekday operator+(const weekday& x, const days& y) NOEXCEPT;
337CONSTCD14 weekday operator+(const days& x, const weekday& y) NOEXCEPT;
338CONSTCD14 weekday operator-(const weekday& x, const days& y) NOEXCEPT;
339CONSTCD14 days operator-(const weekday& x, const weekday& y) NOEXCEPT;
340
341template<class CharT, class Traits>
342std::basic_ostream<CharT, Traits>&
343operator<<(std::basic_ostream<CharT, Traits>& os, const weekday& wd);
344
345// weekday_indexed
346
348{
349 unsigned char wd_ : 4;
350 unsigned char index_ : 4;
351
352public:
353 weekday_indexed() = default;
354 CONSTCD11 weekday_indexed(const solar_hijri::weekday& wd, unsigned index) NOEXCEPT;
355
357 CONSTCD11 unsigned index() const NOEXCEPT;
358 CONSTCD11 bool ok() const NOEXCEPT;
359};
360
361CONSTCD11 bool operator==(const weekday_indexed& x, const weekday_indexed& y) NOEXCEPT;
362CONSTCD11 bool operator!=(const weekday_indexed& x, const weekday_indexed& y) NOEXCEPT;
363
364template<class CharT, class Traits>
365std::basic_ostream<CharT, Traits>&
366operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_indexed& wdi);
367
368// weekday_last
369
371{
373
374public:
375 weekday_last() = default;
377
379 CONSTCD11 bool ok() const NOEXCEPT;
380};
381
382CONSTCD11 bool operator==(const weekday_last& x, const weekday_last& y) NOEXCEPT;
383CONSTCD11 bool operator!=(const weekday_last& x, const weekday_last& y) NOEXCEPT;
384
385template<class CharT, class Traits>
386std::basic_ostream<CharT, Traits>&
387operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_last& wdl);
388
389// year_month
390
392{
395
396public:
397 year_month() = default;
399
402
403 CONSTCD14 year_month& operator+=(const months& dm) NOEXCEPT;
404 CONSTCD14 year_month& operator-=(const months& dm) NOEXCEPT;
405 CONSTCD14 year_month& operator+=(const years& dy) NOEXCEPT;
406 CONSTCD14 year_month& operator-=(const years& dy) NOEXCEPT;
407
408 CONSTCD11 bool ok() const NOEXCEPT;
409};
410
411CONSTCD11 bool operator==(const year_month& x, const year_month& y) NOEXCEPT;
412CONSTCD11 bool operator!=(const year_month& x, const year_month& y) NOEXCEPT;
413CONSTCD11 bool operator< (const year_month& x, const year_month& y) NOEXCEPT;
414CONSTCD11 bool operator> (const year_month& x, const year_month& y) NOEXCEPT;
415CONSTCD11 bool operator<=(const year_month& x, const year_month& y) NOEXCEPT;
416CONSTCD11 bool operator>=(const year_month& x, const year_month& y) NOEXCEPT;
417
418CONSTCD14 year_month operator+(const year_month& ym, const months& dm) NOEXCEPT;
419CONSTCD14 year_month operator+(const months& dm, const year_month& ym) NOEXCEPT;
420CONSTCD14 year_month operator-(const year_month& ym, const months& dm) NOEXCEPT;
421
422CONSTCD11 months operator-(const year_month& x, const year_month& y) NOEXCEPT;
423CONSTCD11 year_month operator+(const year_month& ym, const years& dy) NOEXCEPT;
424CONSTCD11 year_month operator+(const years& dy, const year_month& ym) NOEXCEPT;
425CONSTCD11 year_month operator-(const year_month& ym, const years& dy) NOEXCEPT;
426
427template<class CharT, class Traits>
428std::basic_ostream<CharT, Traits>&
429operator<<(std::basic_ostream<CharT, Traits>& os, const year_month& ym);
430
431// month_day
432
434{
437
438public:
439 month_day() = default;
441
444
445 CONSTCD14 bool ok() const NOEXCEPT;
446};
447
448CONSTCD11 bool operator==(const month_day& x, const month_day& y) NOEXCEPT;
449CONSTCD11 bool operator!=(const month_day& x, const month_day& y) NOEXCEPT;
450CONSTCD11 bool operator< (const month_day& x, const month_day& y) NOEXCEPT;
451CONSTCD11 bool operator> (const month_day& x, const month_day& y) NOEXCEPT;
452CONSTCD11 bool operator<=(const month_day& x, const month_day& y) NOEXCEPT;
453CONSTCD11 bool operator>=(const month_day& x, const month_day& y) NOEXCEPT;
454
455template<class CharT, class Traits>
456std::basic_ostream<CharT, Traits>&
457operator<<(std::basic_ostream<CharT, Traits>& os, const month_day& md);
458
459// month_day_last
460
462{
464
465public:
466 month_day_last() = default;
468
470 CONSTCD11 bool ok() const NOEXCEPT;
471};
472
473CONSTCD11 bool operator==(const month_day_last& x, const month_day_last& y) NOEXCEPT;
474CONSTCD11 bool operator!=(const month_day_last& x, const month_day_last& y) NOEXCEPT;
475CONSTCD11 bool operator< (const month_day_last& x, const month_day_last& y) NOEXCEPT;
476CONSTCD11 bool operator> (const month_day_last& x, const month_day_last& y) NOEXCEPT;
477CONSTCD11 bool operator<=(const month_day_last& x, const month_day_last& y) NOEXCEPT;
478CONSTCD11 bool operator>=(const month_day_last& x, const month_day_last& y) NOEXCEPT;
479
480template<class CharT, class Traits>
481std::basic_ostream<CharT, Traits>&
482operator<<(std::basic_ostream<CharT, Traits>& os, const month_day_last& mdl);
483
484// month_weekday
485
487{
490public:
491 month_weekday() = default;
494
497
498 CONSTCD11 bool ok() const NOEXCEPT;
499};
500
501CONSTCD11 bool operator==(const month_weekday& x, const month_weekday& y) NOEXCEPT;
502CONSTCD11 bool operator!=(const month_weekday& x, const month_weekday& y) NOEXCEPT;
503
504template<class CharT, class Traits>
505std::basic_ostream<CharT, Traits>&
506operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday& mwd);
507
508// month_weekday_last
509
511{
514
515public:
519
522
523 CONSTCD11 bool ok() const NOEXCEPT;
524};
525
527 bool operator==(const month_weekday_last& x, const month_weekday_last& y) NOEXCEPT;
529 bool operator!=(const month_weekday_last& x, const month_weekday_last& y) NOEXCEPT;
530
531template<class CharT, class Traits>
532std::basic_ostream<CharT, Traits>&
533operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday_last& mwdl);
534
535// class year_month_day
536
538{
542
543public:
544 year_month_day() = default;
546 const solar_hijri::day& d) NOEXCEPT;
548
551
556
560
561 CONSTCD14 operator sys_days() const NOEXCEPT;
562 CONSTCD14 explicit operator local_days() const NOEXCEPT;
563 CONSTCD14 bool ok() const NOEXCEPT;
564
565private:
566 static CONSTCD14 year_month_day from_days(days dp) NOEXCEPT;
567 CONSTCD14 days to_days() const NOEXCEPT;
568};
569
570CONSTCD11 bool operator==(const year_month_day& x, const year_month_day& y) NOEXCEPT;
571CONSTCD11 bool operator!=(const year_month_day& x, const year_month_day& y) NOEXCEPT;
572CONSTCD11 bool operator< (const year_month_day& x, const year_month_day& y) NOEXCEPT;
573CONSTCD11 bool operator> (const year_month_day& x, const year_month_day& y) NOEXCEPT;
574CONSTCD11 bool operator<=(const year_month_day& x, const year_month_day& y) NOEXCEPT;
575CONSTCD11 bool operator>=(const year_month_day& x, const year_month_day& y) NOEXCEPT;
576
577CONSTCD14 year_month_day operator+(const year_month_day& ymd, const months& dm) NOEXCEPT;
578CONSTCD14 year_month_day operator+(const months& dm, const year_month_day& ymd) NOEXCEPT;
579CONSTCD14 year_month_day operator-(const year_month_day& ymd, const months& dm) NOEXCEPT;
580CONSTCD11 year_month_day operator+(const year_month_day& ymd, const years& dy) NOEXCEPT;
581CONSTCD11 year_month_day operator+(const years& dy, const year_month_day& ymd) NOEXCEPT;
582CONSTCD11 year_month_day operator-(const year_month_day& ymd, const years& dy) NOEXCEPT;
583
584template<class CharT, class Traits>
585std::basic_ostream<CharT, Traits>&
586operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day& ymd);
587
588// year_month_day_last
589
591{
594
595public:
599
604
609
610 CONSTCD14 operator sys_days() const NOEXCEPT;
611 CONSTCD14 explicit operator local_days() const NOEXCEPT;
612 CONSTCD11 bool ok() const NOEXCEPT;
613};
614
616 bool operator==(const year_month_day_last& x, const year_month_day_last& y) NOEXCEPT;
618 bool operator!=(const year_month_day_last& x, const year_month_day_last& y) NOEXCEPT;
620 bool operator< (const year_month_day_last& x, const year_month_day_last& y) NOEXCEPT;
622 bool operator> (const year_month_day_last& x, const year_month_day_last& y) NOEXCEPT;
624 bool operator<=(const year_month_day_last& x, const year_month_day_last& y) NOEXCEPT;
626 bool operator>=(const year_month_day_last& x, const year_month_day_last& y) NOEXCEPT;
627
630operator+(const year_month_day_last& ymdl, const months& dm) NOEXCEPT;
631
634operator+(const months& dm, const year_month_day_last& ymdl) NOEXCEPT;
635
638operator+(const year_month_day_last& ymdl, const years& dy) NOEXCEPT;
639
642operator+(const years& dy, const year_month_day_last& ymdl) NOEXCEPT;
643
646operator-(const year_month_day_last& ymdl, const months& dm) NOEXCEPT;
647
650operator-(const year_month_day_last& ymdl, const years& dy) NOEXCEPT;
651
652template<class CharT, class Traits>
653std::basic_ostream<CharT, Traits>&
654operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day_last& ymdl);
655
656// year_month_weekday
657
659{
663
664public:
670
675
679 CONSTCD11 unsigned index() const NOEXCEPT;
681
682 CONSTCD14 operator sys_days() const NOEXCEPT;
683 CONSTCD14 explicit operator local_days() const NOEXCEPT;
684 CONSTCD14 bool ok() const NOEXCEPT;
685
686private:
687 static CONSTCD14 year_month_weekday from_days(days dp) NOEXCEPT;
688 CONSTCD14 days to_days() const NOEXCEPT;
689};
690
692 bool operator==(const year_month_weekday& x, const year_month_weekday& y) NOEXCEPT;
694 bool operator!=(const year_month_weekday& x, const year_month_weekday& y) NOEXCEPT;
695
698operator+(const year_month_weekday& ymwd, const months& dm) NOEXCEPT;
699
702operator+(const months& dm, const year_month_weekday& ymwd) NOEXCEPT;
703
706operator+(const year_month_weekday& ymwd, const years& dy) NOEXCEPT;
707
710operator+(const years& dy, const year_month_weekday& ymwd) NOEXCEPT;
711
714operator-(const year_month_weekday& ymwd, const months& dm) NOEXCEPT;
715
718operator-(const year_month_weekday& ymwd, const years& dy) NOEXCEPT;
719
720template<class CharT, class Traits>
721std::basic_ostream<CharT, Traits>&
722operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwdi);
723
724// year_month_weekday_last
725
727{
731
732public:
736
741
746
747 CONSTCD14 operator sys_days() const NOEXCEPT;
748 CONSTCD14 explicit operator local_days() const NOEXCEPT;
749 CONSTCD11 bool ok() const NOEXCEPT;
750
751private:
752 CONSTCD14 days to_days() const NOEXCEPT;
753};
754
756bool
757operator==(const year_month_weekday_last& x, const year_month_weekday_last& y) NOEXCEPT;
758
760bool
761operator!=(const year_month_weekday_last& x, const year_month_weekday_last& y) NOEXCEPT;
762
765operator+(const year_month_weekday_last& ymwdl, const months& dm) NOEXCEPT;
766
769operator+(const months& dm, const year_month_weekday_last& ymwdl) NOEXCEPT;
770
773operator+(const year_month_weekday_last& ymwdl, const years& dy) NOEXCEPT;
774
777operator+(const years& dy, const year_month_weekday_last& ymwdl) NOEXCEPT;
778
781operator-(const year_month_weekday_last& ymwdl, const months& dm) NOEXCEPT;
782
785operator-(const year_month_weekday_last& ymwdl, const years& dy) NOEXCEPT;
786
787template<class CharT, class Traits>
788std::basic_ostream<CharT, Traits>&
789operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl);
790
791#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
792inline namespace literals
793{
794
795CONSTCD11 solar_hijri::day operator "" _d(unsigned long long d) NOEXCEPT;
796CONSTCD11 solar_hijri::year operator "" _y(unsigned long long y) NOEXCEPT;
797
798} // inline namespace literals
799#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
800
801//----------------+
802// Implementation |
803//----------------+
804
805// day
806
807CONSTCD11 inline day::day(unsigned d) NOEXCEPT : d_(static_cast<unsigned char>(d)) {}
808CONSTCD14 inline day& day::operator++() NOEXCEPT {++d_; return *this;}
809CONSTCD14 inline day day::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
810CONSTCD14 inline day& day::operator--() NOEXCEPT {--d_; return *this;}
811CONSTCD14 inline day day::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
812CONSTCD14 inline day& day::operator+=(const days& d) NOEXCEPT {*this = *this + d; return *this;}
813CONSTCD14 inline day& day::operator-=(const days& d) NOEXCEPT {*this = *this - d; return *this;}
814CONSTCD11 inline day::operator unsigned() const NOEXCEPT {return d_;}
815CONSTCD11 inline bool day::ok() const NOEXCEPT {return 1 <= d_ && d_ <= 30;}
816
818inline
819bool
820operator==(const day& x, const day& y) NOEXCEPT
821{
822 return static_cast<unsigned>(x) == static_cast<unsigned>(y);
823}
824
826inline
827bool
828operator!=(const day& x, const day& y) NOEXCEPT
829{
830 return !(x == y);
831}
832
834inline
835bool
836operator<(const day& x, const day& y) NOEXCEPT
837{
838 return static_cast<unsigned>(x) < static_cast<unsigned>(y);
839}
840
842inline
843bool
844operator>(const day& x, const day& y) NOEXCEPT
845{
846 return y < x;
847}
848
850inline
851bool
852operator<=(const day& x, const day& y) NOEXCEPT
853{
854 return !(y < x);
855}
856
858inline
859bool
860operator>=(const day& x, const day& y) NOEXCEPT
861{
862 return !(x < y);
863}
864
866inline
867days
868operator-(const day& x, const day& y) NOEXCEPT
869{
870 return days{static_cast<days::rep>(static_cast<unsigned>(x)
871 - static_cast<unsigned>(y))};
872}
873
875inline
876day
877operator+(const day& x, const days& y) NOEXCEPT
878{
879 return day{static_cast<unsigned>(x) + static_cast<unsigned>(y.count())};
880}
881
883inline
884day
885operator+(const days& x, const day& y) NOEXCEPT
886{
887 return y + x;
888}
889
891inline
892day
893operator-(const day& x, const days& y) NOEXCEPT
894{
895 return x + -y;
896}
897
898template<class CharT, class Traits>
899inline
900std::basic_ostream<CharT, Traits>&
901operator<<(std::basic_ostream<CharT, Traits>& os, const day& d)
902{
904 os.fill('0');
905 os.flags(std::ios::dec | std::ios::right);
906 os.width(2);
907 os << static_cast<unsigned>(d);
908 return os;
909}
910
911// month
912
913CONSTCD11 inline month::month(unsigned m) NOEXCEPT : m_(static_cast<decltype(m_)>(m)) {}
914CONSTCD14 inline month& month::operator++() NOEXCEPT {if (++m_ == 13) m_ = 1; return *this;}
915CONSTCD14 inline month month::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
916CONSTCD14 inline month& month::operator--() NOEXCEPT {if (--m_ == 0) m_ = 12; return *this;}
917CONSTCD14 inline month month::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
918
920inline
921month&
923{
924 *this = *this + m;
925 return *this;
926}
927
929inline
930month&
932{
933 *this = *this - m;
934 return *this;
935}
936
937CONSTCD11 inline month::operator unsigned() const NOEXCEPT {return m_;}
938CONSTCD11 inline bool month::ok() const NOEXCEPT {return 1 <= m_ && m_ <= 12;}
939
941inline
942bool
943operator==(const month& x, const month& y) NOEXCEPT
944{
945 return static_cast<unsigned>(x) == static_cast<unsigned>(y);
946}
947
949inline
950bool
951operator!=(const month& x, const month& y) NOEXCEPT
952{
953 return !(x == y);
954}
955
957inline
958bool
959operator<(const month& x, const month& y) NOEXCEPT
960{
961 return static_cast<unsigned>(x) < static_cast<unsigned>(y);
962}
963
965inline
966bool
967operator>(const month& x, const month& y) NOEXCEPT
968{
969 return y < x;
970}
971
973inline
974bool
975operator<=(const month& x, const month& y) NOEXCEPT
976{
977 return !(y < x);
978}
979
981inline
982bool
983operator>=(const month& x, const month& y) NOEXCEPT
984{
985 return !(x < y);
986}
987
989inline
990months
991operator-(const month& x, const month& y) NOEXCEPT
992{
993 auto const d = static_cast<unsigned>(x) - static_cast<unsigned>(y);
994 return months(d <= 11 ? d : d + 12);
995}
996
998inline
999month
1000operator+(const month& x, const months& y) NOEXCEPT
1001{
1002 auto const mu = static_cast<long long>(static_cast<unsigned>(x)) - 1 + y.count();
1003 auto const yr = (mu >= 0 ? mu : mu-11) / 12;
1004 return month{static_cast<unsigned>(mu - yr * 12 + 1)};
1005}
1006
1008inline
1009month
1010operator+(const months& x, const month& y) NOEXCEPT
1011{
1012 return y + x;
1013}
1014
1016inline
1017month
1018operator-(const month& x, const months& y) NOEXCEPT
1019{
1020 return x + -y;
1021}
1022
1023template<class CharT, class Traits>
1024inline
1025std::basic_ostream<CharT, Traits>&
1026operator<<(std::basic_ostream<CharT, Traits>& os, const month& m)
1027{
1028 switch (static_cast<unsigned>(m))
1029 {
1030 case 1:
1031 os << "Farvardin";
1032 break;
1033 case 2:
1034 os << "Ordibehesht";
1035 break;
1036 case 3:
1037 os << "Khordad";
1038 break;
1039 case 4:
1040 os << "Tir";
1041 break;
1042 case 5:
1043 os << "Mordad";
1044 break;
1045 case 6:
1046 os << "Shahrivar";
1047 break;
1048 case 7:
1049 os << "Mehr";
1050 break;
1051 case 8:
1052 os << "Aban";
1053 break;
1054 case 9:
1055 os << "Azar";
1056 break;
1057 case 10:
1058 os << "Dey";
1059 break;
1060 case 11:
1061 os << "Bahman";
1062 break;
1063 case 12:
1064 os << "Esfand";
1065 break;
1066 default:
1067 os << static_cast<unsigned>(m) << " is not a valid month";
1068 break;
1069 }
1070 return os;
1071}
1072
1073// year
1074
1075CONSTCD11 inline year::year(int y) NOEXCEPT : y_(static_cast<decltype(y_)>(y)) {}
1076CONSTCD14 inline year& year::operator++() NOEXCEPT {++y_; return *this;}
1077CONSTCD14 inline year year::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
1078CONSTCD14 inline year& year::operator--() NOEXCEPT {--y_; return *this;}
1079CONSTCD14 inline year year::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
1080CONSTCD14 inline year& year::operator+=(const years& y) NOEXCEPT {*this = *this + y; return *this;}
1081CONSTCD14 inline year& year::operator-=(const years& y) NOEXCEPT {*this = *this - y; return *this;}
1082
1084inline
1085bool
1087{
1088 using namespace internal;
1089 auto const y = static_cast<int>(y_)-475;
1090 auto const era_d = static_cast<int>(y >= 0 ? y : y-years_in_era+1) / static_cast<double>(years_in_era);
1091 auto const era = static_cast<int>(era_d);
1092 auto const yoe = static_cast<unsigned>(y - era * years_in_era);
1093
1094 // Reference: https://www.timeanddate.com/date/iran-leap-year.html
1095 // 29 + 33 + 33 + 33 = 128
1096 // 22 * 128 + 4
1097 auto const yoc = (yoe < (22 * 128)) ? ((yoe%128) < 29 ? yoe%128 : (yoe%128 - 29)%33) : yoe - (22 * 128) + 33;
1098 return (yoc != 0 && (yoc%4)==0);
1099}
1100
1101CONSTCD11 inline year::operator int() const NOEXCEPT {return y_;}
1102CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;}
1103
1105inline
1106year
1108{
1110}
1111
1113inline
1114year
1116{
1118}
1119
1121inline
1122bool
1123operator==(const year& x, const year& y) NOEXCEPT
1124{
1125 return static_cast<int>(x) == static_cast<int>(y);
1126}
1127
1129inline
1130bool
1131operator!=(const year& x, const year& y) NOEXCEPT
1132{
1133 return !(x == y);
1134}
1135
1137inline
1138bool
1139operator<(const year& x, const year& y) NOEXCEPT
1140{
1141 return static_cast<int>(x) < static_cast<int>(y);
1142}
1143
1145inline
1146bool
1147operator>(const year& x, const year& y) NOEXCEPT
1148{
1149 return y < x;
1150}
1151
1153inline
1154bool
1155operator<=(const year& x, const year& y) NOEXCEPT
1156{
1157 return !(y < x);
1158}
1159
1161inline
1162bool
1163operator>=(const year& x, const year& y) NOEXCEPT
1164{
1165 return !(x < y);
1166}
1167
1169inline
1170years
1171operator-(const year& x, const year& y) NOEXCEPT
1172{
1173 return years{static_cast<int>(x) - static_cast<int>(y)};
1174}
1175
1177inline
1178year
1179operator+(const year& x, const years& y) NOEXCEPT
1180{
1181 return year{static_cast<int>(x) + y.count()};
1182}
1183
1185inline
1186year
1187operator+(const years& x, const year& y) NOEXCEPT
1188{
1189 return y + x;
1190}
1191
1193inline
1194year
1195operator-(const year& x, const years& y) NOEXCEPT
1196{
1197 return year{static_cast<int>(x) - y.count()};
1198}
1199
1200template<class CharT, class Traits>
1201inline
1202std::basic_ostream<CharT, Traits>&
1203operator<<(std::basic_ostream<CharT, Traits>& os, const year& y)
1204{
1206 os.fill('0');
1207 os.flags(std::ios::dec | std::ios::internal);
1208 os.width(4 + (y < year{0}));
1209 os << static_cast<int>(y);
1210 return os;
1211}
1212
1213// weekday
1214
1216inline
1217unsigned char
1219{
1220 auto u = static_cast<unsigned>(z);
1221 return static_cast<unsigned char>(z >= -4 ? (u+4) % 7 : u % 7);
1222}
1223
1225inline
1227 : wd_(static_cast<decltype(wd_)>(wd != 7 ? wd : 0))
1228 {}
1229
1231inline
1233 : wd_(weekday_from_days(dp.time_since_epoch().count()))
1234 {}
1235
1237inline
1239 : wd_(weekday_from_days(dp.time_since_epoch().count()))
1240 {}
1241
1242CONSTCD14 inline weekday& weekday::operator++() NOEXCEPT {if (++wd_ == 7) wd_ = 0; return *this;}
1243CONSTCD14 inline weekday weekday::operator++(int) NOEXCEPT {auto tmp(*this); ++(*this); return tmp;}
1244CONSTCD14 inline weekday& weekday::operator--() NOEXCEPT {if (wd_-- == 0) wd_ = 6; return *this;}
1245CONSTCD14 inline weekday weekday::operator--(int) NOEXCEPT {auto tmp(*this); --(*this); return tmp;}
1246
1248inline
1249weekday&
1251{
1252 *this = *this + d;
1253 return *this;
1254}
1255
1257inline
1258weekday&
1260{
1261 *this = *this - d;
1262 return *this;
1263}
1264
1266inline
1267weekday::operator unsigned() const NOEXCEPT
1268{
1269 return static_cast<unsigned>(wd_);
1270}
1271
1272CONSTCD11 inline bool weekday::ok() const NOEXCEPT {return wd_ <= 6;}
1273
1275inline
1276bool
1278{
1279 return static_cast<unsigned>(x) == static_cast<unsigned>(y);
1280}
1281
1283inline
1284bool
1286{
1287 return !(x == y);
1288}
1289
1291inline
1292days
1294{
1295 auto const diff = static_cast<unsigned>(x) - static_cast<unsigned>(y);
1296 return days{diff <= 6 ? diff : diff + 7};
1297}
1298
1300inline
1301weekday
1302operator+(const weekday& x, const days& y) NOEXCEPT
1303{
1304 auto const wdu = static_cast<long long>(static_cast<unsigned>(x)) + y.count();
1305 auto const wk = (wdu >= 0 ? wdu : wdu-6) / 7;
1306 return weekday{static_cast<unsigned>(wdu - wk * 7)};
1307}
1308
1310inline
1311weekday
1312operator+(const days& x, const weekday& y) NOEXCEPT
1313{
1314 return y + x;
1315}
1316
1318inline
1319weekday
1320operator-(const weekday& x, const days& y) NOEXCEPT
1321{
1322 return x + -y;
1323}
1324
1325template<class CharT, class Traits>
1326inline
1327std::basic_ostream<CharT, Traits>&
1328operator<<(std::basic_ostream<CharT, Traits>& os, const weekday& wd)
1329{
1330 switch (static_cast<unsigned>(wd))
1331 {
1332 case 0:
1333 os << "Yekshanbe";
1334 break;
1335 case 1:
1336 os << "Doshanbe";
1337 break;
1338 case 2:
1339 os << "Seshanbe";
1340 break;
1341 case 3:
1342 os << "Chaharshanbe";
1343 break;
1344 case 4:
1345 os << "Panjshanbe";
1346 break;
1347 case 5:
1348 os << "Adine";
1349 break;
1350 case 6:
1351 os << "Shanbe";
1352 break;
1353 default:
1354 os << static_cast<unsigned>(wd) << " is not a valid weekday";
1355 break;
1356 }
1357 return os;
1358}
1359
1360#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1361inline namespace literals
1362{
1363
1365inline
1367operator "" _d(unsigned long long d) NOEXCEPT
1368{
1369 return solar_hijri::day{static_cast<unsigned>(d)};
1370}
1371
1373inline
1375operator "" _y(unsigned long long y) NOEXCEPT
1376{
1377 return solar_hijri::year(static_cast<int>(y));
1378}
1379#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
1380
1382
1395
1408
1416
1424
1425#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1426} // inline namespace literals
1427#endif
1428
1429// weekday_indexed
1430
1432inline
1433weekday
1435{
1436 return solar_hijri::weekday{static_cast<unsigned>(wd_)};
1437}
1438
1439CONSTCD11 inline unsigned weekday_indexed::index() const NOEXCEPT {return index_;}
1440
1442inline
1443bool
1445{
1446 return weekday().ok() && 1 <= index_ && index_ <= 5;
1447}
1448
1450inline
1452 : wd_(static_cast<decltype(wd_)>(static_cast<unsigned>(wd)))
1453 , index_(static_cast<decltype(index_)>(index))
1454 {}
1455
1456template<class CharT, class Traits>
1457inline
1458std::basic_ostream<CharT, Traits>&
1459operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_indexed& wdi)
1460{
1461 return os << wdi.weekday() << '[' << wdi.index() << ']';
1462}
1463
1465inline
1466weekday_indexed
1467weekday::operator[](unsigned index) const NOEXCEPT
1468{
1469 return {*this, index};
1470}
1471
1473inline
1474bool
1476{
1477 return x.weekday() == y.weekday() && x.index() == y.index();
1478}
1479
1481inline
1482bool
1484{
1485 return !(x == y);
1486}
1487
1488// weekday_last
1489
1491CONSTCD11 inline bool weekday_last::ok() const NOEXCEPT {return wd_.ok();}
1493
1495inline
1496bool
1498{
1499 return x.weekday() == y.weekday();
1500}
1501
1503inline
1504bool
1506{
1507 return !(x == y);
1508}
1509
1510template<class CharT, class Traits>
1511inline
1512std::basic_ostream<CharT, Traits>&
1513operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_last& wdl)
1514{
1515 return os << wdl.weekday() << "[last]";
1516}
1517
1519inline
1520weekday_last
1522{
1523 return weekday_last{*this};
1524}
1525
1526// year_month
1527
1529inline
1531 : y_(y)
1532 , m_(m)
1533 {}
1534
1535CONSTCD11 inline year year_month::year() const NOEXCEPT {return y_;}
1536CONSTCD11 inline month year_month::month() const NOEXCEPT {return m_;}
1537CONSTCD11 inline bool year_month::ok() const NOEXCEPT {return y_.ok() && m_.ok();}
1538
1540inline
1543{
1544 *this = *this + dm;
1545 return *this;
1546}
1547
1549inline
1552{
1553 *this = *this - dm;
1554 return *this;
1555}
1556
1558inline
1561{
1562 *this = *this + dy;
1563 return *this;
1564}
1565
1567inline
1570{
1571 *this = *this - dy;
1572 return *this;
1573}
1574
1576inline
1577bool
1579{
1580 return x.year() == y.year() && x.month() == y.month();
1581}
1582
1584inline
1585bool
1587{
1588 return !(x == y);
1589}
1590
1592inline
1593bool
1594operator<(const year_month& x, const year_month& y) NOEXCEPT
1595{
1596 return x.year() < y.year() ? true
1597 : (x.year() > y.year() ? false
1598 : (x.month() < y.month()));
1599}
1600
1602inline
1603bool
1605{
1606 return y < x;
1607}
1608
1610inline
1611bool
1612operator<=(const year_month& x, const year_month& y) NOEXCEPT
1613{
1614 return !(y < x);
1615}
1616
1618inline
1619bool
1621{
1622 return !(x < y);
1623}
1624
1626inline
1627year_month
1629{
1630 auto dmi = static_cast<int>(static_cast<unsigned>(ym.month())) - 1 + dm.count();
1631 auto dy = (dmi >= 0 ? dmi : dmi-11) / 12;
1632 dmi = dmi - dy * 12 + 1;
1633 return (ym.year() + years(dy)) / month(static_cast<unsigned>(dmi));
1634}
1635
1637inline
1638year_month
1640{
1641 return ym + dm;
1642}
1643
1645inline
1646year_month
1648{
1649 return ym + -dm;
1650}
1651
1653inline
1654months
1656{
1657 return (x.year() - y.year()) +
1658 months(static_cast<unsigned>(x.month()) - static_cast<unsigned>(y.month()));
1659}
1660
1662inline
1663year_month
1664operator+(const year_month& ym, const years& dy) NOEXCEPT
1665{
1666 return (ym.year() + dy) / ym.month();
1667}
1668
1670inline
1671year_month
1672operator+(const years& dy, const year_month& ym) NOEXCEPT
1673{
1674 return ym + dy;
1675}
1676
1678inline
1679year_month
1680operator-(const year_month& ym, const years& dy) NOEXCEPT
1681{
1682 return ym + -dy;
1683}
1684
1685template<class CharT, class Traits>
1686inline
1687std::basic_ostream<CharT, Traits>&
1688operator<<(std::basic_ostream<CharT, Traits>& os, const year_month& ym)
1689{
1690 return os << ym.year() << '/' << ym.month();
1691}
1692
1693// month_day
1694
1696inline
1698 : m_(m)
1699 , d_(d)
1700 {}
1701
1704
1706inline
1707bool
1709{
1715 };
1716 return m_.ok() && solar_hijri::day(1) <= d_ && d_ <= d[static_cast<unsigned>(m_)-1];
1717}
1718
1720inline
1721bool
1723{
1724 return x.month() == y.month() && x.day() == y.day();
1725}
1726
1728inline
1729bool
1731{
1732 return !(x == y);
1733}
1734
1736inline
1737bool
1738operator<(const month_day& x, const month_day& y) NOEXCEPT
1739{
1740 return x.month() < y.month() ? true
1741 : (x.month() > y.month() ? false
1742 : (x.day() < y.day()));
1743}
1744
1746inline
1747bool
1749{
1750 return y < x;
1751}
1752
1754inline
1755bool
1756operator<=(const month_day& x, const month_day& y) NOEXCEPT
1757{
1758 return !(y < x);
1759}
1760
1762inline
1763bool
1765{
1766 return !(x < y);
1767}
1768
1769template<class CharT, class Traits>
1770inline
1771std::basic_ostream<CharT, Traits>&
1772operator<<(std::basic_ostream<CharT, Traits>& os, const month_day& md)
1773{
1774 return os << md.month() << '/' << md.day();
1775}
1776
1777// month_day_last
1778
1780CONSTCD11 inline bool month_day_last::ok() const NOEXCEPT {return m_.ok();}
1782
1784inline
1785bool
1787{
1788 return x.month() == y.month();
1789}
1790
1792inline
1793bool
1795{
1796 return !(x == y);
1797}
1798
1800inline
1801bool
1803{
1804 return x.month() < y.month();
1805}
1806
1808inline
1809bool
1811{
1812 return y < x;
1813}
1814
1816inline
1817bool
1819{
1820 return !(y < x);
1821}
1822
1824inline
1825bool
1827{
1828 return !(x < y);
1829}
1830
1831template<class CharT, class Traits>
1832inline
1833std::basic_ostream<CharT, Traits>&
1834operator<<(std::basic_ostream<CharT, Traits>& os, const month_day_last& mdl)
1835{
1836 return os << mdl.month() << "/last";
1837}
1838
1839// month_weekday
1840
1842inline
1845 : m_(m)
1846 , wdi_(wdi)
1847 {}
1848
1850
1852inline
1855{
1856 return wdi_;
1857}
1858
1860inline
1861bool
1863{
1864 return m_.ok() && wdi_.ok();
1865}
1866
1868inline
1869bool
1871{
1872 return x.month() == y.month() && x.weekday_indexed() == y.weekday_indexed();
1873}
1874
1876inline
1877bool
1879{
1880 return !(x == y);
1881}
1882
1883template<class CharT, class Traits>
1884inline
1885std::basic_ostream<CharT, Traits>&
1886operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday& mwd)
1887{
1888 return os << mwd.month() << '/' << mwd.weekday_indexed();
1889}
1890
1891// month_weekday_last
1892
1894inline
1897 : m_(m)
1898 , wdl_(wdl)
1899 {}
1900
1902
1904inline
1907{
1908 return wdl_;
1909}
1910
1912inline
1913bool
1915{
1916 return m_.ok() && wdl_.ok();
1917}
1918
1920inline
1921bool
1923{
1924 return x.month() == y.month() && x.weekday_last() == y.weekday_last();
1925}
1926
1928inline
1929bool
1931{
1932 return !(x == y);
1933}
1934
1935template<class CharT, class Traits>
1936inline
1937std::basic_ostream<CharT, Traits>&
1938operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday_last& mwdl)
1939{
1940 return os << mwdl.month() << '/' << mwdl.weekday_last();
1941}
1942
1943// year_month_day_last
1944
1946inline
1949 : y_(y)
1950 , mdl_(mdl)
1951 {}
1952
1954inline
1957{
1958 *this = *this + m;
1959 return *this;
1960}
1961
1963inline
1966{
1967 *this = *this - m;
1968 return *this;
1969}
1970
1972inline
1975{
1976 *this = *this + y;
1977 return *this;
1978}
1979
1981inline
1984{
1985 *this = *this - y;
1986 return *this;
1987}
1988
1991
1993inline
1996{
1997 return mdl_;
1998}
1999
2001inline
2002day
2004{
2010 };
2011 return month() != esf || !y_.is_leap() ?
2012 d[static_cast<unsigned>(month()) - 1] : solar_hijri::day(30);
2013}
2014
2016inline
2017year_month_day_last::operator sys_days() const NOEXCEPT
2018{
2019 return sys_days(year()/month()/day());
2020}
2021
2023inline
2024year_month_day_last::operator local_days() const NOEXCEPT
2025{
2026 return local_days(year()/month()/day());
2027}
2028
2030inline
2031bool
2033{
2034 return y_.ok() && mdl_.ok();
2035}
2036
2038inline
2039bool
2041{
2042 return x.year() == y.year() && x.month_day_last() == y.month_day_last();
2043}
2044
2046inline
2047bool
2049{
2050 return !(x == y);
2051}
2052
2054inline
2055bool
2057{
2058 return x.year() < y.year() ? true
2059 : (x.year() > y.year() ? false
2060 : (x.month_day_last() < y.month_day_last()));
2061}
2062
2064inline
2065bool
2067{
2068 return y < x;
2069}
2070
2072inline
2073bool
2075{
2076 return !(y < x);
2077}
2078
2080inline
2081bool
2083{
2084 return !(x < y);
2085}
2086
2087template<class CharT, class Traits>
2088inline
2089std::basic_ostream<CharT, Traits>&
2090operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day_last& ymdl)
2091{
2092 return os << ymdl.year() << '/' << ymdl.month_day_last();
2093}
2094
2096inline
2097year_month_day_last
2099{
2100 return (ymdl.year() / ymdl.month() + dm) / last;
2101}
2102
2104inline
2105year_month_day_last
2107{
2108 return ymdl + dm;
2109}
2110
2112inline
2113year_month_day_last
2115{
2116 return ymdl + (-dm);
2117}
2118
2120inline
2121year_month_day_last
2123{
2124 return {ymdl.year()+dy, ymdl.month_day_last()};
2125}
2126
2128inline
2129year_month_day_last
2131{
2132 return ymdl + dy;
2133}
2134
2136inline
2137year_month_day_last
2139{
2140 return ymdl + (-dy);
2141}
2142
2143// year_month_day
2144
2146inline
2148 const solar_hijri::day& d) NOEXCEPT
2149 : y_(y)
2150 , m_(m)
2151 , d_(d)
2152 {}
2153
2155inline
2157 : y_(ymdl.year())
2158 , m_(ymdl.month())
2159 , d_(ymdl.day())
2160 {}
2161
2163inline
2165 : year_month_day(from_days(dp.time_since_epoch()))
2166 {}
2167
2169inline
2171 : year_month_day(from_days(dp.time_since_epoch()))
2172 {}
2173
2174CONSTCD11 inline year year_month_day::year() const NOEXCEPT {return y_;}
2177
2179inline
2182{
2183 *this = *this + m;
2184 return *this;
2185}
2186
2188inline
2191{
2192 *this = *this - m;
2193 return *this;
2194}
2195
2197inline
2200{
2201 *this = *this + y;
2202 return *this;
2203}
2204
2206inline
2209{
2210 *this = *this - y;
2211 return *this;
2212}
2213
2215inline
2216days
2218{
2219 static_assert(std::numeric_limits<unsigned>::digits >= 18,
2220 "This algorithm has not been ported to a 16 bit unsigned integer");
2221 static_assert(std::numeric_limits<int>::digits >= 20,
2222 "This algorithm has not been ported to a 16 bit signed integer");
2223
2224 using namespace internal;
2225 auto const y = static_cast<int>(y_) - 475;
2226 auto const m = static_cast<unsigned>(m_);
2227 auto const d = static_cast<unsigned>(d_);
2228 auto const era_d = static_cast<int>(y >= 0 ? y : y-years_in_era+1) / static_cast<double>(years_in_era);
2229 auto const era = static_cast<int>(era_d);
2230 auto const fdoe = static_cast<int>(epoch + era * days_in_era);
2231 auto const yoe = static_cast<int>(y - era * years_in_era);
2232
2233 auto const period_d = static_cast<double>(yoe/years_in_period);
2234 auto const period = static_cast<unsigned>(period_d);
2235 auto const yop = yoe%years_in_period;
2236 auto const fdop = period*days_in_period;
2237 auto const cycle = yop < 29 ? 0 : static_cast<unsigned>((yop-29)/years_in_other_cycles + 1);
2238 auto const yoc = yop < 29 ? yop : (yop-29)%years_in_other_cycles;
2239 auto const fdoc = cycle > 0 ? days_in_first_cycle + (cycle-1)*days_in_other_cycles : 0;
2240 auto const group = yoc < 1 ? 0 : static_cast<unsigned>((yoc-1) / 4);
2241 auto const yog = static_cast<int>(yoc < 1 ? -1 : (yoc-1) % 4);
2242 auto const fdoyog = group*1461 + (yog+1)*365;
2243 auto const fdoyoe = fdop + fdoc + fdoyog;
2244
2245 auto const doy = 30*(m-1) + ((m > 6) ? 6 : m-1) + d-1; // [0, 365]
2246 auto const doe = fdoe + fdoyoe + doy;
2247 return days{doe - unix_time_shift};
2248}
2249
2251inline
2252year_month_day::operator sys_days() const NOEXCEPT
2253{
2254 return sys_days{to_days()};
2255}
2256
2258inline
2259year_month_day::operator local_days() const NOEXCEPT
2260{
2261 return local_days{to_days()};
2262}
2263
2265inline
2266bool
2268{
2269 if (!(y_.ok() && m_.ok()))
2270 return false;
2271 return solar_hijri::day(1) <= d_ && d_ <= (y_/m_/last).day();
2272}
2273
2275inline
2276bool
2278{
2279 return x.year() == y.year() && x.month() == y.month() && x.day() == y.day();
2280}
2281
2283inline
2284bool
2286{
2287 return !(x == y);
2288}
2289
2291inline
2292bool
2294{
2295 return x.year() < y.year() ? true
2296 : (x.year() > y.year() ? false
2297 : (x.month() < y.month() ? true
2298 : (x.month() > y.month() ? false
2299 : (x.day() < y.day()))));
2300}
2301
2303inline
2304bool
2306{
2307 return y < x;
2308}
2309
2311inline
2312bool
2314{
2315 return !(y < x);
2316}
2317
2319inline
2320bool
2322{
2323 return !(x < y);
2324}
2325
2326template<class CharT, class Traits>
2327inline
2328std::basic_ostream<CharT, Traits>&
2329operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day& ymd)
2330{
2332 os.fill('0');
2333 os.flags(std::ios::dec | std::ios::right);
2334 os << ymd.year() << '-';
2335 os.width(2);
2336 os << static_cast<unsigned>(ymd.month()) << '-';
2337 os << ymd.day();
2338 return os;
2339}
2340
2342inline
2343year_month_day
2345{
2346 static_assert(std::numeric_limits<unsigned>::digits >= 18,
2347 "This algorithm has not been ported to a 16 bit unsigned integer");
2348 static_assert(std::numeric_limits<int>::digits >= 20,
2349 "This algorithm has not been ported to a 16 bit signed integer");
2350
2351 using namespace internal;
2352 auto const z = dp.count() + unix_time_shift;
2353 auto const delta = static_cast<int>(z - epoch);
2354 auto const era = static_cast<int>(delta >= 0 ? delta : delta-days_in_era+1) / static_cast<double>(days_in_era);
2355 auto const era_i = static_cast<int>(era);
2356 auto const fdoe = static_cast<int>(epoch + static_cast<int>(era_i * days_in_era));
2357
2358 auto const doe_fdoe = z - fdoe;
2359 auto const period = static_cast<unsigned>(doe_fdoe < 22*days_in_period ? doe_fdoe / days_in_period : 22);
2360 auto const dop = doe_fdoe % days_in_period;
2361 auto const cycle = dop < days_in_first_cycle ? 0 : (dop-days_in_first_cycle) / days_in_other_cycles + 1;
2362 auto const doc = dop < days_in_first_cycle ? dop : (dop-days_in_first_cycle) % days_in_other_cycles;
2363 auto const group = doc < 365 && period != 22 ? -1 : static_cast<int>(((doc < 365 ? 365 : doc)-365)/1461);
2364 auto const yog = doc < 365 && period != 22 ? -1 : static_cast<int>( (period != 22 ? ((doc-365 )%1461) : doc)/365);
2365 auto const yoc = group == -1 ? 0 : (period != 22 ? 1 : 0) + group*4 + (yog == 4 ? 3 : yog);
2366 auto const doy = group == -1 ? doc : (period != 22 ? ((yoc-1)%4 == 0 ? (group >= 0 ? (doe_fdoe -
2367 (period*days_in_period) -
2368 (cycle > 0 ? days_in_first_cycle + (cycle-1)*days_in_other_cycles : 0) -
2369 (group*1461 + ((yog == 4 ? 3 : yog)+1)*365))
2370 : 365)
2371 : doe_fdoe -
2372 (period*days_in_period) -
2373 (cycle > 0 ? days_in_first_cycle + (cycle-1)*days_in_other_cycles : 0) -
2374 (group*1461 + ((yog == 4 ? 3 : yog)+1)*365))
2375 : (yog == 4 ? 365 : doe_fdoe - (period*days_in_period) - yog*365));
2376 auto const yoe = period != 22 ? period*years_in_period +
2377 (cycle > 0 ? years_in_first_cycle +
2378 (cycle-1)*years_in_other_cycles
2379 : 0) +
2380 yoc
2381 : 22*years_in_period + ((yog == 4) ? 3 : yog);
2382 auto const y = static_cast<int>(static_cast<sys_days::rep>(yoe) + 475 + era_i * years_in_era);
2383 auto const m = doy < 186 ? doy/31 + 1 : (doy-186)/30 + 7; // [1, 12]
2384 auto const d = doy - (30*(m-1) + ((m > 6) ? 6 : m-1) - 1); // [1, 31]
2385
2387}
2388
2390inline
2393{
2394 return (ymd.year() / ymd.month() + dm) / ymd.day();
2395}
2396
2398inline
2399year_month_day
2401{
2402 return ymd + dm;
2403}
2404
2406inline
2407year_month_day
2409{
2410 return ymd + (-dm);
2411}
2412
2414inline
2415year_month_day
2417{
2418 return (ymd.year() + dy) / ymd.month() / ymd.day();
2419}
2420
2422inline
2423year_month_day
2425{
2426 return ymd + dy;
2427}
2428
2430inline
2431year_month_day
2433{
2434 return ymd + (-dy);
2435}
2436
2437// year_month_weekday
2438
2440inline
2443 NOEXCEPT
2444 : y_(y)
2445 , m_(m)
2446 , wdi_(wdi)
2447 {}
2448
2450inline
2452 : year_month_weekday(from_days(dp.time_since_epoch()))
2453 {}
2454
2456inline
2458 : year_month_weekday(from_days(dp.time_since_epoch()))
2459 {}
2460
2462inline
2465{
2466 *this = *this + m;
2467 return *this;
2468}
2469
2471inline
2474{
2475 *this = *this - m;
2476 return *this;
2477}
2478
2480inline
2483{
2484 *this = *this + y;
2485 return *this;
2486}
2487
2489inline
2492{
2493 *this = *this - y;
2494 return *this;
2495}
2496
2499
2501inline
2502weekday
2504{
2505 return wdi_.weekday();
2506}
2507
2509inline
2510unsigned
2512{
2513 return wdi_.index();
2514}
2515
2517inline
2520{
2521 return wdi_;
2522}
2523
2525inline
2526year_month_weekday::operator sys_days() const NOEXCEPT
2527{
2528 return sys_days{to_days()};
2529}
2530
2532inline
2533year_month_weekday::operator local_days() const NOEXCEPT
2534{
2535 return local_days{to_days()};
2536}
2537
2539inline
2540bool
2542{
2543 if (!y_.ok() || !m_.ok() || !wdi_.weekday().ok() || wdi_.index() < 1)
2544 return false;
2545 if (wdi_.index() <= 4)
2546 return true;
2547 auto d2 = wdi_.weekday() - solar_hijri::weekday(y_/m_/1) + days((wdi_.index()-1)*7 + 1);
2548 return static_cast<unsigned>(d2.count()) <= static_cast<unsigned>((y_/m_/last).day());
2549}
2550
2552inline
2555{
2556 sys_days dp{d};
2557 auto const wd = solar_hijri::weekday(dp);
2558 auto const ymd = year_month_day(dp);
2559 return {ymd.year(), ymd.month(), wd[(static_cast<unsigned>(ymd.day())-1)/7+1]};
2560}
2561
2563inline
2564days
2566{
2567 auto d = sys_days(y_/m_/1);
2568 return (d + (wdi_.weekday() - solar_hijri::weekday(d) + days{(wdi_.index()-1)*7})
2569 ).time_since_epoch();
2570}
2571
2573inline
2574bool
2576{
2577 return x.year() == y.year() && x.month() == y.month() &&
2578 x.weekday_indexed() == y.weekday_indexed();
2579}
2580
2582inline
2583bool
2585{
2586 return !(x == y);
2587}
2588
2589template<class CharT, class Traits>
2590inline
2591std::basic_ostream<CharT, Traits>&
2592operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwdi)
2593{
2594 return os << ymwdi.year() << '/' << ymwdi.month()
2595 << '/' << ymwdi.weekday_indexed();
2596}
2597
2599inline
2600year_month_weekday
2602{
2603 return (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed();
2604}
2605
2607inline
2608year_month_weekday
2610{
2611 return ymwd + dm;
2612}
2613
2615inline
2616year_month_weekday
2618{
2619 return ymwd + (-dm);
2620}
2621
2623inline
2624year_month_weekday
2626{
2627 return {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()};
2628}
2629
2631inline
2632year_month_weekday
2634{
2635 return ymwd + dy;
2636}
2637
2639inline
2640year_month_weekday
2642{
2643 return ymwd + (-dy);
2644}
2645
2646// year_month_weekday_last
2647
2649inline
2651 const solar_hijri::month& m,
2653 : y_(y)
2654 , m_(m)
2655 , wdl_(wdl)
2656 {}
2657
2659inline
2662{
2663 *this = *this + m;
2664 return *this;
2665}
2666
2668inline
2671{
2672 *this = *this - m;
2673 return *this;
2674}
2675
2677inline
2680{
2681 *this = *this + y;
2682 return *this;
2683}
2684
2686inline
2689{
2690 *this = *this - y;
2691 return *this;
2692}
2693
2696
2698inline
2699weekday
2701{
2702 return wdl_.weekday();
2703}
2704
2706inline
2709{
2710 return wdl_;
2711}
2712
2714inline
2715year_month_weekday_last::operator sys_days() const NOEXCEPT
2716{
2717 return sys_days{to_days()};
2718}
2719
2721inline
2722year_month_weekday_last::operator local_days() const NOEXCEPT
2723{
2724 return local_days{to_days()};
2725}
2726
2728inline
2729bool
2731{
2732 return y_.ok() && m_.ok() && wdl_.ok();
2733}
2734
2736inline
2737days
2739{
2740 auto const d = sys_days(y_/m_/last);
2741 return (d - (solar_hijri::weekday{d} - wdl_.weekday())).time_since_epoch();
2742}
2743
2745inline
2746bool
2748{
2749 return x.year() == y.year() && x.month() == y.month() &&
2750 x.weekday_last() == y.weekday_last();
2751}
2752
2754inline
2755bool
2757{
2758 return !(x == y);
2759}
2760
2761template<class CharT, class Traits>
2762inline
2763std::basic_ostream<CharT, Traits>&
2764operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl)
2765{
2766 return os << ymwdl.year() << '/' << ymwdl.month() << '/' << ymwdl.weekday_last();
2767}
2768
2770inline
2771year_month_weekday_last
2773{
2774 return (ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last();
2775}
2776
2778inline
2779year_month_weekday_last
2781{
2782 return ymwdl + dm;
2783}
2784
2786inline
2787year_month_weekday_last
2789{
2790 return ymwdl + (-dm);
2791}
2792
2794inline
2795year_month_weekday_last
2797{
2798 return {ymwdl.year()+dy, ymwdl.month(), ymwdl.weekday_last()};
2799}
2800
2802inline
2803year_month_weekday_last
2805{
2806 return ymwdl + dy;
2807}
2808
2810inline
2811year_month_weekday_last
2813{
2814 return ymwdl + (-dy);
2815}
2816
2817// year_month from operator/()
2818
2820inline
2821year_month
2822operator/(const year& y, const month& m) NOEXCEPT
2823{
2824 return {y, m};
2825}
2826
2828inline
2829year_month
2830operator/(const year& y, int m) NOEXCEPT
2831{
2832 return y / month(static_cast<unsigned>(m));
2833}
2834
2835// month_day from operator/()
2836
2838inline
2839month_day
2840operator/(const month& m, const day& d) NOEXCEPT
2841{
2842 return {m, d};
2843}
2844
2846inline
2847month_day
2848operator/(const day& d, const month& m) NOEXCEPT
2849{
2850 return m / d;
2851}
2852
2854inline
2855month_day
2856operator/(const month& m, int d) NOEXCEPT
2857{
2858 return m / day(static_cast<unsigned>(d));
2859}
2860
2862inline
2863month_day
2864operator/(int m, const day& d) NOEXCEPT
2865{
2866 return month(static_cast<unsigned>(m)) / d;
2867}
2868
2869CONSTCD11 inline month_day operator/(const day& d, int m) NOEXCEPT {return m / d;}
2870
2871// month_day_last from operator/()
2872
2874inline
2875month_day_last
2877{
2878 return month_day_last{m};
2879}
2880
2882inline
2883month_day_last
2885{
2886 return m/last;
2887}
2888
2890inline
2891month_day_last
2893{
2894 return month(static_cast<unsigned>(m))/last;
2895}
2896
2898inline
2899month_day_last
2901{
2902 return m/last;
2903}
2904
2905// month_weekday from operator/()
2906
2908inline
2909month_weekday
2911{
2912 return {m, wdi};
2913}
2914
2916inline
2917month_weekday
2919{
2920 return m / wdi;
2921}
2922
2924inline
2925month_weekday
2927{
2928 return month(static_cast<unsigned>(m)) / wdi;
2929}
2930
2932inline
2933month_weekday
2935{
2936 return m / wdi;
2937}
2938
2939// month_weekday_last from operator/()
2940
2942inline
2943month_weekday_last
2945{
2946 return {m, wdl};
2947}
2948
2950inline
2951month_weekday_last
2953{
2954 return m / wdl;
2955}
2956
2958inline
2959month_weekday_last
2961{
2962 return month(static_cast<unsigned>(m)) / wdl;
2963}
2964
2966inline
2967month_weekday_last
2969{
2970 return m / wdl;
2971}
2972
2973// year_month_day from operator/()
2974
2976inline
2977year_month_day
2978operator/(const year_month& ym, const day& d) NOEXCEPT
2979{
2980 return {ym.year(), ym.month(), d};
2981}
2982
2984inline
2985year_month_day
2987{
2988 return ym / day(static_cast<unsigned>(d));
2989}
2990
2992inline
2993year_month_day
2994operator/(const year& y, const month_day& md) NOEXCEPT
2995{
2996 return y / md.month() / md.day();
2997}
2998
3000inline
3001year_month_day
3003{
3004 return year(y) / md;
3005}
3006
3008inline
3009year_month_day
3010operator/(const month_day& md, const year& y) NOEXCEPT
3011{
3012 return y / md;
3013}
3014
3016inline
3017year_month_day
3019{
3020 return year(y) / md;
3021}
3022
3023// year_month_day_last from operator/()
3024
3026inline
3027year_month_day_last
3029{
3030 return {ym.year(), month_day_last{ym.month()}};
3031}
3032
3034inline
3035year_month_day_last
3037{
3038 return {y, mdl};
3039}
3040
3042inline
3043year_month_day_last
3045{
3046 return year(y) / mdl;
3047}
3048
3050inline
3051year_month_day_last
3053{
3054 return y / mdl;
3055}
3056
3058inline
3059year_month_day_last
3061{
3062 return year(y) / mdl;
3063}
3064
3065// year_month_weekday from operator/()
3066
3068inline
3069year_month_weekday
3071{
3072 return {ym.year(), ym.month(), wdi};
3073}
3074
3076inline
3077year_month_weekday
3079{
3080 return {y, mwd.month(), mwd.weekday_indexed()};
3081}
3082
3084inline
3085year_month_weekday
3087{
3088 return year(y) / mwd;
3089}
3090
3092inline
3093year_month_weekday
3095{
3096 return y / mwd;
3097}
3098
3100inline
3101year_month_weekday
3103{
3104 return year(y) / mwd;
3105}
3106
3107// year_month_weekday_last from operator/()
3108
3110inline
3111year_month_weekday_last
3113{
3114 return {ym.year(), ym.month(), wdl};
3115}
3116
3118inline
3119year_month_weekday_last
3121{
3122 return {y, mwdl.month(), mwdl.weekday_last()};
3123}
3124
3126inline
3127year_month_weekday_last
3129{
3130 return year(y) / mwdl;
3131}
3132
3134inline
3135year_month_weekday_last
3137{
3138 return y / mwdl;
3139}
3140
3142inline
3143year_month_weekday_last
3145{
3146 return year(y) / mwdl;
3147}
3148
3149} // namespace solar_hijri
3150
3151#endif // SOLAR_HIJRI_H
unsigned char d_
Definition: solar_hijri.h:188
CONSTCD14 day & operator--() NOEXCEPT
Definition: solar_hijri.h:810
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:815
CONSTCD14 day & operator-=(const days &d) NOEXCEPT
Definition: solar_hijri.h:813
CONSTCD14 day & operator++() NOEXCEPT
Definition: solar_hijri.h:808
CONSTCD14 day & operator+=(const days &d) NOEXCEPT
Definition: solar_hijri.h:812
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:1779
solar_hijri::month m_
Definition: solar_hijri.h:463
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1780
CONSTCD11 solar_hijri::day day() const NOEXCEPT
Definition: solar_hijri.h:1703
solar_hijri::month m_
Definition: solar_hijri.h:435
CONSTCD14 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1708
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:1702
solar_hijri::day d_
Definition: solar_hijri.h:436
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:1901
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1914
solar_hijri::weekday_last wdl_
Definition: solar_hijri.h:513
CONSTCD11 solar_hijri::weekday_last weekday_last() const NOEXCEPT
Definition: solar_hijri.h:1906
solar_hijri::weekday_indexed wdi_
Definition: solar_hijri.h:489
solar_hijri::month m_
Definition: solar_hijri.h:488
CONSTCD11 solar_hijri::weekday_indexed weekday_indexed() const NOEXCEPT
Definition: solar_hijri.h:1854
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:1849
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1862
CONSTCD14 month & operator+=(const months &m) NOEXCEPT
Definition: solar_hijri.h:922
CONSTCD14 month & operator-=(const months &m) NOEXCEPT
Definition: solar_hijri.h:931
unsigned char m_
Definition: solar_hijri.h:226
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:938
CONSTCD14 month & operator--() NOEXCEPT
Definition: solar_hijri.h:916
CONSTCD14 month & operator++() NOEXCEPT
Definition: solar_hijri.h:914
CONSTCD11 unsigned index() const NOEXCEPT
Definition: solar_hijri.h:1439
CONSTCD11 solar_hijri::weekday weekday() const NOEXCEPT
Definition: solar_hijri.h:1434
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1444
CONSTCD11 solar_hijri::weekday weekday() const NOEXCEPT
Definition: solar_hijri.h:1490
solar_hijri::weekday wd_
Definition: solar_hijri.h:372
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1491
CONSTCD14 weekday & operator--() NOEXCEPT
Definition: solar_hijri.h:1244
CONSTCD14 weekday & operator-=(const days &d) NOEXCEPT
Definition: solar_hijri.h:1259
CONSTCD14 weekday & operator++() NOEXCEPT
Definition: solar_hijri.h:1242
unsigned char wd_
Definition: solar_hijri.h:307
CONSTCD14 weekday & operator+=(const days &d) NOEXCEPT
Definition: solar_hijri.h:1250
CONSTCD11 weekday_indexed operator[](unsigned index) const NOEXCEPT
Definition: solar_hijri.h:1467
static CONSTCD11 unsigned char weekday_from_days(int z) NOEXCEPT
Definition: solar_hijri.h:1218
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1272
CONSTCD11 solar_hijri::year year() const NOEXCEPT
Definition: solar_hijri.h:1989
CONSTCD14 solar_hijri::day day() const NOEXCEPT
Definition: solar_hijri.h:2003
CONSTCD14 year_month_day_last & operator+=(const months &m) NOEXCEPT
Definition: solar_hijri.h:1956
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:2032
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:1990
CONSTCD14 year_month_day_last & operator-=(const months &m) NOEXCEPT
Definition: solar_hijri.h:1965
CONSTCD11 solar_hijri::month_day_last month_day_last() const NOEXCEPT
Definition: solar_hijri.h:1995
solar_hijri::month_day_last mdl_
Definition: solar_hijri.h:593
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:2175
CONSTCD14 year_month_day & operator+=(const months &m) NOEXCEPT
Definition: solar_hijri.h:2181
CONSTCD14 bool ok() const NOEXCEPT
Definition: solar_hijri.h:2267
solar_hijri::year y_
Definition: solar_hijri.h:539
CONSTCD11 solar_hijri::year year() const NOEXCEPT
Definition: solar_hijri.h:2174
solar_hijri::month m_
Definition: solar_hijri.h:540
CONSTCD14 year_month_day & operator-=(const months &m) NOEXCEPT
Definition: solar_hijri.h:2190
CONSTCD11 solar_hijri::day day() const NOEXCEPT
Definition: solar_hijri.h:2176
CONSTCD14 days to_days() const NOEXCEPT
Definition: solar_hijri.h:2217
static CONSTCD14 year_month_day from_days(days dp) NOEXCEPT
Definition: solar_hijri.h:2344
CONSTCD14 days to_days() const NOEXCEPT
Definition: solar_hijri.h:2738
CONSTCD11 solar_hijri::weekday_last weekday_last() const NOEXCEPT
Definition: solar_hijri.h:2708
CONSTCD11 solar_hijri::year year() const NOEXCEPT
Definition: solar_hijri.h:2694
CONSTCD14 year_month_weekday_last & operator-=(const months &m) NOEXCEPT
Definition: solar_hijri.h:2670
solar_hijri::weekday_last wdl_
Definition: solar_hijri.h:730
CONSTCD11 solar_hijri::weekday weekday() const NOEXCEPT
Definition: solar_hijri.h:2700
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:2730
CONSTCD14 year_month_weekday_last & operator+=(const months &m) NOEXCEPT
Definition: solar_hijri.h:2661
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:2695
solar_hijri::weekday_indexed wdi_
Definition: solar_hijri.h:662
CONSTCD14 year_month_weekday & operator-=(const months &m) NOEXCEPT
Definition: solar_hijri.h:2473
CONSTCD11 solar_hijri::weekday_indexed weekday_indexed() const NOEXCEPT
Definition: solar_hijri.h:2519
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:2498
CONSTCD14 days to_days() const NOEXCEPT
Definition: solar_hijri.h:2565
CONSTCD11 unsigned index() const NOEXCEPT
Definition: solar_hijri.h:2511
CONSTCD11 solar_hijri::weekday weekday() const NOEXCEPT
Definition: solar_hijri.h:2503
CONSTCD11 solar_hijri::year year() const NOEXCEPT
Definition: solar_hijri.h:2497
CONSTCD14 bool ok() const NOEXCEPT
Definition: solar_hijri.h:2541
CONSTCD14 year_month_weekday & operator+=(const months &m) NOEXCEPT
Definition: solar_hijri.h:2464
static CONSTCD14 year_month_weekday from_days(days dp) NOEXCEPT
Definition: solar_hijri.h:2554
CONSTCD14 year_month & operator-=(const months &dm) NOEXCEPT
Definition: solar_hijri.h:1551
CONSTCD11 solar_hijri::month month() const NOEXCEPT
Definition: solar_hijri.h:1536
solar_hijri::month m_
Definition: solar_hijri.h:394
solar_hijri::year y_
Definition: solar_hijri.h:393
CONSTCD11 solar_hijri::year year() const NOEXCEPT
Definition: solar_hijri.h:1535
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1537
CONSTCD14 year_month & operator+=(const months &dm) NOEXCEPT
Definition: solar_hijri.h:1542
CONSTCD14 year & operator+=(const years &y) NOEXCEPT
Definition: solar_hijri.h:1080
CONSTCD11 bool ok() const NOEXCEPT
Definition: solar_hijri.h:1102
CONSTCD14 year & operator++() NOEXCEPT
Definition: solar_hijri.h:1076
CONSTCD14 year & operator--() NOEXCEPT
Definition: solar_hijri.h:1078
CONSTCD14 year & operator-=(const years &y) NOEXCEPT
Definition: solar_hijri.h:1081
CONSTCD14 bool is_leap() const NOEXCEPT
Definition: solar_hijri.h:1086
static CONSTCD11 year max() NOEXCEPT
Definition: solar_hijri.h:1115
static CONSTCD11 year min() NOEXCEPT
Definition: solar_hijri.h:1107
#define NOEXCEPT
Definition: date.h:135
#define CONSTDATA
Definition: date.h:132
#define CONSTCD14
Definition: date.h:134
#define CONSTCD11
Definition: date.h:133
decltype(std::ratio_divide< R1, R2 >{}) ratio_divide
Definition: date.h:167
decltype(std::ratio_multiply< R1, R2 >{}) ratio_multiply
Definition: date.h:164
CONSTDATA date::month dec
Definition: date.h:2002
local_time< days > local_days
Definition: date.h:202
std::chrono::duration< int, detail::ratio_multiply< std::ratio< 7 >, days::period > > weeks
Definition: date.h:180
std::chrono::duration< int, detail::ratio_multiply< std::ratio< 24 >, std::chrono::hours::period > > days
Definition: date.h:177
sys_time< days > sys_days
Definition: date.h:193
Namespace for mathematical applications.
Definition: muParser.cpp:53
auto const days_in_first_cycle
Definition: solar_hijri.h:49
static const auto days_in_era
Definition: solar_hijri.h:43
static const auto epoch
Definition: solar_hijri.h:42
auto const years_in_first_cycle
Definition: solar_hijri.h:46
auto const days_in_other_cycles
Definition: solar_hijri.h:50
static const auto years_in_era
Definition: solar_hijri.h:44
auto const days_in_period
Definition: solar_hijri.h:51
static const auto unix_time_shift
Definition: solar_hijri.h:45
auto const years_in_other_cycles
Definition: solar_hijri.h:47
auto const years_in_period
Definition: solar_hijri.h:48
CONSTDATA solar_hijri::weekday pan
Definition: solar_hijri.h:1413
CONSTDATA solar_hijri::weekday dos
Definition: solar_hijri.h:1410
CONSTDATA solar_hijri::month sha
Definition: solar_hijri.h:1388
CONSTDATA solar_hijri::month Aban
Definition: solar_hijri.h:1403
CONSTDATA solar_hijri::month Esfand
Definition: solar_hijri.h:1407
CONSTDATA solar_hijri::month bah
Definition: solar_hijri.h:1393
CONSTDATA solar_hijri::month Azar
Definition: solar_hijri.h:1404
CONSTDATA solar_hijri::month kho
Definition: solar_hijri.h:1385
CONSTDATA solar_hijri::weekday Doshanbe
Definition: solar_hijri.h:1418
CONSTDATA solar_hijri::weekday Adine
Definition: solar_hijri.h:1422
CONSTDATA solar_hijri::weekday Panjshanbe
Definition: solar_hijri.h:1421
CONSTDATA solar_hijri::month far
Definition: solar_hijri.h:1383
CONSTDATA solar_hijri::month aba
Definition: solar_hijri.h:1390
CONSTDATA solar_hijri::weekday Seshanbe
Definition: solar_hijri.h:1419
CONSTDATA solar_hijri::weekday Yekshanbe
Definition: solar_hijri.h:1417
CONSTDATA solar_hijri::month mor
Definition: solar_hijri.h:1387
CONSTDATA solar_hijri::month Tir
Definition: solar_hijri.h:1399
CONSTDATA solar_hijri::month Dey
Definition: solar_hijri.h:1405
CONSTDATA solar_hijri::month esf
Definition: solar_hijri.h:1394
CONSTDATA solar_hijri::month aza
Definition: solar_hijri.h:1391
CONSTDATA solar_hijri::month Ordibehesht
Definition: solar_hijri.h:1397
CONSTDATA solar_hijri::weekday adi
Definition: solar_hijri.h:1414
CONSTDATA solar_hijri::weekday yek
Definition: solar_hijri.h:1409
CONSTDATA solar_hijri::month Bahman
Definition: solar_hijri.h:1406
CONSTDATA solar_hijri::month Mordad
Definition: solar_hijri.h:1400
CONSTDATA solar_hijri::month ord
Definition: solar_hijri.h:1384
CONSTDATA solar_hijri::weekday cha
Definition: solar_hijri.h:1412
CONSTDATA solar_hijri::month Shahrivar
Definition: solar_hijri.h:1401
CONSTDATA solar_hijri::month Farvardin
Definition: solar_hijri.h:1396
CONSTDATA solar_hijri::month dey
Definition: solar_hijri.h:1392
CONSTDATA solar_hijri::month Mehr
Definition: solar_hijri.h:1402
CONSTDATA solar_hijri::month tir
Definition: solar_hijri.h:1386
CONSTDATA solar_hijri::last_spec last
Definition: solar_hijri.h:1381
CONSTDATA solar_hijri::weekday Chaharshanbe
Definition: solar_hijri.h:1420
CONSTDATA solar_hijri::weekday ses
Definition: solar_hijri.h:1411
CONSTDATA solar_hijri::month meh
Definition: solar_hijri.h:1389
CONSTDATA solar_hijri::month Khordad
Definition: solar_hijri.h:1398
CONSTDATA solar_hijri::weekday Shanbe
Definition: solar_hijri.h:1423
CONSTDATA solar_hijri::weekday shn
Definition: solar_hijri.h:1415
CONSTCD11 bool operator<=(const day &x, const day &y) NOEXCEPT
Definition: solar_hijri.h:852
CONSTCD11 bool operator!=(const day &x, const day &y) NOEXCEPT
Definition: solar_hijri.h:828
CONSTCD11 bool operator>=(const day &x, const day &y) NOEXCEPT
Definition: solar_hijri.h:860
date::local_days local_days
Definition: solar_hijri.h:69
CONSTCD11 year_month operator/(const year &y, const month &m) NOEXCEPT
Definition: solar_hijri.h:2822
std::chrono::duration< int, date::detail::ratio_divide< years::period, std::ratio< 12 > > > months
Definition: solar_hijri.h:64
CONSTCD11 bool operator<(const day &x, const day &y) NOEXCEPT
Definition: solar_hijri.h:836
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const day &d)
Definition: solar_hijri.h:901
date::days days
Definition: solar_hijri.h:56
CONSTCD11 bool operator==(const day &x, const day &y) NOEXCEPT
Definition: solar_hijri.h:820
date::weeks weeks
Definition: solar_hijri.h:58
CONSTCD11 day operator-(const day &x, const days &y) NOEXCEPT
Definition: solar_hijri.h:893
std::chrono::duration< int, date::detail::ratio_multiply< std::ratio< internal::days_in_era, internal::years_in_era >, days::period > > years
Definition: solar_hijri.h:61
CONSTCD11 bool operator>(const day &x, const day &y) NOEXCEPT
Definition: solar_hijri.h:844
CONSTCD11 day operator+(const day &x, const days &y) NOEXCEPT
Definition: solar_hijri.h:877
date::sys_days sys_days
Definition: solar_hijri.h:68
#define min(a, b)
Definition: resampler.cpp:34
#define max(a, b)
Definition: resampler.cpp:30