71# pragma GCC diagnostic push
72# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)
73# pragma GCC diagnostic ignored "-Wpedantic"
77# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
84# pragma warning(disable : 4127)
95# define ONLY_C_LOCALE 0
98#ifndef HAS_UNCAUGHT_EXCEPTIONS
99# if __cplusplus >= 201703 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
100# define HAS_UNCAUGHT_EXCEPTIONS 1
102# define HAS_UNCAUGHT_EXCEPTIONS 0
107# if __cplusplus >= 201703 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
118template <
typename R1,
typename R2>
119using ratio_multiply =
decltype(std::ratio_multiply<R1, R2>{});
121template <
typename R1,
typename R2>
122using ratio_divide =
decltype(std::ratio_divide<R1, R2>{});
131using days = std::chrono::duration
132 <
int, detail::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
134using weeks = std::chrono::duration
135 <
int, detail::ratio_multiply<std::ratio<7>, days::period>>;
137using years = std::chrono::duration
138 <
int, detail::ratio_multiply<std::ratio<146097, 400>, days::period>>;
140using months = std::chrono::duration
141 <
int, detail::ratio_divide<years::period, std::ratio<12>>>;
145template <
class Duration>
146 using sys_time = std::chrono::time_point<std::chrono::system_clock, Duration>;
153template <
class Duration>
154 using local_time = std::chrono::time_point<local_t, Duration>;
163 explicit last_spec() =
default;
270 explicit constexpr day(
unsigned d)
noexcept;
272 constexpr day& operator++() noexcept;
273 constexpr day operator++(
int) noexcept;
274 constexpr day& operator--() noexcept;
275 constexpr day operator--(
int) noexcept;
277 constexpr day& operator+=(const days& d) noexcept;
278 constexpr day& operator-=(const days& d) noexcept;
280 constexpr explicit operator
unsigned() const noexcept;
281 constexpr
bool ok() const noexcept;
284constexpr
bool operator==(const day& x, const day& y) noexcept;
285constexpr
bool operator!=(const day& x, const day& y) noexcept;
286constexpr
bool operator< (const day& x, const day& y) noexcept;
287constexpr
bool operator> (const day& x, const day& y) noexcept;
288constexpr
bool operator<=(const day& x, const day& y) noexcept;
289constexpr
bool operator>=(const day& x, const day& y) noexcept;
291constexpr day operator+(const day& x, const days& y) noexcept;
292constexpr day operator+(const days& x, const day& y) noexcept;
293constexpr day operator-(const day& x, const days& y) noexcept;
294constexpr days operator-(const day& x, const day& y) noexcept;
296template<class CharT, class Traits>
297std::basic_ostream<CharT, Traits>&
298operator<<(std::basic_ostream<CharT, Traits>& os, const day& d);
308 explicit constexpr month(
unsigned m)
noexcept;
310 constexpr month& operator++() noexcept;
311 constexpr month operator++(
int) noexcept;
312 constexpr month& operator--() noexcept;
313 constexpr month operator--(
int) noexcept;
315 constexpr month& operator+=(const months& m) noexcept;
316 constexpr month& operator-=(const months& m) noexcept;
318 constexpr explicit operator
unsigned() const noexcept;
319 constexpr
bool ok() const noexcept;
322constexpr
bool operator==(const month& x, const month& y) noexcept;
323constexpr
bool operator!=(const month& x, const month& y) noexcept;
324constexpr
bool operator< (const month& x, const month& y) noexcept;
325constexpr
bool operator> (const month& x, const month& y) noexcept;
326constexpr
bool operator<=(const month& x, const month& y) noexcept;
327constexpr
bool operator>=(const month& x, const month& y) noexcept;
329constexpr month operator+(const month& x, const months& y) noexcept;
330constexpr month operator+(const months& x, const month& y) noexcept;
331constexpr month operator-(const month& x, const months& y) noexcept;
332constexpr months operator-(const month& x, const month& y) noexcept;
334template<class CharT, class Traits>
335std::basic_ostream<CharT, Traits>&
336operator<<(std::basic_ostream<CharT, Traits>& os, const month& m);
346 explicit constexpr year(
int y)
noexcept;
348 constexpr year& operator++() noexcept;
349 constexpr year operator++(
int) noexcept;
350 constexpr year& operator--() noexcept;
351 constexpr year operator--(
int) noexcept;
353 constexpr year& operator+=(const years& y) noexcept;
354 constexpr year& operator-=(const years& y) noexcept;
356 constexpr year operator-() const noexcept;
357 constexpr year operator+() const noexcept;
359 constexpr
bool is_leap() const noexcept;
361 constexpr explicit operator
int() const noexcept;
362 constexpr
bool ok() const noexcept;
364 static constexpr year min() noexcept {
return year{-32767}; }
365 static constexpr year max() noexcept {
return year{32767}; }
368constexpr bool operator==(
const year& x,
const year& y)
noexcept;
369constexpr bool operator!=(
const year& x,
const year& y)
noexcept;
370constexpr bool operator< (
const year& x,
const year& y)
noexcept;
371constexpr bool operator> (
const year& x,
const year& y)
noexcept;
372constexpr bool operator<=(
const year& x,
const year& y)
noexcept;
373constexpr bool operator>=(
const year& x,
const year& y)
noexcept;
375constexpr year operator+(
const year& x,
const years& y)
noexcept;
376constexpr year operator+(
const years& x,
const year& y)
noexcept;
377constexpr year operator-(
const year& x,
const years& y)
noexcept;
378constexpr years operator-(
const year& x,
const year& y)
noexcept;
380template<
class CharT,
class Traits>
381std::basic_ostream<CharT, Traits>&
382operator<<(std::basic_ostream<CharT, Traits>& os,
const year& y);
391 explicit constexpr weekday(
unsigned wd)
noexcept;
392 constexpr weekday(
const sys_days& dp)
noexcept;
393 constexpr explicit weekday(
const local_days& dp)
noexcept;
395 constexpr weekday& operator++() noexcept;
396 constexpr weekday operator++(
int) noexcept;
397 constexpr weekday& operator--() noexcept;
398 constexpr weekday operator--(
int) noexcept;
400 constexpr weekday& operator+=(const days& d) noexcept;
401 constexpr weekday& operator-=(const days& d) noexcept;
403 constexpr
bool ok() const noexcept;
405 constexpr
unsigned c_encoding() const noexcept;
406 constexpr
unsigned iso_encoding() const noexcept;
408 constexpr weekday_indexed operator[](
unsigned index) const noexcept;
409 constexpr weekday_last operator[](last_spec) const noexcept;
412 static constexpr
unsigned char weekday_from_days(
int z) noexcept;
414 friend constexpr
bool operator==(const weekday& x, const weekday& y) noexcept;
415 friend constexpr days operator-(const weekday& x, const weekday& y) noexcept;
416 friend constexpr weekday operator+(const weekday& x, const days& y) noexcept;
417 template<class CharT, class Traits>
418 friend std::basic_ostream<CharT, Traits>&
419 operator<<(std::basic_ostream<CharT, Traits>& os, const weekday& wd);
420 friend class weekday_indexed;
423constexpr
bool operator==(const weekday& x, const weekday& y) noexcept;
424constexpr
bool operator!=(const weekday& x, const weekday& y) noexcept;
426constexpr weekday operator+(const weekday& x, const days& y) noexcept;
427constexpr weekday operator+(const days& x, const weekday& y) noexcept;
428constexpr weekday operator-(const weekday& x, const days& y) noexcept;
429constexpr days operator-(const weekday& x, const weekday& y) noexcept;
431template<class CharT, class Traits>
432std::basic_ostream<CharT, Traits>&
433operator<<(std::basic_ostream<CharT, Traits>& os, const weekday& wd);
439 unsigned char wd_ : 4;
440 unsigned char index_ : 4;
443 weekday_indexed() =
default;
444 constexpr weekday_indexed(
const gul17::date::weekday& wd,
unsigned index)
noexcept;
446 constexpr gul17::date::weekday weekday() const noexcept;
447 constexpr
unsigned index() const noexcept;
448 constexpr
bool ok() const noexcept;
451constexpr
bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
452constexpr
bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
454template<class CharT, class Traits>
455std::basic_ostream<CharT, Traits>&
456operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_indexed& wdi);
462 gul17::date::weekday wd_;
465 explicit constexpr weekday_last(
const gul17::date::weekday& wd)
noexcept;
467 constexpr gul17::date::weekday weekday() const noexcept;
468 constexpr
bool ok() const noexcept;
471constexpr
bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
472constexpr
bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
474template<class CharT, class Traits>
475std::basic_ostream<CharT, Traits>&
476operator<<(std::basic_ostream<CharT, Traits>& os, const weekday_last& wdl);
481struct unspecified_month_disambiguator {};
489 gul17::date::year y_;
490 gul17::date::month m_;
493 year_month() =
default;
494 constexpr year_month(
const gul17::date::year& y,
const gul17::date::month& m)
noexcept;
496 constexpr gul17::date::year year() const noexcept;
497 constexpr
gul17::date::month month() const noexcept;
499 template<class = detail::unspecified_month_disambiguator>
500 constexpr year_month& operator+=(const months& dm) noexcept;
501 template<class = detail::unspecified_month_disambiguator>
502 constexpr year_month& operator-=(const months& dm) noexcept;
503 constexpr year_month& operator+=(const years& dy) noexcept;
504 constexpr year_month& operator-=(const years& dy) noexcept;
506 constexpr
bool ok() const noexcept;
509constexpr
bool operator==(const year_month& x, const year_month& y) noexcept;
510constexpr
bool operator!=(const year_month& x, const year_month& y) noexcept;
511constexpr
bool operator< (const year_month& x, const year_month& y) noexcept;
512constexpr
bool operator> (const year_month& x, const year_month& y) noexcept;
513constexpr
bool operator<=(const year_month& x, const year_month& y) noexcept;
514constexpr
bool operator>=(const year_month& x, const year_month& y) noexcept;
516template<class = detail::unspecified_month_disambiguator>
517constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
518template<class = detail::unspecified_month_disambiguator>
519constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
520template<class = detail::unspecified_month_disambiguator>
521constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
523constexpr months operator-(const year_month& x, const year_month& y) noexcept;
524constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
525constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
526constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
528template<class CharT, class Traits>
529std::basic_ostream<CharT, Traits>&
530operator<<(std::basic_ostream<CharT, Traits>& os, const year_month& ym);
536 gul17::date::month m_;
540 month_day() =
default;
541 constexpr month_day(
const gul17::date::month& m,
const gul17::date::day& d)
noexcept;
543 constexpr gul17::date::month month() const noexcept;
544 constexpr
gul17::date::day day() const noexcept;
546 constexpr
bool ok() const noexcept;
549constexpr
bool operator==(const month_day& x, const month_day& y) noexcept;
550constexpr
bool operator!=(const month_day& x, const month_day& y) noexcept;
551constexpr
bool operator< (const month_day& x, const month_day& y) noexcept;
552constexpr
bool operator> (const month_day& x, const month_day& y) noexcept;
553constexpr
bool operator<=(const month_day& x, const month_day& y) noexcept;
554constexpr
bool operator>=(const month_day& x, const month_day& y) noexcept;
556template<class CharT, class Traits>
557std::basic_ostream<CharT, Traits>&
558operator<<(std::basic_ostream<CharT, Traits>& os, const month_day& md);
564 gul17::date::month m_;
567 constexpr explicit month_day_last(
const gul17::date::month& m)
noexcept;
569 constexpr gul17::date::month month() const noexcept;
570 constexpr
bool ok() const noexcept;
573constexpr
bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
574constexpr
bool operator!=(const month_day_last& x, const month_day_last& y) noexcept;
575constexpr
bool operator< (const month_day_last& x, const month_day_last& y) noexcept;
576constexpr
bool operator> (const month_day_last& x, const month_day_last& y) noexcept;
577constexpr
bool operator<=(const month_day_last& x, const month_day_last& y) noexcept;
578constexpr
bool operator>=(const month_day_last& x, const month_day_last& y) noexcept;
580template<class CharT, class Traits>
581std::basic_ostream<CharT, Traits>&
582operator<<(std::basic_ostream<CharT, Traits>& os, const month_day_last& mdl);
588 gul17::date::month m_;
589 gul17::date::weekday_indexed wdi_;
591 constexpr month_weekday(
const gul17::date::month& m,
592 const gul17::date::weekday_indexed& wdi)
noexcept;
594 constexpr gul17::date::month month() const noexcept;
595 constexpr
gul17::date::weekday_indexed weekday_indexed() const noexcept;
597 constexpr
bool ok() const noexcept;
600constexpr
bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
601constexpr
bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
603template<class CharT, class Traits>
604std::basic_ostream<CharT, Traits>&
605operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday& mwd);
609class month_weekday_last
611 gul17::date::month m_;
612 gul17::date::weekday_last wdl_;
615 constexpr month_weekday_last(
const gul17::date::month& m,
616 const gul17::date::weekday_last& wd)
noexcept;
618 constexpr gul17::date::month month() const noexcept;
619 constexpr
gul17::date::weekday_last weekday_last() const noexcept;
621 constexpr
bool ok() const noexcept;
625 bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
627 bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
629template<class CharT, class Traits>
630std::basic_ostream<CharT, Traits>&
631operator<<(std::basic_ostream<CharT, Traits>& os, const month_weekday_last& mwdl);
637 gul17::date::year y_;
638 gul17::date::month m_;
642 year_month_day() =
default;
643 constexpr year_month_day(
const gul17::date::year& y,
const gul17::date::month& m,
644 const gul17::date::day& d)
noexcept;
645 constexpr year_month_day(
const year_month_day_last& ymdl)
noexcept;
647 constexpr year_month_day(sys_days dp)
noexcept;
648 constexpr explicit year_month_day(local_days dp)
noexcept;
650 template<
class = detail::unspecified_month_disambiguator>
651 constexpr year_month_day& operator+=(
const months& m)
noexcept;
652 template<
class = detail::unspecified_month_disambiguator>
653 constexpr year_month_day& operator-=(
const months& m)
noexcept;
654 constexpr year_month_day& operator+=(
const years& y)
noexcept;
655 constexpr year_month_day& operator-=(
const years& y)
noexcept;
657 constexpr gul17::date::year year() const noexcept;
658 constexpr
gul17::date::month month() const noexcept;
659 constexpr
gul17::date::day day() const noexcept;
661 constexpr operator sys_days() const noexcept;
662 constexpr explicit operator local_days() const noexcept;
663 constexpr
bool ok() const noexcept;
666 static constexpr year_month_day from_days(days dp) noexcept;
667 constexpr days to_days() const noexcept;
670constexpr
bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
671constexpr
bool operator!=(const year_month_day& x, const year_month_day& y) noexcept;
672constexpr
bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
673constexpr
bool operator> (const year_month_day& x, const year_month_day& y) noexcept;
674constexpr
bool operator<=(const year_month_day& x, const year_month_day& y) noexcept;
675constexpr
bool operator>=(const year_month_day& x, const year_month_day& y) noexcept;
677template<class = detail::unspecified_month_disambiguator>
678constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
679template<class = detail::unspecified_month_disambiguator>
680constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
681template<class = detail::unspecified_month_disambiguator>
682constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
683constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
684constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
685constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
687template<class CharT, class Traits>
688std::basic_ostream<CharT, Traits>&
689operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day& ymd);
693class year_month_day_last
695 gul17::date::year y_;
696 gul17::date::month_day_last mdl_;
699 constexpr year_month_day_last(
const gul17::date::year& y,
700 const gul17::date::month_day_last& mdl)
noexcept;
702 template<
class = detail::unspecified_month_disambiguator>
703 constexpr year_month_day_last& operator+=(
const months& m)
noexcept;
704 template<
class = detail::unspecified_month_disambiguator>
705 constexpr year_month_day_last& operator-=(
const months& m)
noexcept;
706 constexpr year_month_day_last& operator+=(
const years& y)
noexcept;
707 constexpr year_month_day_last& operator-=(
const years& y)
noexcept;
709 constexpr gul17::date::year year() const noexcept;
710 constexpr
gul17::date::month month() const noexcept;
711 constexpr
gul17::date::month_day_last month_day_last() const noexcept;
712 constexpr
gul17::date::day day() const noexcept;
714 constexpr operator sys_days() const noexcept;
715 constexpr explicit operator local_days() const noexcept;
716 constexpr
bool ok() const noexcept;
720 bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
722 bool operator!=(const year_month_day_last& x, const year_month_day_last& y) noexcept;
724 bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept;
726 bool operator> (const year_month_day_last& x, const year_month_day_last& y) noexcept;
728 bool operator<=(const year_month_day_last& x, const year_month_day_last& y) noexcept;
730 bool operator>=(const year_month_day_last& x, const year_month_day_last& y) noexcept;
732template<class = detail::unspecified_month_disambiguator>
735operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
737template<class = detail::unspecified_month_disambiguator>
740operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
744operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
748operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
750template<class = detail::unspecified_month_disambiguator>
753operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
757operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
759template<class CharT, class Traits>
760std::basic_ostream<CharT, Traits>&
761operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_day_last& ymdl);
765class year_month_weekday
767 gul17::date::year y_;
768 gul17::date::month m_;
769 gul17::date::weekday_indexed wdi_;
772 year_month_weekday() =
default;
773 constexpr year_month_weekday(
const gul17::date::year& y,
const gul17::date::month& m,
774 const gul17::date::weekday_indexed& wdi)
noexcept;
775 constexpr year_month_weekday(
const sys_days& dp)
noexcept;
776 constexpr explicit year_month_weekday(
const local_days& dp)
noexcept;
778 template<
class = detail::unspecified_month_disambiguator>
779 constexpr year_month_weekday& operator+=(
const months& m)
noexcept;
780 template<
class = detail::unspecified_month_disambiguator>
781 constexpr year_month_weekday& operator-=(
const months& m)
noexcept;
782 constexpr year_month_weekday& operator+=(
const years& y)
noexcept;
783 constexpr year_month_weekday& operator-=(
const years& y)
noexcept;
785 constexpr gul17::date::year year() const noexcept;
786 constexpr
gul17::date::month month() const noexcept;
787 constexpr
gul17::date::weekday weekday() const noexcept;
788 constexpr
unsigned index() const noexcept;
789 constexpr
gul17::date::weekday_indexed weekday_indexed() const noexcept;
791 constexpr operator sys_days() const noexcept;
792 constexpr explicit operator local_days() const noexcept;
793 constexpr
bool ok() const noexcept;
796 static constexpr year_month_weekday from_days(days dp) noexcept;
797 constexpr days to_days() const noexcept;
801 bool operator==(const year_month_weekday& x, const year_month_weekday& y) noexcept;
803 bool operator!=(const year_month_weekday& x, const year_month_weekday& y) noexcept;
805template<class = detail::unspecified_month_disambiguator>
808operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
810template<class = detail::unspecified_month_disambiguator>
813operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
817operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
821operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
823template<class = detail::unspecified_month_disambiguator>
826operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
830operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
832template<class CharT, class Traits>
833std::basic_ostream<CharT, Traits>&
834operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday& ymwdi);
838class year_month_weekday_last
840 gul17::date::year y_;
841 gul17::date::month m_;
842 gul17::date::weekday_last wdl_;
845 constexpr year_month_weekday_last(
const gul17::date::year& y,
const gul17::date::month& m,
846 const gul17::date::weekday_last& wdl)
noexcept;
848 template<
class = detail::unspecified_month_disambiguator>
849 constexpr year_month_weekday_last& operator+=(
const months& m)
noexcept;
850 template<
class = detail::unspecified_month_disambiguator>
851 constexpr year_month_weekday_last& operator-=(
const months& m)
noexcept;
852 constexpr year_month_weekday_last& operator+=(
const years& y)
noexcept;
853 constexpr year_month_weekday_last& operator-=(
const years& y)
noexcept;
855 constexpr gul17::date::year year() const noexcept;
856 constexpr
gul17::date::month month() const noexcept;
857 constexpr
gul17::date::weekday weekday() const noexcept;
858 constexpr
gul17::date::weekday_last weekday_last() const noexcept;
860 constexpr operator sys_days() const noexcept;
861 constexpr explicit operator local_days() const noexcept;
862 constexpr
bool ok() const noexcept;
865 constexpr days to_days() const noexcept;
870operator==(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept;
874operator!=(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept;
876template<class = detail::unspecified_month_disambiguator>
878year_month_weekday_last
879operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
881template<class = detail::unspecified_month_disambiguator>
883year_month_weekday_last
884operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
887year_month_weekday_last
888operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
891year_month_weekday_last
892operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
894template<class = detail::unspecified_month_disambiguator>
896year_month_weekday_last
897operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
900year_month_weekday_last
901operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
903template<class CharT, class Traits>
904std::basic_ostream<CharT, Traits>&
905operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last& ymwdl);
907#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
908inline namespace literals
911constexpr gul17::date::day
operator "" _d(
unsigned long long d)
noexcept;
912constexpr gul17::date::year
operator "" _y(
unsigned long long y)
noexcept;
940template <
class T,
class = std::
void_t<>>
946struct is_clock<T, std::void_t<decltype(T::now()), typename T::rep, typename T::period,
947 typename T::duration, typename T::time_point,
948 decltype(T::is_steady)>>
952template<
class T>
inline constexpr bool is_clock_v = is_clock<T>::value;
963template<
class CharT,
class Traits = std::
char_traits<CharT>>
967 std::basic_ios<CharT, Traits>& is_;
969 std::ios::fmtflags flags_;
970 std::streamsize precision_;
971 std::streamsize width_;
972 std::basic_ostream<CharT, Traits>* tie_;
980 is_.precision(precision_);
986 save_istream(
const save_istream&) =
delete;
987 save_istream& operator=(
const save_istream&) =
delete;
989 explicit save_istream(std::basic_ios<CharT, Traits>& is)
993 , precision_(is.precision())
994 , width_(is.width(0))
995 , tie_(is.tie(nullptr))
1003template<
class CharT,
class Traits = std::
char_traits<CharT>>
1005 :
private save_istream<CharT, Traits>
1010 if ((this->flags_ & std::ios::unitbuf) &&
1011#
if HAS_UNCAUGHT_EXCEPTIONS
1012 std::uncaught_exceptions() == 0 &&
1014 !std::uncaught_exception() &&
1017 this->is_.rdbuf()->pubsync();
1020 save_ostream(
const save_ostream&) =
delete;
1021 save_ostream& operator=(
const save_ostream&) =
delete;
1023 explicit save_ostream(std::basic_ios<CharT, Traits>& os)
1024 : save_istream<CharT, Traits>(os)
1030struct choose_trunc_type
1032 static const int digits = std::numeric_limits<T>::digits;
1033 using type =
typename std::conditional
1037 typename std::conditional
1041#ifdef __SIZEOF_INT128__
1052typename std::enable_if
1054 !std::chrono::treat_as_floating_point<T>::value,
1064typename std::enable_if
1066 std::chrono::treat_as_floating_point<T>::value,
1071 using std::numeric_limits;
1072 using I =
typename choose_trunc_type<T>::type;
1073 constexpr const auto digits = numeric_limits<T>::digits;
1074 static_assert(digits < numeric_limits<I>::digits,
"");
1075 constexpr const auto max = I{1} << (digits-1);
1076 constexpr const auto min = -max;
1077 const auto negative = t < T{0};
1078 if (min <= t && t <= max && t != 0 && t == t)
1080 t =
static_cast<T
>(
static_cast<I
>(t));
1081 if (t == 0 && negative)
1087template <std::
intmax_t Xp, std::
intmax_t Yp>
1090 static const std::intmax_t value = static_gcd<Yp, Xp % Yp>::value;
1093template <std::
intmax_t Xp>
1094struct static_gcd<Xp, 0>
1096 static const std::intmax_t value = Xp;
1100struct static_gcd<0, 0>
1102 static const std::intmax_t value = 1;
1105template <
class R1,
class R2>
1109 static const std::intmax_t gcd_n1_n2 = static_gcd<R1::num, R2::num>::value;
1110 static const std::intmax_t gcd_d1_d2 = static_gcd<R1::den, R2::den>::value;
1111 static const std::intmax_t n1 = R1::num / gcd_n1_n2;
1112 static const std::intmax_t d1 = R1::den / gcd_d1_d2;
1113 static const std::intmax_t n2 = R2::num / gcd_n1_n2;
1114 static const std::intmax_t d2 = R2::den / gcd_d1_d2;
1115#ifdef __cpp_constexpr
1116 static const std::intmax_t max = std::numeric_limits<std::intmax_t>::max();
1118 static const std::intmax_t max = LLONG_MAX;
1121 template <std::
intmax_t Xp, std::
intmax_t Yp,
bool overflow>
1124 static const std::intmax_t value = Xp * Yp;
1127 template <std::
intmax_t Xp, std::
intmax_t Yp>
1128 struct mul<Xp, Yp, true>
1130 static const std::intmax_t value = 1;
1134 static const bool value = (n1 <= max / d2) && (n2 <= max / d1);
1135 typedef std::ratio<mul<n1, d2, !value>::value,
1136 mul<n2, d1, !value>::value> type;
1142template <
class To,
class Rep,
class Period>
1144typename std::enable_if
1146 detail::no_overflow<Period, typename To::period>::value,
1149trunc(
const std::chrono::duration<Rep, Period>& d)
1151 return To{detail::trunc(std::chrono::duration_cast<To>(d).count())};
1154template <
class To,
class Rep,
class Period>
1156typename std::enable_if
1158 !detail::no_overflow<Period, typename To::period>::value,
1161trunc(
const std::chrono::duration<Rep, Period>& d)
1163 using std::chrono::duration_cast;
1164 using std::chrono::duration;
1165 using rep =
typename std::common_type<Rep, typename To::rep>::type;
1166 return To{detail::trunc(duration_cast<To>(duration_cast<duration<rep>>(d)).count())};
1169#ifndef HAS_CHRONO_ROUNDING
1170# if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023918 || (_MSC_FULL_VER >= 190000000 && defined (__clang__)))
1171# define HAS_CHRONO_ROUNDING 1
1172# elif defined(__cpp_lib_chrono) && __cplusplus > 201402 && __cpp_lib_chrono >= 201510
1173# define HAS_CHRONO_ROUNDING 1
1174# elif defined(_LIBCPP_VERSION) && __cplusplus > 201402 && _LIBCPP_VERSION >= 3800
1175# define HAS_CHRONO_ROUNDING 1
1177# define HAS_CHRONO_ROUNDING 0
1181#if HAS_CHRONO_ROUNDING == 0
1184template <
class To,
class Rep,
class Period>
1186typename std::enable_if
1188 detail::no_overflow<Period, typename To::period>::value,
1191floor(
const std::chrono::duration<Rep, Period>& d)
1193 auto t = trunc<To>(d);
1199template <
class To,
class Rep,
class Period>
1201typename std::enable_if
1203 !detail::no_overflow<Period, typename To::period>::value,
1206floor(
const std::chrono::duration<Rep, Period>& d)
1208 using rep =
typename std::common_type<Rep, typename To::rep>::type;
1209 return floor<To>(floor<std::chrono::duration<rep>>(d));
1213template <
class To,
class Rep,
class Period>
1216round(
const std::chrono::duration<Rep, Period>& d)
1218 auto t0 = floor<To>(d);
1219 auto t1 = t0 + To{1};
1220 if (t1 == To{0} && t0 < To{0})
1222 auto diff0 = d - t0;
1223 auto diff1 = t1 - d;
1226 if (t0 - trunc<To>(t0/2)*2 == To{0})
1236template <
class To,
class Rep,
class Period>
1239ceil(
const std::chrono::duration<Rep, Period>& d)
1241 auto t = trunc<To>(d);
1247template <
class Rep,
class Period,
1248 class =
typename std::enable_if
1250 std::numeric_limits<Rep>::is_signed
1253std::chrono::duration<Rep, Period>
1254abs(std::chrono::duration<Rep, Period> d)
1256 return d >= d.zero() ? d : -d;
1260template <
class To,
class Clock,
class FromDuration>
1262std::chrono::time_point<Clock, To>
1263floor(
const std::chrono::time_point<Clock, FromDuration>& tp)
1265 using std::chrono::time_point;
1266 return time_point<Clock, To>{gul17::date::floor<To>(tp.time_since_epoch())};
1270template <
class To,
class Clock,
class FromDuration>
1272std::chrono::time_point<Clock, To>
1273round(
const std::chrono::time_point<Clock, FromDuration>& tp)
1275 using std::chrono::time_point;
1276 return time_point<Clock, To>{round<To>(tp.time_since_epoch())};
1280template <
class To,
class Clock,
class FromDuration>
1282std::chrono::time_point<Clock, To>
1283ceil(
const std::chrono::time_point<Clock, FromDuration>& tp)
1285 using std::chrono::time_point;
1286 return time_point<Clock, To>{ceil<To>(tp.time_since_epoch())};
1291using std::chrono::floor;
1292using std::chrono::ceil;
1293using std::chrono::round;
1294using std::chrono::abs;
1301template <
class To,
class Rep,
class Period>
1303typename std::enable_if
1305 !std::chrono::treat_as_floating_point<typename To::rep>::value,
1308round_i(
const std::chrono::duration<Rep, Period>& d)
1310 return round<To>(d);
1313template <
class To,
class Rep,
class Period>
1315typename std::enable_if
1317 std::chrono::treat_as_floating_point<typename To::rep>::value,
1320round_i(
const std::chrono::duration<Rep, Period>& d)
1325template <
class To,
class Clock,
class FromDuration>
1327std::chrono::time_point<Clock, To>
1328round_i(
const std::chrono::time_point<Clock, FromDuration>& tp)
1330 using std::chrono::time_point;
1331 return time_point<Clock, To>{round_i<To>(tp.time_since_epoch())};
1337template <
class To,
class Clock,
class FromDuration>
1339std::chrono::time_point<Clock, To>
1340trunc(
const std::chrono::time_point<Clock, FromDuration>& tp)
1342 using std::chrono::time_point;
1343 return time_point<Clock, To>{trunc<To>(tp.time_since_epoch())};
1348constexpr inline day::day(
unsigned d) noexcept : d_(
static_cast<decltype(d_)
>(d)) {}
1349constexpr inline day& day::operator++() noexcept {++d_;
return *
this;}
1350constexpr inline day day::operator++(
int)
noexcept {
auto tmp(*
this); ++(*this);
return tmp;}
1351constexpr inline day& day::operator--() noexcept {--d_;
return *
this;}
1352constexpr inline day day::operator--(
int)
noexcept {
auto tmp(*
this); --(*this);
return tmp;}
1353constexpr inline day& day::operator+=(
const days& d)
noexcept {*
this = *
this + d;
return *
this;}
1354constexpr inline day& day::operator-=(
const days& d)
noexcept {*
this = *
this - d;
return *
this;}
1355constexpr inline day::operator unsigned() const noexcept {
return d_;}
1356constexpr inline bool day::ok() const noexcept {
return 1 <= d_ && d_ <= 31;}
1358constexpr inline bool
1359operator==(
const day& x,
const day& y)
noexcept
1361 return static_cast<unsigned>(x) ==
static_cast<unsigned>(y);
1364constexpr inline bool
1365operator!=(
const day& x,
const day& y)
noexcept
1370constexpr inline bool
1371operator<(
const day& x,
const day& y)
noexcept
1373 return static_cast<unsigned>(x) <
static_cast<unsigned>(y);
1376constexpr inline bool
1377operator>(
const day& x,
const day& y)
noexcept
1382constexpr inline bool
1383operator<=(
const day& x,
const day& y)
noexcept
1388constexpr inline bool
1389operator>=(
const day& x,
const day& y)
noexcept
1394constexpr inline days
1395operator-(
const day& x,
const day& y)
noexcept
1397 return days{
static_cast<days::rep
>(
static_cast<unsigned>(x)
1398 -
static_cast<unsigned>(y))};
1402operator+(
const day& x,
const days& y)
noexcept
1404 return day{
static_cast<unsigned>(x) +
static_cast<unsigned>(y.count())};
1408operator+(
const days& x,
const day& y)
noexcept
1414operator-(
const day& x,
const days& y)
noexcept
1422template<
class CharT,
class Traits>
1423std::basic_ostream<CharT, Traits>&
1424low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const day& d)
1426 detail::save_ostream<CharT, Traits> _(os);
1428 os.flags(std::ios::dec | std::ios::right);
1430 os << static_cast<unsigned>(d);
1436template<
class CharT,
class Traits>
1438std::basic_ostream<CharT, Traits>&
1439operator<<(std::basic_ostream<CharT, Traits>& os,
const day& d)
1441 detail::low_level_fmt(os, d);
1443 os <<
" is not a valid day";
1449constexpr inline month::month(
unsigned m) noexcept : m_(
static_cast<decltype(m_)
>(m)) {}
1450constexpr inline month& month::operator++() noexcept {*
this += months{1};
return *
this;}
1451constexpr inline month month::operator++(
int)
noexcept {
auto tmp(*
this); ++(*this);
return tmp;}
1452constexpr inline month& month::operator--() noexcept {*
this -= months{1};
return *
this;}
1453constexpr inline month month::operator--(
int)
noexcept {
auto tmp(*
this); --(*this);
return tmp;}
1455constexpr inline month&
1456month::operator+=(
const months& m)
noexcept
1462constexpr inline month&
1463month::operator-=(
const months& m)
noexcept
1469constexpr inline month::operator unsigned() const noexcept {
return m_;}
1470constexpr inline bool month::ok() const noexcept {
return 1 <= m_ && m_ <= 12;}
1472constexpr inline bool
1473operator==(
const month& x,
const month& y)
noexcept
1475 return static_cast<unsigned>(x) ==
static_cast<unsigned>(y);
1478constexpr inline bool
1479operator!=(
const month& x,
const month& y)
noexcept
1484constexpr inline bool
1485operator<(
const month& x,
const month& y)
noexcept
1487 return static_cast<unsigned>(x) <
static_cast<unsigned>(y);
1490constexpr inline bool
1491operator>(
const month& x,
const month& y)
noexcept
1496constexpr inline bool
1497operator<=(
const month& x,
const month& y)
noexcept
1502constexpr inline bool
1503operator>=(
const month& x,
const month& y)
noexcept
1508constexpr inline months
1509operator-(
const month& x,
const month& y)
noexcept
1511 auto const d =
static_cast<unsigned>(x) -
static_cast<unsigned>(y);
1512 return months(d <= 11 ? d : d + 12);
1515constexpr inline month
1516operator+(
const month& x,
const months& y)
noexcept
1518 auto const mu =
static_cast<long long>(
static_cast<unsigned>(x)) + y.count() - 1;
1519 auto const yr = (mu >= 0 ? mu : mu-11) / 12;
1520 return month{
static_cast<unsigned>(mu - yr * 12 + 1)};
1523constexpr inline month
1524operator+(
const months& x,
const month& y)
noexcept
1529constexpr inline month
1530operator-(
const month& x,
const months& y)
noexcept
1538template<
class CharT,
class Traits>
1539std::basic_ostream<CharT, Traits>&
1540low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const month& m)
1544 CharT fmt[] = {
'%',
'b', 0};
1545 os << format(os.getloc(), fmt, m);
1548 os << static_cast<unsigned>(m);
1554template<
class CharT,
class Traits>
1556std::basic_ostream<CharT, Traits>&
1557operator<<(std::basic_ostream<CharT, Traits>& os,
const month& m)
1559 detail::low_level_fmt(os, m);
1561 os <<
" is not a valid month";
1567constexpr inline year::year(
int y) noexcept : y_(
static_cast<decltype(y_)
>(y)) {}
1568constexpr inline year& year::operator++() noexcept {++y_;
return *
this;}
1569constexpr inline year year::operator++(
int)
noexcept {
auto tmp(*
this); ++(*this);
return tmp;}
1570constexpr inline year& year::operator--() noexcept {--y_;
return *
this;}
1571constexpr inline year year::operator--(
int)
noexcept {
auto tmp(*
this); --(*this);
return tmp;}
1572constexpr inline year& year::operator+=(
const years& y)
noexcept {*
this = *
this + y;
return *
this;}
1573constexpr inline year& year::operator-=(
const years& y)
noexcept {*
this = *
this - y;
return *
this;}
1574constexpr inline year year::operator-() const noexcept {
return year{-y_};}
1575constexpr inline year year::operator+() const noexcept {
return *
this;}
1577constexpr inline bool
1578year::is_leap() const noexcept
1580 return y_ % 4 == 0 && (y_ % 100 != 0 || y_ % 400 == 0);
1583constexpr inline year::operator int() const noexcept {
return y_;}
1585constexpr inline bool
1586year::ok() const noexcept
1588 return y_ != std::numeric_limits<short>::min();
1591constexpr inline bool
1592operator==(
const year& x,
const year& y)
noexcept
1594 return static_cast<int>(x) ==
static_cast<int>(y);
1597constexpr inline bool
1598operator!=(
const year& x,
const year& y)
noexcept
1603constexpr inline bool
1604operator<(
const year& x,
const year& y)
noexcept
1606 return static_cast<int>(x) <
static_cast<int>(y);
1609constexpr inline bool
1610operator>(
const year& x,
const year& y)
noexcept
1615constexpr inline bool
1616operator<=(
const year& x,
const year& y)
noexcept
1621constexpr inline bool
1622operator>=(
const year& x,
const year& y)
noexcept
1627constexpr inline years
1628operator-(
const year& x,
const year& y)
noexcept
1630 return years{
static_cast<int>(x) -
static_cast<int>(y)};
1633constexpr inline year
1634operator+(
const year& x,
const years& y)
noexcept
1636 return year{
static_cast<int>(x) + y.count()};
1639constexpr inline year
1640operator+(
const years& x,
const year& y)
noexcept
1645constexpr inline year
1646operator-(
const year& x,
const years& y)
noexcept
1648 return year{
static_cast<int>(x) - y.count()};
1654template<
class CharT,
class Traits>
1655std::basic_ostream<CharT, Traits>&
1656low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const year& y)
1658 detail::save_ostream<CharT, Traits> _(os);
1660 os.flags(std::ios::dec | std::ios::internal);
1661 os.width(4 + (y < year{0}));
1662 os.imbue(std::locale::classic());
1663 os << static_cast<int>(y);
1669template<
class CharT,
class Traits>
1671std::basic_ostream<CharT, Traits>&
1672operator<<(std::basic_ostream<CharT, Traits>& os,
const year& y)
1674 detail::low_level_fmt(os, y);
1676 os <<
" is not a valid year";
1684weekday::weekday_from_days(
int z)
noexcept
1686 auto u =
static_cast<unsigned>(z);
1687 return static_cast<unsigned char>(z >= -4 ? (u+4) % 7 : u % 7);
1691weekday::weekday(
unsigned wd) noexcept
1692 : wd_(
static_cast<decltype(wd_)
>(wd != 7 ? wd : 0))
1696weekday::weekday(
const sys_days& dp) noexcept
1697 : wd_(weekday_from_days(dp.time_since_epoch().count()))
1701weekday::weekday(
const local_days& dp) noexcept
1702 : wd_(weekday_from_days(dp.time_since_epoch().count()))
1705constexpr inline weekday& weekday::operator++() noexcept {*
this += days{1};
return *
this;}
1706constexpr inline weekday weekday::operator++(
int)
noexcept {
auto tmp(*
this); ++(*this);
return tmp;}
1707constexpr inline weekday& weekday::operator--() noexcept {*
this -= days{1};
return *
this;}
1708constexpr inline weekday weekday::operator--(
int)
noexcept {
auto tmp(*
this); --(*this);
return tmp;}
1710constexpr inline weekday&
1711weekday::operator+=(
const days& d)
noexcept
1717constexpr inline weekday&
1718weekday::operator-=(
const days& d)
noexcept
1724constexpr inline bool weekday::ok() const noexcept {
return wd_ <= 6;}
1726constexpr inline unsigned weekday::c_encoding() const noexcept
1728 return unsigned{wd_};
1731constexpr inline unsigned weekday::iso_encoding() const noexcept
1733 return unsigned{((wd_ == 0u) ? 7u : wd_)};
1736constexpr inline bool
1737operator==(
const weekday& x,
const weekday& y)
noexcept
1739 return x.wd_ == y.wd_;
1742constexpr inline bool
1743operator!=(
const weekday& x,
const weekday& y)
noexcept
1748constexpr inline days
1749operator-(
const weekday& x,
const weekday& y)
noexcept
1751 auto const wdu = x.wd_ - y.wd_;
1752 auto const wk = (wdu >= 0 ? wdu : wdu-6) / 7;
1753 return days{wdu - wk * 7};
1756constexpr inline weekday
1757operator+(
const weekday& x,
const days& y)
noexcept
1759 auto const wdu =
static_cast<long long>(
static_cast<unsigned>(x.wd_)) + y.count();
1760 auto const wk = (wdu >= 0 ? wdu : wdu-6) / 7;
1761 return weekday{
static_cast<unsigned>(wdu - wk * 7)};
1764constexpr inline weekday
1765operator+(
const days& x,
const weekday& y)
noexcept
1770constexpr inline weekday
1771operator-(
const weekday& x,
const days& y)
noexcept
1779template<
class CharT,
class Traits>
1780std::basic_ostream<CharT, Traits>&
1781low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const weekday& wd)
1785 CharT fmt[] = {
'%',
'a', 0};
1786 os << format(fmt, wd);
1789 os << wd.c_encoding();
1795template<
class CharT,
class Traits>
1797std::basic_ostream<CharT, Traits>&
1798operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday& wd)
1800 detail::low_level_fmt(os, wd);
1802 os <<
" is not a valid weekday";
1806#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1807inline namespace literals
1812operator "" _d(
unsigned long long d)
noexcept
1814 return gul17::date::day{
static_cast<unsigned>(d)};
1819operator "" _y(
unsigned long long y)
noexcept
1821 return gul17::date::year(
static_cast<int>(y));
1825constexpr const gul17::date::last_spec last{};
1827constexpr const gul17::date::month jan{1};
1828constexpr const gul17::date::month feb{2};
1829constexpr const gul17::date::month mar{3};
1830constexpr const gul17::date::month apr{4};
1831constexpr const gul17::date::month may{5};
1832constexpr const gul17::date::month jun{6};
1833constexpr const gul17::date::month jul{7};
1834constexpr const gul17::date::month aug{8};
1835constexpr const gul17::date::month sep{9};
1836constexpr const gul17::date::month oct{10};
1837constexpr const gul17::date::month nov{11};
1838constexpr const gul17::date::month dec{12};
1840constexpr const gul17::date::weekday sun{0u};
1841constexpr const gul17::date::weekday mon{1u};
1842constexpr const gul17::date::weekday tue{2u};
1843constexpr const gul17::date::weekday wed{3u};
1844constexpr const gul17::date::weekday thu{4u};
1845constexpr const gul17::date::weekday fri{5u};
1846constexpr const gul17::date::weekday sat{6u};
1848#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1852constexpr const gul17::date::month January{1};
1853constexpr const gul17::date::month February{2};
1854constexpr const gul17::date::month March{3};
1855constexpr const gul17::date::month April{4};
1856constexpr const gul17::date::month May{5};
1857constexpr const gul17::date::month June{6};
1858constexpr const gul17::date::month July{7};
1859constexpr const gul17::date::month August{8};
1860constexpr const gul17::date::month September{9};
1861constexpr const gul17::date::month October{10};
1862constexpr const gul17::date::month November{11};
1863constexpr const gul17::date::month December{12};
1865constexpr const gul17::date::weekday Monday{1};
1866constexpr const gul17::date::weekday Tuesday{2};
1867constexpr const gul17::date::weekday Wednesday{3};
1868constexpr const gul17::date::weekday Thursday{4};
1869constexpr const gul17::date::weekday Friday{5};
1870constexpr const gul17::date::weekday Saturday{6};
1871constexpr const gul17::date::weekday Sunday{7};
1877weekday_indexed::weekday() const noexcept
1879 return gul17::date::weekday{
static_cast<unsigned>(wd_)};
1882constexpr inline unsigned weekday_indexed::index() const noexcept {
return index_;}
1884constexpr inline bool
1885weekday_indexed::ok() const noexcept
1887 return weekday().ok() && 1 <= index_ && index_ <= 5;
1891# pragma GCC diagnostic push
1892# pragma GCC diagnostic ignored "-Wconversion"
1896weekday_indexed::weekday_indexed(
const gul17::date::weekday& wd,
unsigned index) noexcept
1897 : wd_(
static_cast<decltype(wd_)
>(
static_cast<unsigned>(wd.wd_)))
1898 , index_(
static_cast<decltype(index_)
>(index))
1902# pragma GCC diagnostic pop
1908template<
class CharT,
class Traits>
1909std::basic_ostream<CharT, Traits>&
1910low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const weekday_indexed& wdi)
1912 return low_level_fmt(os, wdi.weekday()) <<
'[' << wdi.index() <<
']';
1917template<
class CharT,
class Traits>
1919std::basic_ostream<CharT, Traits>&
1920operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday_indexed& wdi)
1922 detail::low_level_fmt(os, wdi);
1924 os <<
" is not a valid weekday_indexed";
1928constexpr inline weekday_indexed
1929weekday::operator[](
unsigned index)
const noexcept
1931 return {*
this, index};
1934constexpr inline bool
1935operator==(
const weekday_indexed& x,
const weekday_indexed& y)
noexcept
1937 return x.weekday() == y.weekday() && x.index() == y.index();
1940constexpr inline bool
1941operator!=(
const weekday_indexed& x,
const weekday_indexed& y)
noexcept
1948constexpr inline gul17::date::weekday weekday_last::weekday() const noexcept {
return wd_;}
1949constexpr inline bool weekday_last::ok() const noexcept {
return wd_.ok();}
1950constexpr inline weekday_last::weekday_last(
const gul17::date::weekday& wd) noexcept : wd_(wd) {}
1952constexpr inline bool
1953operator==(
const weekday_last& x,
const weekday_last& y)
noexcept
1955 return x.weekday() == y.weekday();
1958constexpr inline bool
1959operator!=(
const weekday_last& x,
const weekday_last& y)
noexcept
1967template<
class CharT,
class Traits>
1968std::basic_ostream<CharT, Traits>&
1969low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const weekday_last& wdl)
1971 return low_level_fmt(os, wdl.weekday()) <<
"[last]";
1976template<
class CharT,
class Traits>
1978std::basic_ostream<CharT, Traits>&
1979operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday_last& wdl)
1981 detail::low_level_fmt(os, wdl);
1983 os <<
" is not a valid weekday_last";
1989weekday::operator[](last_spec)
const noexcept
1991 return weekday_last{*
this};
1997year_month::year_month(
const gul17::date::year& y,
const gul17::date::month& m) noexcept
2002constexpr inline year year_month::year() const noexcept {
return y_;}
2003constexpr inline month year_month::month() const noexcept {
return m_;}
2004constexpr inline bool year_month::ok() const noexcept {
return y_.ok() && m_.ok();}
2007constexpr inline year_month&
2008year_month::operator+=(
const months& dm)
noexcept
2015constexpr inline year_month&
2016year_month::operator-=(
const months& dm)
noexcept
2022constexpr inline year_month&
2023year_month::operator+=(
const years& dy)
noexcept
2029constexpr inline year_month&
2030year_month::operator-=(
const years& dy)
noexcept
2036constexpr inline bool
2037operator==(
const year_month& x,
const year_month& y)
noexcept
2039 return x.year() == y.year() && x.month() == y.month();
2042constexpr inline bool
2043operator!=(
const year_month& x,
const year_month& y)
noexcept
2048constexpr inline bool
2049operator<(
const year_month& x,
const year_month& y)
noexcept
2051 return x.year() < y.year() ? true
2052 : (x.year() > y.year() ? false
2053 : (x.month() < y.month()));
2056constexpr inline bool
2057operator>(
const year_month& x,
const year_month& y)
noexcept
2062constexpr inline bool
2063operator<=(
const year_month& x,
const year_month& y)
noexcept
2068constexpr inline bool
2069operator>=(
const year_month& x,
const year_month& y)
noexcept
2075constexpr inline year_month
2076operator+(
const year_month& ym,
const months& dm)
noexcept
2078 auto dmi =
static_cast<int>(
static_cast<unsigned>(ym.month())) - 1 + dm.count();
2079 auto dy = (dmi >= 0 ? dmi : dmi-11) / 12;
2080 dmi = dmi - dy * 12 + 1;
2081 return (ym.year() + years(dy)) / month(
static_cast<unsigned>(dmi));
2085constexpr inline year_month
2086operator+(
const months& dm,
const year_month& ym)
noexcept
2092constexpr inline year_month
2093operator-(
const year_month& ym,
const months& dm)
noexcept
2098constexpr inline months
2099operator-(
const year_month& x,
const year_month& y)
noexcept
2101 return (x.year() - y.year()) +
2102 months(
static_cast<unsigned>(x.month()) -
static_cast<unsigned>(y.month()));
2105constexpr inline year_month
2106operator+(
const year_month& ym,
const years& dy)
noexcept
2108 return (ym.year() + dy) / ym.month();
2111constexpr inline year_month
2112operator+(
const years& dy,
const year_month& ym)
noexcept
2117constexpr inline year_month
2118operator-(
const year_month& ym,
const years& dy)
noexcept
2126template<
class CharT,
class Traits>
2127std::basic_ostream<CharT, Traits>&
2128low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const year_month& ym)
2130 low_level_fmt(os, ym.year()) <<
'/';
2131 return low_level_fmt(os, ym.month());
2136template<
class CharT,
class Traits>
2138std::basic_ostream<CharT, Traits>&
2139operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month& ym)
2141 detail::low_level_fmt(os, ym);
2143 os <<
" is not a valid year_month";
2150month_day::month_day(
const gul17::date::month& m,
const gul17::date::day& d) noexcept
2155constexpr inline gul17::date::month month_day::month() const noexcept {
return m_;}
2156constexpr inline gul17::date::day month_day::day() const noexcept {
return d_;}
2158constexpr inline bool
2159month_day::ok() const noexcept
2161 constexpr const gul17::date::day d[] =
2163 gul17::date::day(31), gul17::date::day(29), gul17::date::day(31),
2164 gul17::date::day(30), gul17::date::day(31), gul17::date::day(30),
2165 gul17::date::day(31), gul17::date::day(31), gul17::date::day(30),
2166 gul17::date::day(31), gul17::date::day(30), gul17::date::day(31)
2168 return m_.ok() && gul17::date::day{1} <= d_ && d_ <= d[static_cast<unsigned>(m_)-1];
2171constexpr inline bool
2172operator==(
const month_day& x,
const month_day& y)
noexcept
2174 return x.month() == y.month() && x.day() == y.day();
2177constexpr inline bool
2178operator!=(
const month_day& x,
const month_day& y)
noexcept
2183constexpr inline bool
2184operator<(
const month_day& x,
const month_day& y)
noexcept
2186 return x.month() < y.month() ? true
2187 : (x.month() > y.month() ? false
2188 : (x.day() < y.day()));
2191constexpr inline bool
2192operator>(
const month_day& x,
const month_day& y)
noexcept
2197constexpr inline bool
2198operator<=(
const month_day& x,
const month_day& y)
noexcept
2203constexpr inline bool
2204operator>=(
const month_day& x,
const month_day& y)
noexcept
2212template<
class CharT,
class Traits>
2213std::basic_ostream<CharT, Traits>&
2214low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const month_day& md)
2216 low_level_fmt(os, md.month()) <<
'/';
2217 return low_level_fmt(os, md.day());
2222template<
class CharT,
class Traits>
2224std::basic_ostream<CharT, Traits>&
2225operator<<(std::basic_ostream<CharT, Traits>& os,
const month_day& md)
2227 detail::low_level_fmt(os, md);
2229 os <<
" is not a valid month_day";
2235constexpr inline month month_day_last::month() const noexcept {
return m_;}
2236constexpr inline bool month_day_last::ok() const noexcept {
return m_.ok();}
2237constexpr inline month_day_last::month_day_last(
const gul17::date::month& m) noexcept : m_(m) {}
2239constexpr inline bool
2240operator==(
const month_day_last& x,
const month_day_last& y)
noexcept
2242 return x.month() == y.month();
2245constexpr inline bool
2246operator!=(
const month_day_last& x,
const month_day_last& y)
noexcept
2251constexpr inline bool
2252operator<(
const month_day_last& x,
const month_day_last& y)
noexcept
2254 return x.month() < y.month();
2257constexpr inline bool
2258operator>(
const month_day_last& x,
const month_day_last& y)
noexcept
2263constexpr inline bool
2264operator<=(
const month_day_last& x,
const month_day_last& y)
noexcept
2269constexpr inline bool
2270operator>=(
const month_day_last& x,
const month_day_last& y)
noexcept
2278template<
class CharT,
class Traits>
2279std::basic_ostream<CharT, Traits>&
2280low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const month_day_last& mdl)
2282 return low_level_fmt(os, mdl.month()) <<
"/last";
2287template<
class CharT,
class Traits>
2289std::basic_ostream<CharT, Traits>&
2290operator<<(std::basic_ostream<CharT, Traits>& os,
const month_day_last& mdl)
2292 detail::low_level_fmt(os, mdl);
2294 os <<
" is not a valid month_day_last";
2301month_weekday::month_weekday(
const gul17::date::month& m,
2302 const gul17::date::weekday_indexed& wdi) noexcept
2307constexpr inline month month_weekday::month() const noexcept {
return m_;}
2309constexpr inline weekday_indexed
2310month_weekday::weekday_indexed() const noexcept
2315constexpr inline bool
2316month_weekday::ok() const noexcept
2318 return m_.ok() && wdi_.ok();
2321constexpr inline bool
2322operator==(
const month_weekday& x,
const month_weekday& y)
noexcept
2324 return x.month() == y.month() && x.weekday_indexed() == y.weekday_indexed();
2327constexpr inline bool
2328operator!=(
const month_weekday& x,
const month_weekday& y)
noexcept
2336template<
class CharT,
class Traits>
2337std::basic_ostream<CharT, Traits>&
2338low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const month_weekday& mwd)
2340 low_level_fmt(os, mwd.month()) <<
'/';
2341 return low_level_fmt(os, mwd.weekday_indexed());
2346template<
class CharT,
class Traits>
2348std::basic_ostream<CharT, Traits>&
2349operator<<(std::basic_ostream<CharT, Traits>& os,
const month_weekday& mwd)
2351 detail::low_level_fmt(os, mwd);
2353 os <<
" is not a valid month_weekday";
2360month_weekday_last::month_weekday_last(
const gul17::date::month& m,
2361 const gul17::date::weekday_last& wdl) noexcept
2366constexpr inline month month_weekday_last::month() const noexcept {
return m_;}
2368constexpr inline weekday_last
2369month_weekday_last::weekday_last() const noexcept
2374constexpr inline bool
2375month_weekday_last::ok() const noexcept
2377 return m_.ok() && wdl_.ok();
2380constexpr inline bool
2381operator==(
const month_weekday_last& x,
const month_weekday_last& y)
noexcept
2383 return x.month() == y.month() && x.weekday_last() == y.weekday_last();
2386constexpr inline bool
2387operator!=(
const month_weekday_last& x,
const month_weekday_last& y)
noexcept
2395template<
class CharT,
class Traits>
2396std::basic_ostream<CharT, Traits>&
2397low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const month_weekday_last& mwdl)
2399 low_level_fmt(os, mwdl.month()) <<
'/';
2400 return low_level_fmt(os, mwdl.weekday_last());
2405template<
class CharT,
class Traits>
2407std::basic_ostream<CharT, Traits>&
2408operator<<(std::basic_ostream<CharT, Traits>& os,
const month_weekday_last& mwdl)
2410 detail::low_level_fmt(os, mwdl);
2412 os <<
" is not a valid month_weekday_last";
2418constexpr inline year_month_day_last::year_month_day_last(
const gul17::date::year& y,
2419 const gul17::date::month_day_last& mdl) noexcept
2425constexpr inline year_month_day_last&
2426year_month_day_last::operator+=(
const months& m)
noexcept
2433constexpr inline year_month_day_last&
2434year_month_day_last::operator-=(
const months& m)
noexcept
2440constexpr inline year_month_day_last&
2441year_month_day_last::operator+=(
const years& y)
noexcept
2447constexpr inline year_month_day_last&
2448year_month_day_last::operator-=(
const years& y)
noexcept
2454constexpr inline year year_month_day_last::year() const noexcept {
return y_;}
2455constexpr inline month year_month_day_last::month() const noexcept {
return mdl_.month();}
2459year_month_day_last::month_day_last() const noexcept
2466year_month_day_last::day() const noexcept
2468 constexpr const gul17::date::day d[] =
2470 gul17::date::day(31), gul17::date::day(28), gul17::date::day(31),
2471 gul17::date::day(30), gul17::date::day(31), gul17::date::day(30),
2472 gul17::date::day(31), gul17::date::day(31), gul17::date::day(30),
2473 gul17::date::day(31), gul17::date::day(30), gul17::date::day(31)
2475 return (month() != February || !y_.is_leap()) && mdl_.ok() ?
2476 d[
static_cast<unsigned>(month()) - 1] :
gul17::date::day{29};
2480year_month_day_last::operator sys_days() const noexcept
2482 return sys_days(year()/month()/day());
2486year_month_day_last::operator local_days() const noexcept
2488 return local_days(year()/month()/day());
2491constexpr inline bool
2492year_month_day_last::ok() const noexcept
2494 return y_.ok() && mdl_.ok();
2497constexpr inline bool
2498operator==(
const year_month_day_last& x,
const year_month_day_last& y)
noexcept
2500 return x.year() == y.year() && x.month_day_last() == y.month_day_last();
2503constexpr inline bool
2504operator!=(
const year_month_day_last& x,
const year_month_day_last& y)
noexcept
2509constexpr inline bool
2510operator<(
const year_month_day_last& x,
const year_month_day_last& y)
noexcept
2512 return x.year() < y.year() ? true
2513 : (x.year() > y.year() ? false
2514 : (x.month_day_last() < y.month_day_last()));
2517constexpr inline bool
2518operator>(
const year_month_day_last& x,
const year_month_day_last& y)
noexcept
2523constexpr inline bool
2524operator<=(
const year_month_day_last& x,
const year_month_day_last& y)
noexcept
2529constexpr inline bool
2530operator>=(
const year_month_day_last& x,
const year_month_day_last& y)
noexcept
2538template<
class CharT,
class Traits>
2539std::basic_ostream<CharT, Traits>&
2540low_level_fmt(std::basic_ostream<CharT, Traits>& os,
const year_month_day_last& ymdl)
2542 low_level_fmt(os, ymdl.year()) <<
'/';
2543 return low_level_fmt(os, ymdl.month_day_last());
2548template<
class CharT,
class Traits>
2550std::basic_ostream<CharT, Traits>&
2551operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_day_last& ymdl)
2553 detail::low_level_fmt(os, ymdl);
2555 os <<
" is not a valid year_month_day_last";
2562operator+(
const year_month_day_last& ymdl,
const months& dm)
noexcept
2564 return (ymdl.year() / ymdl.month() + dm) / last;
2570operator+(
const months& dm,
const year_month_day_last& ymdl)
noexcept
2578operator-(
const year_month_day_last& ymdl,
const months& dm)
noexcept
2580 return ymdl + (-dm);
2585operator+(
const year_month_day_last& ymdl,
const years& dy)
noexcept
2587 return {ymdl.year()+dy, ymdl.month_day_last()};
2592operator+(
const years& dy,
const year_month_day_last& ymdl)
noexcept
2599operator-(
const year_month_day_last& ymdl,
const years& dy)
noexcept
2601 return ymdl + (-dy);
2607year_month_day::year_month_day(
const gul17::date::year& y,
const gul17::date::month& m,
2608 const gul17::date::day& d) noexcept
2615year_month_day::year_month_day(
const year_month_day_last& ymdl) noexcept
2622year_month_day::year_month_day(sys_days dp) noexcept
2623 : year_month_day(from_days(dp.time_since_epoch()))
2627year_month_day::year_month_day(local_days dp) noexcept
2628 : year_month_day(from_days(dp.time_since_epoch()))
2631constexpr inline year year_month_day::year() const noexcept {
return y_;}
2632constexpr inline month year_month_day::month() const noexcept {
return m_;}
2633constexpr inline day year_month_day::day() const noexcept {
return d_;}
2638year_month_day::operator+=(
const months& m)
noexcept
2647year_month_day::operator-=(
const months& m)
noexcept
2655year_month_day::operator+=(
const years& y)
noexcept
2663year_month_day::operator-=(
const years& y)
noexcept
2671year_month_day::to_days() const noexcept
2673 static_assert(std::numeric_limits<unsigned>::digits >= 18,
2674 "This algorithm has not been ported to a 16 bit unsigned integer");
2675 static_assert(std::numeric_limits<int>::digits >= 20,
2676 "This algorithm has not been ported to a 16 bit signed integer");
2677 auto const y =
static_cast<int>(y_) - (m_ <= February);
2678 auto const m =
static_cast<unsigned>(m_);
2679 auto const d =
static_cast<unsigned>(d_);
2680 auto const era = (y >= 0 ? y : y-399) / 400;
2681 auto const yoe =
static_cast<unsigned>(y - era * 400);
2682 auto const doy = (153*(m > 2 ? m-3 : m+9) + 2)/5 + d-1;
2683 auto const doe = yoe * 365 + yoe/4 - yoe/100 + doy;
2684 return days{era * 146097 +
static_cast<int>(doe) - 719468};
2688year_month_day::operator sys_days() const noexcept
2690 return sys_days{to_days()};
2694year_month_day::operator local_days() const noexcept
2696 return local_days{to_days()};
2699constexpr inline bool
2700year_month_day::ok() const noexcept
2702 if (!(y_.ok() && m_.ok()))
2704 return gul17::date::day{1} <= d_ && d_ <= (y_ / m_ / last).day();
2707constexpr inline bool
2708operator==(
const year_month_day& x,
const year_month_day& y)
noexcept
2710 return x.year() == y.year() && x.month() == y.month() && x.day() == y.day();
2713constexpr inline bool
2714operator!=(
const year_month_day& x,
const year_month_day& y)
noexcept
2719constexpr inline bool
2720operator<(
const year_month_day& x,
const year_month_day& y)
noexcept
2722 return x.year() < y.year() ? true
2723 : (x.year() > y.year() ? false
2724 : (x.month() < y.month() ? true
2725 : (x.month() > y.month() ? false
2726 : (x.day() < y.day()))));
2729constexpr inline bool
2730operator>(
const year_month_day& x,
const year_month_day& y)
noexcept
2735constexpr inline bool
2736operator<=(
const year_month_day& x,
const year_month_day& y)
noexcept
2741constexpr inline bool
2742operator>=(
const year_month_day& x,
const year_month_day& y)
noexcept
2747template<
class CharT,
class Traits>
2749std::basic_ostream<CharT, Traits>&
2750operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_day& ymd)
2752 detail::save_ostream<CharT, Traits> _(os);
2754 os.flags(std::ios::dec | std::ios::right);
2755 os.imbue(std::locale::classic());
2756 os << static_cast<int>(ymd.year()) <<
'-';
2758 os << static_cast<unsigned>(ymd.month()) <<
'-';
2760 os << static_cast<unsigned>(ymd.day());
2762 os <<
" is not a valid year_month_day";
2768year_month_day::from_days(days dp)
noexcept
2770 static_assert(std::numeric_limits<unsigned>::digits >= 18,
2771 "This algorithm has not been ported to a 16 bit unsigned integer");
2772 static_assert(std::numeric_limits<int>::digits >= 20,
2773 "This algorithm has not been ported to a 16 bit signed integer");
2774 auto const z = dp.count() + 719468;
2775 auto const era = (z >= 0 ? z : z - 146096) / 146097;
2776 auto const doe =
static_cast<unsigned>(z - era * 146097);
2777 auto const yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365;
2778 auto const y =
static_cast<days::rep
>(yoe) + era * 400;
2779 auto const doy = doe - (365*yoe + yoe/4 - yoe/100);
2780 auto const mp = (5*doy + 2)/153;
2781 auto const d = doy - (153*mp+2)/5 + 1;
2782 auto const m = mp < 10 ? mp+3 : mp-9;
2783 return year_month_day{gul17::date::year{y + (m <= 2)}, gul17::date::month(m), gul17::date::day(d)};
2789operator+(
const year_month_day& ymd,
const months& dm)
noexcept
2791 return (ymd.year() / ymd.month() + dm) / ymd.day();
2797operator+(
const months& dm,
const year_month_day& ymd)
noexcept
2805operator-(
const year_month_day& ymd,
const months& dm)
noexcept
2812operator+(
const year_month_day& ymd,
const years& dy)
noexcept
2814 return (ymd.year() + dy) / ymd.month() / ymd.day();
2819operator+(
const years& dy,
const year_month_day& ymd)
noexcept
2826operator-(
const year_month_day& ymd,
const years& dy)
noexcept
2834year_month_weekday::year_month_weekday(
const gul17::date::year& y,
const gul17::date::month& m,
2835 const gul17::date::weekday_indexed& wdi)
2843year_month_weekday::year_month_weekday(
const sys_days& dp) noexcept
2844 : year_month_weekday(from_days(dp.time_since_epoch()))
2848year_month_weekday::year_month_weekday(
const local_days& dp) noexcept
2849 : year_month_weekday(from_days(dp.time_since_epoch()))
2855year_month_weekday::operator+=(
const months& m)
noexcept
2864year_month_weekday::operator-=(
const months& m)
noexcept
2872year_month_weekday::operator+=(
const years& y)
noexcept
2880year_month_weekday::operator-=(
const years& y)
noexcept
2886constexpr inline year year_month_weekday::year() const noexcept {
return y_;}
2887constexpr inline month year_month_weekday::month() const noexcept {
return m_;}
2891year_month_weekday::weekday() const noexcept
2893 return wdi_.weekday();
2898year_month_weekday::index() const noexcept
2900 return wdi_.index();
2905year_month_weekday::weekday_indexed() const noexcept
2911year_month_weekday::operator sys_days() const noexcept
2913 return sys_days{to_days()};
2917year_month_weekday::operator local_days() const noexcept
2919 return local_days{to_days()};
2922constexpr inline bool
2923year_month_weekday::ok() const noexcept
2925 if (!y_.ok() || !m_.ok() || !wdi_.weekday().ok() || wdi_.index() < 1)
2927 if (wdi_.index() <= 4)
2929 auto d2 = wdi_.weekday() - gul17::date::weekday(
static_cast<sys_days
>(y_/m_/1)) +
2930 days((wdi_.index()-1)*7 + 1);
2931 return static_cast<unsigned>(d2.count()) <=
static_cast<unsigned>((y_/m_/last).day());
2936year_month_weekday::from_days(days d)
noexcept
2939 auto const wd = gul17::date::weekday(dp);
2940 auto const ymd = year_month_day(dp);
2941 return {ymd.year(), ymd.month(), wd[(
static_cast<unsigned>(ymd.day())-1)/7+1]};
2946year_month_weekday::to_days() const noexcept
2948 auto d = sys_days(y_/m_/1);
2949 return (d + (wdi_.weekday() - gul17::date::weekday(d) + days{(wdi_.index()-1)*7})
2950 ).time_since_epoch();
2953constexpr inline bool
2954operator==(
const year_month_weekday& x,
const year_month_weekday& y)
noexcept
2956 return x.year() == y.year() && x.month() == y.month() &&
2957 x.weekday_indexed() == y.weekday_indexed();
2960constexpr inline bool
2961operator!=(
const year_month_weekday& x,
const year_month_weekday& y)
noexcept
2966template<
class CharT,
class Traits>
2968std::basic_ostream<CharT, Traits>&
2969operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_weekday& ymwdi)
2971 detail::low_level_fmt(os, ymwdi.year()) <<
'/';
2972 detail::low_level_fmt(os, ymwdi.month()) <<
'/';
2973 detail::low_level_fmt(os, ymwdi.weekday_indexed());
2975 os <<
" is not a valid year_month_weekday";
2982operator+(
const year_month_weekday& ymwd,
const months& dm)
noexcept
2984 return (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed();
2990operator+(
const months& dm,
const year_month_weekday& ymwd)
noexcept
2998operator-(
const year_month_weekday& ymwd,
const months& dm)
noexcept
3000 return ymwd + (-dm);
3005operator+(
const year_month_weekday& ymwd,
const years& dy)
noexcept
3007 return {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()};
3012operator+(
const years& dy,
const year_month_weekday& ymwd)
noexcept
3019operator-(
const year_month_weekday& ymwd,
const years& dy)
noexcept
3021 return ymwd + (-dy);
3027year_month_weekday_last::year_month_weekday_last(
const gul17::date::year& y,
3028 const gul17::date::month& m,
3029 const gul17::date::weekday_last& wdl) noexcept
3037year_month_weekday_last&
3038year_month_weekday_last::operator+=(
const months& m)
noexcept
3046year_month_weekday_last&
3047year_month_weekday_last::operator-=(
const months& m)
noexcept
3054year_month_weekday_last&
3055year_month_weekday_last::operator+=(
const years& y)
noexcept
3062year_month_weekday_last&
3063year_month_weekday_last::operator-=(
const years& y)
noexcept
3069constexpr inline year year_month_weekday_last::year() const noexcept {
return y_;}
3070constexpr inline month year_month_weekday_last::month() const noexcept {
return m_;}
3074year_month_weekday_last::weekday() const noexcept
3076 return wdl_.weekday();
3081year_month_weekday_last::weekday_last() const noexcept
3087year_month_weekday_last::operator sys_days() const noexcept
3089 return sys_days{to_days()};
3093year_month_weekday_last::operator local_days() const noexcept
3095 return local_days{to_days()};
3098constexpr inline bool
3099year_month_weekday_last::ok() const noexcept
3101 return y_.ok() && m_.ok() && wdl_.ok();
3106year_month_weekday_last::to_days() const noexcept
3108 auto const d = sys_days(y_/m_/last);
3109 return (d - (gul17::date::weekday{d} - wdl_.weekday())).time_since_epoch();
3112constexpr inline bool
3113operator==(
const year_month_weekday_last& x,
const year_month_weekday_last& y)
noexcept
3115 return x.year() == y.year() && x.month() == y.month() &&
3116 x.weekday_last() == y.weekday_last();
3119constexpr inline bool
3120operator!=(
const year_month_weekday_last& x,
const year_month_weekday_last& y)
noexcept
3125template<
class CharT,
class Traits>
3127std::basic_ostream<CharT, Traits>&
3128operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_weekday_last& ymwdl)
3130 detail::low_level_fmt(os, ymwdl.year()) <<
'/';
3131 detail::low_level_fmt(os, ymwdl.month()) <<
'/';
3132 detail::low_level_fmt(os, ymwdl.weekday_last());
3134 os <<
" is not a valid year_month_weekday_last";
3140year_month_weekday_last
3141operator+(
const year_month_weekday_last& ymwdl,
const months& dm)
noexcept
3143 return (ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last();
3148year_month_weekday_last
3149operator+(
const months& dm,
const year_month_weekday_last& ymwdl)
noexcept
3156year_month_weekday_last
3157operator-(
const year_month_weekday_last& ymwdl,
const months& dm)
noexcept
3159 return ymwdl + (-dm);
3163year_month_weekday_last
3164operator+(
const year_month_weekday_last& ymwdl,
const years& dy)
noexcept
3166 return {ymwdl.year()+dy, ymwdl.month(), ymwdl.weekday_last()};
3170year_month_weekday_last
3171operator+(
const years& dy,
const year_month_weekday_last& ymwdl)
noexcept
3177year_month_weekday_last
3178operator-(
const year_month_weekday_last& ymwdl,
const years& dy)
noexcept
3180 return ymwdl + (-dy);
3187operator/(
const year& y,
const month& m)
noexcept
3194operator/(
const year& y,
int m)
noexcept
3196 return y / month(
static_cast<unsigned>(m));
3203operator/(
const month& m,
const day& d)
noexcept
3210operator/(
const day& d,
const month& m)
noexcept
3217operator/(
const month& m,
int d)
noexcept
3219 return m / day(
static_cast<unsigned>(d));
3224operator/(
int m,
const day& d)
noexcept
3226 return month(
static_cast<unsigned>(m)) / d;
3229constexpr inline month_day operator/(
const day& d,
int m)
noexcept {
return m / d;}
3235operator/(
const month& m, last_spec)
noexcept
3237 return month_day_last{m};
3242operator/(last_spec,
const month& m)
noexcept
3249operator/(
int m, last_spec)
noexcept
3251 return month(
static_cast<unsigned>(m))/last;
3256operator/(last_spec,
int m)
noexcept
3265operator/(
const month& m,
const weekday_indexed& wdi)
noexcept
3272operator/(
const weekday_indexed& wdi,
const month& m)
noexcept
3279operator/(
int m,
const weekday_indexed& wdi)
noexcept
3281 return month(
static_cast<unsigned>(m)) / wdi;
3286operator/(
const weekday_indexed& wdi,
int m)
noexcept
3295operator/(
const month& m,
const weekday_last& wdl)
noexcept
3302operator/(
const weekday_last& wdl,
const month& m)
noexcept
3309operator/(
int m,
const weekday_last& wdl)
noexcept
3311 return month(
static_cast<unsigned>(m)) / wdl;
3316operator/(
const weekday_last& wdl,
int m)
noexcept
3325operator/(
const year_month& ym,
const day& d)
noexcept
3327 return {ym.year(), ym.month(), d};
3332operator/(
const year_month& ym,
int d)
noexcept
3334 return ym / day(
static_cast<unsigned>(d));
3339operator/(
const year& y,
const month_day& md)
noexcept
3341 return y / md.month() / md.day();
3346operator/(
int y,
const month_day& md)
noexcept
3348 return year(y) / md;
3353operator/(
const month_day& md,
const year& y)
noexcept
3360operator/(
const month_day& md,
int y)
noexcept
3362 return year(y) / md;
3369operator/(
const year_month& ym, last_spec)
noexcept
3371 return {ym.year(), month_day_last{ym.month()}};
3376operator/(
const year& y,
const month_day_last& mdl)
noexcept
3383operator/(
int y,
const month_day_last& mdl)
noexcept
3385 return year(y) / mdl;
3390operator/(
const month_day_last& mdl,
const year& y)
noexcept
3397operator/(
const month_day_last& mdl,
int y)
noexcept
3399 return year(y) / mdl;
3406operator/(
const year_month& ym,
const weekday_indexed& wdi)
noexcept
3408 return {ym.year(), ym.month(), wdi};
3413operator/(
const year& y,
const month_weekday& mwd)
noexcept
3415 return {y, mwd.month(), mwd.weekday_indexed()};
3420operator/(
int y,
const month_weekday& mwd)
noexcept
3422 return year(y) / mwd;
3427operator/(
const month_weekday& mwd,
const year& y)
noexcept
3434operator/(
const month_weekday& mwd,
int y)
noexcept
3436 return year(y) / mwd;
3442year_month_weekday_last
3443operator/(
const year_month& ym,
const weekday_last& wdl)
noexcept
3445 return {ym.year(), ym.month(), wdl};
3449year_month_weekday_last
3450operator/(
const year& y,
const month_weekday_last& mwdl)
noexcept
3452 return {y, mwdl.month(), mwdl.weekday_last()};
3456year_month_weekday_last
3457operator/(
int y,
const month_weekday_last& mwdl)
noexcept
3459 return year(y) / mwdl;
3463year_month_weekday_last
3464operator/(
const month_weekday_last& mwdl,
const year& y)
noexcept
3470year_month_weekday_last
3471operator/(
const month_weekday_last& mwdl,
int y)
noexcept
3473 return year(y) / mwdl;
3476template <
class Duration>
3479template <
class CharT,
class Traits,
class Duration>
3480std::basic_ostream<CharT, Traits>&
3481to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
3482 const fields<Duration>& fds,
const std::string* abbrev =
nullptr,
3483 const std::chrono::seconds* offset_sec =
nullptr);
3485template <
class CharT,
class Traits,
class Duration,
class Alloc>
3486std::basic_istream<CharT, Traits>&
3487from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
3488 fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
3489 std::chrono::minutes* offset =
nullptr);
3496struct undocumented {
explicit undocumented() =
default;};
3507template <std::uint64_t n, std::uint64_t d,
unsigned w = 0,
3508 bool should_continue = n%d != 0 && (w < 19)>
3511 static_assert(d > 0,
"width called with zero denominator");
3512 static constexpr const unsigned value = 1 + width<n%d*10, d, w+1>::value;
3515template <std::u
int64_t n, std::u
int64_t d,
unsigned w>
3516struct width<n, d, w, false>
3518 static constexpr const unsigned value = 0;
3521template <
unsigned exp>
3525 static constexpr const std::uint64_t h = static_pow10<exp/2>::value;
3527 static constexpr const std::uint64_t value = h * h * (exp % 2 ? 10 : 1);
3531struct static_pow10<0>
3533 static constexpr const std::uint64_t value = 1;
3536template <
class Duration>
3537class decimal_format_seconds
3539 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
3540 using rep =
typename CT::rep;
3541 static unsigned constexpr const trial_width =
3542 detail::width<CT::period::num, CT::period::den>::value;
3544 static unsigned constexpr const width = trial_width < 19 ? trial_width : 6u;
3545 using precision = std::chrono::duration<rep,
3546 std::ratio<1, static_pow10<width>::value>>;
3549 std::chrono::seconds s_;
3553 constexpr decimal_format_seconds()
3558 constexpr explicit decimal_format_seconds(
const Duration& d) noexcept
3559 : s_(std::chrono::duration_cast<std::chrono::seconds>(d))
3560 , sub_s_(std::chrono::duration_cast<precision>(d - s_))
3563 constexpr std::chrono::seconds& seconds() noexcept {
return s_;}
3564 constexpr std::chrono::seconds seconds() const noexcept {
return s_;}
3565 constexpr precision subseconds() const noexcept {
return sub_s_;}
3567 constexpr precision to_duration() const noexcept
3572 constexpr bool in_conventional_range() const noexcept
3574 return sub_s_ < std::chrono::seconds{1} && s_ < std::chrono::minutes{1};
3577 template <
class CharT,
class Traits>
3579 std::basic_ostream<CharT, Traits>&
3580 operator<<(std::basic_ostream<CharT, Traits>& os,
const decimal_format_seconds& x)
3582 return x.print(os, std::chrono::treat_as_floating_point<rep>{});
3585 template <
class CharT,
class Traits>
3586 std::basic_ostream<CharT, Traits>&
3587 print(std::basic_ostream<CharT, Traits>& os, std::true_type)
const
3589 gul17::date::detail::save_ostream<CharT, Traits> _(os);
3590 std::chrono::duration<rep> d = s_ + sub_s_;
3591 if (d < std::chrono::seconds{10})
3593 os.precision(width+6);
3594 os << std::fixed << d.count();
3598 template <
class CharT,
class Traits>
3599 std::basic_ostream<CharT, Traits>&
3600 print(std::basic_ostream<CharT, Traits>& os, std::false_type)
const
3602 gul17::date::detail::save_ostream<CharT, Traits> _(os);
3604 os.flags(std::ios::dec | std::ios::right);
3610 os << std::use_facet<std::numpunct<CharT>>(os.getloc()).decimal_point();
3614 gul17::date::detail::save_ostream<CharT, Traits> _s(os);
3615 os.imbue(std::locale::classic());
3617 os << sub_s_.count();
3623template <
class Rep,
class Period>
3625typename std::enable_if
3627 std::numeric_limits<Rep>::is_signed,
3628 std::chrono::duration<Rep, Period>
3630abs(std::chrono::duration<Rep, Period> d)
3632 return d >= d.zero() ? +d : -d;
3635template <
class Rep,
class Period>
3637typename std::enable_if
3639 !std::numeric_limits<Rep>::is_signed,
3640 std::chrono::duration<Rep, Period>
3642abs(std::chrono::duration<Rep, Period> d)
3649template <
class Duration>
3652 using dfs = detail::decimal_format_seconds<
typename std::common_type<Duration,
3653 std::chrono::seconds>::type>;
3655 std::chrono::hours h_;
3656 std::chrono::minutes m_;
3661 static unsigned constexpr const fractional_width = dfs::width;
3662 using precision =
typename dfs::precision;
3664 constexpr hh_mm_ss() noexcept
3665 : hh_mm_ss(Duration::zero())
3668 constexpr explicit hh_mm_ss(Duration d) noexcept
3669 : h_(std::chrono::duration_cast<std::chrono::hours>(detail::abs(d)))
3670 , m_(std::chrono::duration_cast<std::chrono::minutes>(detail::abs(d)) - h_)
3671 , s_(detail::abs(d) - h_ - m_)
3672 , neg_(d < Duration::zero())
3675 constexpr std::chrono::hours hours() const noexcept {
return h_;}
3676 constexpr std::chrono::minutes minutes() const noexcept {
return m_;}
3677 constexpr std::chrono::seconds seconds() const noexcept {
return s_.seconds();}
3678 constexpr std::chrono::seconds&
3679 seconds(detail::undocumented)
noexcept {
return s_.seconds();}
3680 constexpr precision subseconds() const noexcept {
return s_.subseconds();}
3681 constexpr bool is_negative() const noexcept {
return neg_;}
3683 constexpr explicit operator precision() const noexcept {
return to_duration();}
3684 constexpr precision to_duration() const noexcept
3685 {
return (s_.to_duration() + m_ + h_) * (1-2*neg_);}
3687 constexpr bool in_conventional_range() const noexcept
3689 return !neg_ && h_ < days{1} && m_ < std::chrono::hours{1} &&
3690 s_.in_conventional_range();
3695 template <
class charT,
class traits>
3697 std::basic_ostream<charT, traits>&
3698 operator<<(std::basic_ostream<charT, traits>& os, hh_mm_ss
const& tod)
3700 if (tod.is_negative())
3702 if (tod.h_ < std::chrono::hours{10})
3704 os << tod.h_.count() <<
':';
3705 if (tod.m_ < std::chrono::minutes{10})
3707 os << tod.m_.count() <<
':' << tod.s_;
3711 template <
class CharT,
class Traits,
class Duration2>
3713 std::basic_ostream<CharT, Traits>&
3714 gul17::date::to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
3715 const fields<Duration2>& fds,
const std::string* abbrev,
3716 const std::chrono::seconds* offset_sec);
3718 template <
class CharT,
class Traits,
class Duration2,
class Alloc>
3720 std::basic_istream<CharT, Traits>&
3721 gul17::date::from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
3722 fields<Duration2>& fds,
3723 std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
3726inline constexpr bool
3727is_am(std::chrono::hours
const& h)
noexcept
3729 using std::chrono::hours;
3730 return hours{0} <= h && h < hours{12};
3733inline constexpr bool
3734is_pm(std::chrono::hours
const& h)
noexcept
3736 using std::chrono::hours;
3737 return hours{12} <= h && h < hours{24};
3740inline constexpr std::chrono::hours
3741make12(std::chrono::hours h)
noexcept
3743 using std::chrono::hours;
3757inline constexpr std::chrono::hours
3758make24(std::chrono::hours h,
bool is_pm)
noexcept
3760 using std::chrono::hours;
3766 else if (h == hours{12})
3771template <
class Duration>
3772using time_of_day = hh_mm_ss<Duration>;
3774template <
class Rep,
class Period>
3776hh_mm_ss<std::chrono::duration<Rep, Period>>
3777make_time(
const std::chrono::duration<Rep, Period>& d)
3779 return hh_mm_ss<std::chrono::duration<Rep, Period>>(d);
3782template <
class CharT,
class Traits,
class Duration>
3784typename std::enable_if
3786 std::ratio_less<typename Duration::period, days::period>::value
3787 , std::basic_ostream<CharT, Traits>&
3789operator<<(std::basic_ostream<CharT, Traits>& os,
const sys_time<Duration>& tp)
3791 auto const dp = gul17::date::floor<days>(tp);
3792 return os << year_month_day(dp) <<
' ' << make_time(tp-dp);
3795template <
class CharT,
class Traits>
3797std::basic_ostream<CharT, Traits>&
3798operator<<(std::basic_ostream<CharT, Traits>& os,
const sys_days& dp)
3800 return os << year_month_day(dp);
3803template <
class CharT,
class Traits,
class Duration>
3805std::basic_ostream<CharT, Traits>&
3806operator<<(std::basic_ostream<CharT, Traits>& os,
const local_time<Duration>& ut)
3808 return (os << sys_time<Duration>{ut.time_since_epoch()});
3814template <
class CharT, std::
size_t N>
3815class string_literal;
3817template <
class CharT1,
class CharT2, std::
size_t N1, std::
size_t N2>
3819string_literal<
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type,
3821operator+(
const string_literal<CharT1, N1>& x,
const string_literal<CharT2, N2>& y)
noexcept;
3823template <
class CharT, std::
size_t N>
3828 constexpr string_literal() noexcept
3833 using const_iterator =
const CharT*;
3835 string_literal(string_literal
const&) =
default;
3836 string_literal& operator=(string_literal
const&) =
delete;
3838 template <std::size_t N1 = 2,
3839 class =
typename std::enable_if<N1 == N>::type>
3840 constexpr string_literal(CharT c) noexcept
3845 template <std::size_t N1 = 3,
3846 class =
typename std::enable_if<N1 == N>::type>
3847 constexpr string_literal(CharT c1, CharT c2) noexcept
3852 template <std::size_t N1 = 4,
3853 class =
typename std::enable_if<N1 == N>::type>
3854 constexpr string_literal(CharT c1, CharT c2, CharT c3) noexcept
3859 constexpr string_literal(
const CharT(&a)[N]) noexcept
3862 for (std::size_t i = 0; i < N; ++i)
3866 template <
class U = CharT,
3867 class =
typename std::enable_if<(1 <
sizeof(U))>::type>
3868 constexpr string_literal(
const char(&a)[N]) noexcept
3871 for (std::size_t i = 0; i < N; ++i)
3875 template <
class CharT2,
3876 class =
typename std::enable_if<!std::is_same<CharT2, CharT>::value>::type>
3877 constexpr string_literal(string_literal<CharT2, N>
const& a) noexcept
3880 for (std::size_t i = 0; i < N; ++i)
3884 constexpr const CharT* data() const noexcept {
return p_;}
3885 constexpr std::size_t size() const noexcept {
return N-1;}
3887 constexpr const_iterator begin() const noexcept {
return p_;}
3888 constexpr const_iterator end() const noexcept {
return p_ + N-1;}
3890 constexpr CharT
const& operator[](std::size_t n)
const noexcept
3895 template <
class Traits>
3897 std::basic_ostream<CharT, Traits>&
3898 operator<<(std::basic_ostream<CharT, Traits>& os,
const string_literal& s)
3903 template <
class CharT1,
class CharT2, std::
size_t N1, std::
size_t N2>
3906 string_literal<
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type,
3908 operator+(
const string_literal<CharT1, N1>& x,
const string_literal<CharT2, N2>& y)
noexcept;
3911template <
class CharT>
3913string_literal<CharT, 3>
3914operator+(
const string_literal<CharT, 2>& x,
const string_literal<CharT, 2>& y)
noexcept
3916 return string_literal<CharT, 3>(x[0], y[0]);
3919template <
class CharT>
3921string_literal<CharT, 4>
3922operator+(
const string_literal<CharT, 3>& x,
const string_literal<CharT, 2>& y)
noexcept
3924 return string_literal<CharT, 4>(x[0], x[1], y[0]);
3927template <
class CharT1,
class CharT2, std::
size_t N1, std::
size_t N2>
3929string_literal<
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type,
3931operator+(
const string_literal<CharT1, N1>& x,
const string_literal<CharT2, N2>& y)
noexcept
3933 using CT =
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type;
3935 string_literal<CT, N1 + N2 - 1> r;
3937 for (; i < N1-1; ++i)
3938 r.p_[i] = CT(x.p_[i]);
3939 for (std::size_t j = 0; j < N2; ++j, ++i)
3940 r.p_[i] = CT(y.p_[j]);
3946template <
class CharT,
class Traits,
class Alloc, std::
size_t N>
3948std::basic_string<CharT, Traits, Alloc>
3949operator+(std::basic_string<CharT, Traits, Alloc> x,
const string_literal<CharT, N>& y)
3951 x.append(y.data(), y.size());
3955#if __cplusplus >= 201402 && (!defined(__EDG_VERSION__) || __EDG_VERSION__ > 411)
3957template <
class CharT,
3958 class = std::enable_if_t<std::is_same<CharT, char>::value ||
3959 std::is_same<CharT, wchar_t>::value ||
3960 std::is_same<CharT, char16_t>::value ||
3961 std::is_same<CharT, char32_t>::value>>
3963string_literal<CharT, 2>
3964msl(CharT c)
noexcept
3966 return string_literal<CharT, 2>{c};
3971to_string_len(std::intmax_t i)
3982template <std::
intmax_t N>
3987 string_literal<char, to_string_len(N)+1>
3991 return msl(
char(N % 10 +
'0'));
3994template <std::
intmax_t N>
3999 string_literal<char, to_string_len(N)+1>
4003 return msl<N/10>() + msl(
char(N % 10 +
'0'));
4006template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4010 std::ratio<N, D>::type::den != 1,
4011 string_literal<CharT, to_string_len(std::ratio<N, D>::type::num) +
4012 to_string_len(std::ratio<N, D>::type::den) + 4>
4014msl(std::ratio<N, D>)
noexcept
4016 using R =
typename std::ratio<N, D>::type;
4017 return msl(CharT{
'['}) + msl<R::num>() + msl(CharT{
'/'}) +
4018 msl<R::den>() + msl(CharT{
']'});
4021template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4025 std::ratio<N, D>::type::den == 1,
4026 string_literal<CharT, to_string_len(std::ratio<N, D>::type::num) + 3>
4028msl(std::ratio<N, D>)
noexcept
4030 using R =
typename std::ratio<N, D>::type;
4031 return msl(CharT{
'['}) + msl<R::num>() + msl(CharT{
']'});
4039to_string(std::uint64_t x)
4041 return std::to_string(x);
4044template <
class CharT>
4046std::basic_string<CharT>
4047to_string(std::uint64_t x)
4049 auto y = std::to_string(x);
4050 return std::basic_string<CharT>(y.begin(), y.end());
4053template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4055typename std::enable_if
4057 std::ratio<N, D>::type::den != 1,
4058 std::basic_string<CharT>
4060msl(std::ratio<N, D>)
4062 using R =
typename std::ratio<N, D>::type;
4063 return std::basic_string<CharT>(1,
'[') + to_string<CharT>(R::num) + CharT{
'/'} +
4064 to_string<CharT>(R::den) + CharT{
']'};
4067template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4069typename std::enable_if
4071 std::ratio<N, D>::type::den == 1,
4072 std::basic_string<CharT>
4074msl(std::ratio<N, D>)
4076 using R =
typename std::ratio<N, D>::type;
4077 return std::basic_string<CharT>(1,
'[') + to_string<CharT>(R::num) + CharT{
']'};
4082template <
class CharT>
4084string_literal<CharT, 2>
4085msl(std::atto)
noexcept
4087 return string_literal<CharT, 2>{
'a'};
4090template <
class CharT>
4092string_literal<CharT, 2>
4093msl(std::femto)
noexcept
4095 return string_literal<CharT, 2>{
'f'};
4098template <
class CharT>
4100string_literal<CharT, 2>
4101msl(std::pico)
noexcept
4103 return string_literal<CharT, 2>{
'p'};
4106template <
class CharT>
4108string_literal<CharT, 2>
4109msl(std::nano)
noexcept
4111 return string_literal<CharT, 2>{
'n'};
4114template <
class CharT>
4116typename std::enable_if
4118 std::is_same<CharT, char>::value,
4119 string_literal<char, 3>
4121msl(std::micro)
noexcept
4123 return string_literal<char, 3>{
'\xC2',
'\xB5'};
4126template <
class CharT>
4128typename std::enable_if
4130 !std::is_same<CharT, char>::value,
4131 string_literal<CharT, 2>
4133msl(std::micro)
noexcept
4135 return string_literal<CharT, 2>{CharT{
static_cast<unsigned char>(
'\xB5')}};
4138template <
class CharT>
4140string_literal<CharT, 2>
4141msl(std::milli)
noexcept
4143 return string_literal<CharT, 2>{
'm'};
4146template <
class CharT>
4148string_literal<CharT, 2>
4149msl(std::centi)
noexcept
4151 return string_literal<CharT, 2>{
'c'};
4154template <
class CharT>
4156string_literal<CharT, 3>
4157msl(std::deca)
noexcept
4159 return string_literal<CharT, 3>{
'd',
'a'};
4162template <
class CharT>
4164string_literal<CharT, 2>
4165msl(std::deci)
noexcept
4167 return string_literal<CharT, 2>{
'd'};
4170template <
class CharT>
4172string_literal<CharT, 2>
4173msl(std::hecto)
noexcept
4175 return string_literal<CharT, 2>{
'h'};
4178template <
class CharT>
4180string_literal<CharT, 2>
4181msl(std::kilo)
noexcept
4183 return string_literal<CharT, 2>{
'k'};
4186template <
class CharT>
4188string_literal<CharT, 2>
4189msl(std::mega)
noexcept
4191 return string_literal<CharT, 2>{
'M'};
4194template <
class CharT>
4196string_literal<CharT, 2>
4197msl(std::giga)
noexcept
4199 return string_literal<CharT, 2>{
'G'};
4202template <
class CharT>
4204string_literal<CharT, 2>
4205msl(std::tera)
noexcept
4207 return string_literal<CharT, 2>{
'T'};
4210template <
class CharT>
4212string_literal<CharT, 2>
4213msl(std::peta)
noexcept
4215 return string_literal<CharT, 2>{
'P'};
4218template <
class CharT>
4220string_literal<CharT, 2>
4221msl(std::exa)
noexcept
4223 return string_literal<CharT, 2>{
'E'};
4226template <
class CharT,
class Period>
4230 ->
decltype(msl<CharT>(p) + string_literal<CharT, 2>{
's'})
4232 return msl<CharT>(p) + string_literal<CharT, 2>{
's'};
4235template <
class CharT>
4237string_literal<CharT, 2>
4238get_units(std::ratio<1>)
4240 return string_literal<CharT, 2>{
's'};
4243template <
class CharT>
4245string_literal<CharT, 2>
4246get_units(std::ratio<3600>)
4248 return string_literal<CharT, 2>{
'h'};
4251template <
class CharT>
4253string_literal<CharT, 4>
4254get_units(std::ratio<60>)
4256 return string_literal<CharT, 4>{
'm',
'i',
'n'};
4259template <
class CharT>
4261string_literal<CharT, 2>
4262get_units(std::ratio<86400>)
4264 return string_literal<CharT, 2>{
'd'};
4267template <
class CharT,
class Traits = std::
char_traits<CharT>>
4271struct make_string<char>
4273 template <
class Rep>
4278 return std::to_string(n);
4282template <
class Traits>
4283struct make_string<char, Traits>
4285 template <
class Rep>
4287 std::basic_string<char, Traits>
4290 auto s = std::to_string(n);
4291 return std::basic_string<char, Traits>(s.begin(), s.end());
4296struct make_string<wchar_t>
4298 template <
class Rep>
4303 return std::to_wstring(n);
4307template <
class Traits>
4308struct make_string<wchar_t, Traits>
4310 template <
class Rep>
4312 std::basic_string<wchar_t, Traits>
4315 auto s = std::to_wstring(n);
4316 return std::basic_string<wchar_t, Traits>(s.begin(), s.end());
4324constexpr const year nanyear{-32768};
4326template <
class Duration>
4329 year_month_day ymd{nanyear/0/0};
4331 hh_mm_ss<Duration> tod{};
4332 bool has_tod =
false;
4334#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ <= 409)
4335 fields() : ymd{nanyear/0/0}, wd{8u}, tod{}, has_tod{false} {}
4340 fields(year_month_day ymd_) : ymd(ymd_) {}
4341 fields(weekday wd_) : wd(wd_) {}
4342 fields(hh_mm_ss<Duration> tod_) : tod(tod_), has_tod(true) {}
4344 fields(year_month_day ymd_, weekday wd_) : ymd(ymd_), wd(wd_) {}
4345 fields(year_month_day ymd_, hh_mm_ss<Duration> tod_) : ymd(ymd_), tod(tod_),
4348 fields(weekday wd_, hh_mm_ss<Duration> tod_) : wd(wd_), tod(tod_), has_tod(true) {}
4350 fields(year_month_day ymd_, weekday wd_, hh_mm_ss<Duration> tod_)
4361template <
class CharT,
class Traits,
class Duration>
4363extract_weekday(std::basic_ostream<CharT, Traits>& os,
const fields<Duration>& fds)
4365 if (!fds.ymd.ok() && !fds.wd.ok())
4368 os.setstate(std::ios::failbit);
4374 wd = weekday{sys_days(fds.ymd)};
4375 if (fds.wd.ok() && wd != fds.wd)
4378 os.setstate(std::ios::failbit);
4384 return static_cast<unsigned>((wd - Sunday).count());
4387template <
class CharT,
class Traits,
class Duration>
4389extract_month(std::basic_ostream<CharT, Traits>& os,
const fields<Duration>& fds)
4391 if (!fds.ymd.month().ok())
4394 os.setstate(std::ios::failbit);
4397 return static_cast<unsigned>(fds.ymd.month());
4408std::pair<const std::string*, const std::string*>
4411 static const std::string nm[] =
4428 return std::make_pair(nm, nm+
sizeof(nm)/
sizeof(nm[0]));
4432std::pair<const std::string*, const std::string*>
4435 static const std::string nm[] =
4462 return std::make_pair(nm, nm+
sizeof(nm)/
sizeof(nm[0]));
4466std::pair<const std::string*, const std::string*>
4469 static const std::string nm[] =
4474 return std::make_pair(nm, nm+
sizeof(nm)/
sizeof(nm[0]));
4477template <
class CharT,
class Traits,
class FwdIter>
4479scan_keyword(std::basic_istream<CharT, Traits>& is, FwdIter kb, FwdIter ke)
4481 size_t nkw =
static_cast<size_t>(std::distance(kb, ke));
4482 const unsigned char doesnt_match =
'\0';
4483 const unsigned char might_match =
'\1';
4484 const unsigned char does_match =
'\2';
4485 unsigned char statbuf[100];
4486 unsigned char* status = statbuf;
4487 std::unique_ptr<
unsigned char, void(*)(
void*)> stat_hold(0, free);
4488 if (nkw >
sizeof(statbuf))
4490 status = (
unsigned char*)std::malloc(nkw);
4491 if (status ==
nullptr)
4492 throw std::bad_alloc();
4493 stat_hold.reset(status);
4495 size_t n_might_match = nkw;
4496 size_t n_does_match = 0;
4498 unsigned char* st = status;
4499 for (
auto ky = kb; ky != ke; ++ky, ++st)
4511 for (
size_t indx = 0; is && n_might_match > 0; ++indx)
4514 auto ic = is.peek();
4517 is.setstate(std::ios::eofbit);
4520 auto c =
static_cast<char>(toupper(
static_cast<unsigned char>(ic)));
4521 bool consume =
false;
4529 for (
auto ky = kb; ky != ke; ++ky, ++st)
4531 if (*st == might_match)
4533 if (c ==
static_cast<char>(toupper(
static_cast<unsigned char>((*ky)[indx]))))
4536 if (ky->size() == indx+1)
4557 if (n_might_match + n_does_match > 1)
4560 for (
auto ky = kb; ky != ke; ++ky, ++st)
4562 if (*st == does_match && ky->size() != indx+1)
4573 for (st = status; kb != ke; ++kb, ++st)
4574 if (*st == does_match)
4577 is.setstate(std::ios::failbit);
4585template <
class CharT,
class Traits,
class Duration>
4586std::basic_ostream<CharT, Traits>&
4587to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
4588 const fields<Duration>& fds,
const std::string* abbrev,
4589 const std::chrono::seconds* offset_sec)
4592 using detail::weekday_names;
4593 using detail::month_names;
4594 using detail::ampm_names;
4596 using detail::save_ostream;
4597 using detail::get_units;
4598 using detail::extract_weekday;
4599 using detail::extract_month;
4601 using std::chrono::duration_cast;
4602 using std::chrono::seconds;
4603 using std::chrono::minutes;
4604 using std::chrono::hours;
4605 gul17::date::detail::save_ostream<CharT, Traits> ss(os);
4607 os.flags(std::ios::skipws | std::ios::dec);
4610 bool insert_negative = fds.has_tod && fds.tod.to_duration() < Duration::zero();
4612 auto& facet = std::use_facet<std::time_put<CharT>>(os.getloc());
4614 const CharT* command =
nullptr;
4615 CharT modified = CharT{};
4624 if (modified == CharT{})
4626 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
4630 const CharT f[] = {
'%', *fmt};
4631 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4633 os << weekday_names().first[tm.tm_wday+7*(*fmt ==
'a')];
4638 os << CharT{
'%'} << modified << *fmt;
4651 if (modified == CharT{})
4653 tm.tm_mon =
static_cast<int>(extract_month(os, fds)) - 1;
4655 const CharT f[] = {
'%', *fmt};
4656 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4658 os << month_names().first[tm.tm_mon+12*(*fmt !=
'B')];
4663 os << CharT{
'%'} << modified << *fmt;
4675 if (modified == CharT{
'O'})
4676 os << CharT{
'%'} << modified << *fmt;
4680 os.setstate(std::ios::failbit);
4681 if (*fmt ==
'c' && !fds.has_tod)
4682 os.setstate(std::ios::failbit);
4685 auto const& ymd = fds.ymd;
4686 auto ld = local_days(ymd);
4689 tm.tm_sec =
static_cast<int>(fds.tod.seconds().count());
4690 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
4691 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
4693 tm.tm_mday =
static_cast<int>(
static_cast<unsigned>(ymd.day()));
4694 tm.tm_mon =
static_cast<int>(extract_month(os, fds) - 1);
4695 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
4696 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
4699 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
4701 auto fe = std::begin(f) + 1;
4702 if (modified == CharT{
'E'})
4705 facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
4709 auto wd =
static_cast<int>(extract_weekday(os, fds));
4710 os << weekday_names().first[
static_cast<unsigned>(wd)+7]
4712 os << month_names().first[extract_month(os, fds)-1+12] <<
' ';
4713 auto d =
static_cast<int>(
static_cast<unsigned>(fds.ymd.day()));
4717 << make_time(duration_cast<seconds>(fds.tod.to_duration()))
4718 <<
' ' << fds.ymd.year();
4723 auto const& ymd = fds.ymd;
4724 save_ostream<CharT, Traits> _(os);
4726 os.flags(std::ios::dec | std::ios::right);
4728 os << static_cast<unsigned>(ymd.month()) << CharT{
'/'};
4730 os << static_cast<unsigned>(ymd.day()) << CharT{
'/'};
4732 os << static_cast<int>(ymd.year()) % 100;
4745 if (modified == CharT{
'O'})
4746 os << CharT{
'%'} << modified << *fmt;
4749 if (!fds.ymd.year().ok())
4750 os.setstate(std::ios::failbit);
4751 auto y =
static_cast<int>(fds.ymd.year());
4753 if (modified == CharT{})
4756 save_ostream<CharT, Traits> _(os);
4758 os.flags(std::ios::dec | std::ios::right);
4772 else if (modified == CharT{
'E'})
4774 tm.tm_year = y - 1900;
4775 CharT f[3] = {
'%',
'E',
'C'};
4776 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4790 if (modified == CharT{
'E'})
4791 os << CharT{
'%'} << modified << *fmt;
4794 if (!fds.ymd.day().ok())
4795 os.setstate(std::ios::failbit);
4796 auto d =
static_cast<int>(
static_cast<unsigned>(fds.ymd.day()));
4798 if (modified == CharT{})
4801 save_ostream<CharT, Traits> _(os);
4802 if (*fmt == CharT{
'd'})
4806 os.flags(std::ios::dec | std::ios::right);
4811 else if (modified == CharT{
'O'})
4814 CharT f[3] = {
'%',
'O', *fmt};
4815 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4828 if (modified == CharT{})
4831 os.setstate(std::ios::failbit);
4832 auto const& ymd = fds.ymd;
4833 save_ostream<CharT, Traits> _(os);
4835 os.flags(std::ios::dec | std::ios::right);
4837 os << static_cast<unsigned>(ymd.month()) << CharT{
'/'};
4839 os << static_cast<unsigned>(ymd.day()) << CharT{
'/'};
4841 os << static_cast<int>(ymd.year()) % 100;
4845 os << CharT{
'%'} << modified << *fmt;
4856 if (modified == CharT{})
4859 os.setstate(std::ios::failbit);
4860 auto const& ymd = fds.ymd;
4861 save_ostream<CharT, Traits> _(os);
4862 os.imbue(std::locale::classic());
4864 os.flags(std::ios::dec | std::ios::right);
4866 os << static_cast<int>(ymd.year()) << CharT{
'-'};
4868 os << static_cast<unsigned>(ymd.month()) << CharT{
'-'};
4870 os << static_cast<unsigned>(ymd.day());
4874 os << CharT{
'%'} << modified << *fmt;
4886 if (modified == CharT{})
4889 os.setstate(std::ios::failbit);
4890 auto ld = local_days(fds.ymd);
4891 auto y = year_month_day{ld + days{3}}.year();
4892 auto start = local_days((y-years{1})/December/Thursday[last]) +
4896 if (*fmt == CharT{
'G'})
4900 save_ostream<CharT, Traits> _(os);
4902 os.flags(std::ios::dec | std::ios::right);
4904 os << std::abs(static_cast<int>(y)) % 100;
4909 os << CharT{
'%'} << modified << *fmt;
4921 if (modified == CharT{
'E'})
4922 os << CharT{
'%'} << modified << *fmt;
4926 os.setstate(std::ios::failbit);
4927 if (insert_negative)
4930 insert_negative =
false;
4934 if (modified == CharT{})
4937 auto h = *fmt == CharT{
'I'} ? gul17::date::make12(hms.hours()) : hms.hours();
4943 else if (modified == CharT{
'O'})
4945 const CharT f[] = {
'%', modified, *fmt};
4946 tm.tm_hour =
static_cast<int>(hms.hours().count());
4947 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4960 if (modified == CharT{})
4962 if (fds.ymd.ok() || fds.has_tod)
4967 auto ld = local_days(fds.ymd);
4968 auto y = fds.ymd.year();
4969 doy = ld - local_days(y/January/1) + days{1};
4973 doy = duration_cast<days>(fds.tod.to_duration());
4975 save_ostream<CharT, Traits> _(os);
4977 os.flags(std::ios::dec | std::ios::right);
4983 os.setstate(std::ios::failbit);
4988 os << CharT{
'%'} << modified << *fmt;
4999 if (modified == CharT{
'E'})
5000 os << CharT{
'%'} << modified << *fmt;
5003 if (!fds.ymd.month().ok())
5004 os.setstate(std::ios::failbit);
5005 auto m =
static_cast<unsigned>(fds.ymd.month());
5007 if (modified == CharT{})
5015 else if (modified == CharT{
'O'})
5017 const CharT f[] = {
'%', modified, *fmt};
5018 tm.tm_mon =
static_cast<int>(m-1);
5019 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5032 if (modified == CharT{
'E'})
5033 os << CharT{
'%'} << modified << *fmt;
5037 os.setstate(std::ios::failbit);
5038 if (insert_negative)
5041 insert_negative =
false;
5044 if (modified == CharT{})
5047 if (fds.tod.minutes() < minutes{10})
5049 os << fds.tod.minutes().count();
5052 else if (modified == CharT{
'O'})
5054 const CharT f[] = {
'%', modified, *fmt};
5055 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
5056 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5069 if (modified == CharT{})
5073 os << CharT{
'%'} << modified << *fmt;
5084 if (modified == CharT{})
5087 os.setstate(std::ios::failbit);
5089 const CharT f[] = {
'%', *fmt};
5090 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
5091 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5093 if (gul17::date::is_am(fds.tod.hours()))
5094 os << ampm_names().first[0];
5096 os << ampm_names().first[1];
5101 os << CharT{
'%'} << modified << *fmt;
5113 if (modified == CharT{})
5116 os.setstate(std::ios::failbit);
5117 auto d = fds.tod.to_duration();
5119 os << get_units<CharT>(
typename decltype(d)::period::type{});
5125 os << CharT{
'%'} << modified << *fmt;
5136 if (modified == CharT{})
5139 os.setstate(std::ios::failbit);
5141 const CharT f[] = {
'%', *fmt};
5142 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
5143 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
5144 tm.tm_sec =
static_cast<int>(fds.tod.seconds().count());
5145 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5147 hh_mm_ss<seconds> tod(duration_cast<seconds>(fds.tod.to_duration()));
5148 save_ostream<CharT, Traits> _(os);
5151 os << gul17::date::make12(tod.hours()).count() << CharT{
':'};
5153 os << tod.minutes().count() << CharT{
':'};
5155 os << tod.seconds().count() << CharT{
' '};
5156 if (gul17::date::is_am(tod.hours()))
5157 os << ampm_names().first[0];
5159 os << ampm_names().first[1];
5164 os << CharT{
'%'} << modified << *fmt;
5175 if (modified == CharT{})
5178 os.setstate(std::ios::failbit);
5179 if (fds.tod.hours() < hours{10})
5181 os << fds.tod.hours().count() << CharT{
':'};
5182 if (fds.tod.minutes() < minutes{10})
5184 os << fds.tod.minutes().count();
5188 os << CharT{
'%'} << modified << *fmt;
5199 if (modified == CharT{
'E'})
5200 os << CharT{
'%'} << modified << *fmt;
5204 os.setstate(std::ios::failbit);
5205 if (insert_negative)
5208 insert_negative =
false;
5211 if (modified == CharT{})
5217 else if (modified == CharT{
'O'})
5219 const CharT f[] = {
'%', modified, *fmt};
5220 tm.tm_sec =
static_cast<int>(fds.tod.s_.seconds().count());
5221 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5234 if (modified == CharT{})
5238 os << CharT{
'%'} << modified << *fmt;
5249 if (modified == CharT{})
5252 os.setstate(std::ios::failbit);
5257 os << CharT{
'%'} << modified << *fmt;
5268 if (modified == CharT{
'E'})
5269 os << CharT{
'%'} << modified << *fmt;
5272 auto wd = extract_weekday(os, fds);
5274 if (modified == CharT{})
5277 os << (wd != 0 ? wd : 7u);
5280 else if (modified == CharT{
'O'})
5282 const CharT f[] = {
'%', modified, *fmt};
5283 tm.tm_wday =
static_cast<int>(wd);
5284 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5297 if (modified == CharT{
'E'})
5298 os << CharT{
'%'} << modified << *fmt;
5301 auto const& ymd = fds.ymd;
5303 os.setstate(std::ios::failbit);
5304 auto ld = local_days(ymd);
5306 if (modified == CharT{})
5309 auto st = local_days(Sunday[1]/January/ymd.year());
5311 os << CharT{
'0'} << CharT{
'0'};
5314 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5321 else if (modified == CharT{
'O'})
5323 const CharT f[] = {
'%', modified, *fmt};
5324 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5325 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5328 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
5329 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5342 if (modified == CharT{
'E'})
5343 os << CharT{
'%'} << modified << *fmt;
5347 os.setstate(std::ios::failbit);
5348 auto ld = local_days(fds.ymd);
5350 if (modified == CharT{})
5353 auto y = year_month_day{ld + days{3}}.year();
5354 auto st = local_days((y-years{1})/12/Thursday[last]) +
5359 st = local_days((y - years{1})/12/Thursday[last]) +
5362 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5368 else if (modified == CharT{
'O'})
5370 const CharT f[] = {
'%', modified, *fmt};
5371 auto const& ymd = fds.ymd;
5372 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5373 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5376 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
5377 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5390 auto wd = extract_weekday(os, fds);
5394 if (modified == CharT{})
5396 if (modified != CharT{
'E'})
5402 else if (modified == CharT{
'O'})
5404 const CharT f[] = {
'%', modified, *fmt};
5405 tm.tm_wday =
static_cast<int>(wd);
5406 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5411 os << CharT{
'%'} << modified << *fmt;
5422 if (modified == CharT{
'E'})
5423 os << CharT{
'%'} << modified << *fmt;
5426 auto const& ymd = fds.ymd;
5428 os.setstate(std::ios::failbit);
5429 auto ld = local_days(ymd);
5431 if (modified == CharT{})
5434 auto st = local_days(Monday[1]/January/ymd.year());
5436 os << CharT{
'0'} << CharT{
'0'};
5439 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5446 else if (modified == CharT{
'O'})
5448 const CharT f[] = {
'%', modified, *fmt};
5449 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5450 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5453 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
5454 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5467 if (modified == CharT{
'O'})
5468 os << CharT{
'%'} << modified << *fmt;
5472 os.setstate(std::ios::failbit);
5475 tm.tm_sec =
static_cast<int>(fds.tod.seconds().count());
5476 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
5477 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
5479 auto fe = std::begin(f) + 1;
5480 if (modified == CharT{
'E'})
5483 facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
5497 if (!fds.ymd.year().ok())
5498 os.setstate(std::ios::failbit);
5499 auto y =
static_cast<int>(fds.ymd.year());
5501 if (modified == CharT{})
5504 y = std::abs(y) % 100;
5512 const CharT f[] = {
'%', modified, *fmt};
5513 tm.tm_year = y - 1900;
5514 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5526 if (modified == CharT{
'O'})
5527 os << CharT{
'%'} << modified << *fmt;
5530 if (!fds.ymd.year().ok())
5531 os.setstate(std::ios::failbit);
5532 auto y = fds.ymd.year();
5534 if (modified == CharT{})
5537 save_ostream<CharT, Traits> _(os);
5538 os.imbue(std::locale::classic());
5542 else if (modified == CharT{
'E'})
5544 const CharT f[] = {
'%', modified, *fmt};
5545 tm.tm_year =
static_cast<int>(y) - 1900;
5546 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5559 if (offset_sec ==
nullptr)
5562 os.setstate(ios::failbit);
5565 auto m = duration_cast<minutes>(*offset_sec);
5566 auto neg = m < minutes{0};
5567 m = gul17::date::abs(m);
5568 auto h = duration_cast<hours>(m);
5577 if (modified != CharT{})
5579 if (m < minutes{10})
5591 if (modified == CharT{})
5593 if (abbrev ==
nullptr)
5596 os.setstate(ios::failbit);
5599 for (
auto c : *abbrev)
5604 os << CharT{
'%'} << modified << *fmt;
5616 if (modified == CharT{})
5622 os << CharT{
'%'} << modified << *fmt;
5633 if (modified == CharT{})
5640 os << CharT{
'%'} << modified << CharT{
'%'};
5654 if (modified != CharT{})
5665 if (modified != CharT{})
5670template <
class CharT,
class Traits>
5672std::basic_ostream<CharT, Traits>&
5673to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const year& y)
5675 using CT = std::chrono::seconds;
5676 fields<CT> fds{y/0/0};
5677 return to_stream(os, fmt, fds);
5680template <
class CharT,
class Traits>
5682std::basic_ostream<CharT, Traits>&
5683to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const month& m)
5685 using CT = std::chrono::seconds;
5686 fields<CT> fds{m/0/nanyear};
5687 return to_stream(os, fmt, fds);
5690template <
class CharT,
class Traits>
5692std::basic_ostream<CharT, Traits>&
5693to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const day& d)
5695 using CT = std::chrono::seconds;
5696 fields<CT> fds{d/0/nanyear};
5697 return to_stream(os, fmt, fds);
5700template <
class CharT,
class Traits>
5702std::basic_ostream<CharT, Traits>&
5703to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const weekday& wd)
5705 using CT = std::chrono::seconds;
5707 return to_stream(os, fmt, fds);
5710template <
class CharT,
class Traits>
5712std::basic_ostream<CharT, Traits>&
5713to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const year_month& ym)
5715 using CT = std::chrono::seconds;
5716 fields<CT> fds{ym/0};
5717 return to_stream(os, fmt, fds);
5720template <
class CharT,
class Traits>
5722std::basic_ostream<CharT, Traits>&
5723to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const month_day& md)
5725 using CT = std::chrono::seconds;
5726 fields<CT> fds{md/nanyear};
5727 return to_stream(os, fmt, fds);
5730template <
class CharT,
class Traits>
5732std::basic_ostream<CharT, Traits>&
5733to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5734 const year_month_day& ymd)
5736 using CT = std::chrono::seconds;
5737 fields<CT> fds{ymd};
5738 return to_stream(os, fmt, fds);
5741template <
class CharT,
class Traits,
class Rep,
class Period>
5743std::basic_ostream<CharT, Traits>&
5744to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5745 const std::chrono::duration<Rep, Period>& d)
5747 using Duration = std::chrono::duration<Rep, Period>;
5748 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
5749 fields<CT> fds{hh_mm_ss<CT>{d}};
5750 return to_stream(os, fmt, fds);
5753template <
class CharT,
class Traits,
class Duration>
5754std::basic_ostream<CharT, Traits>&
5755to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5756 const local_time<Duration>& tp,
const std::string* abbrev =
nullptr,
5757 const std::chrono::seconds* offset_sec =
nullptr)
5759 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
5760 auto ld = std::chrono::time_point_cast<days>(tp);
5763 fds = fields<CT>{year_month_day{ld}, hh_mm_ss<CT>{tp-local_seconds{ld}}};
5765 fds = fields<CT>{year_month_day{ld - days{1}},
5766 hh_mm_ss<CT>{days{1} - (local_seconds{ld} - tp)}};
5767 return to_stream(os, fmt, fds, abbrev, offset_sec);
5770template <
class CharT,
class Traits,
class Duration>
5771std::basic_ostream<CharT, Traits>&
5772to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5773 const sys_time<Duration>& tp)
5775 using std::chrono::seconds;
5776 using CT =
typename std::common_type<Duration, seconds>::type;
5777 const std::string abbrev(
"UTC");
5778 constexpr const seconds offset{0};
5779 auto sd = std::chrono::time_point_cast<days>(tp);
5782 fds = fields<CT>{year_month_day{sd}, hh_mm_ss<CT>{tp-sys_seconds{sd}}};
5784 fds = fields<CT>{year_month_day{sd - days{1}},
5785 hh_mm_ss<CT>{days{1} - (sys_seconds{sd} - tp)}};
5786 return to_stream(os, fmt, fds, &abbrev, &offset);
5791template <
class CharT,
class Streamable>
5793format(
const std::locale& loc,
const CharT* fmt,
const Streamable& tp)
5794 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT>&>(), fmt, tp),
5795 std::basic_string<CharT>{})
5797 std::basic_ostringstream<CharT> os;
5798 os.exceptions(std::ios::failbit | std::ios::badbit);
5800 to_stream(os, fmt, tp);
5804template <
class CharT,
class Streamable>
5806format(
const CharT* fmt,
const Streamable& tp)
5807 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT>&>(), fmt, tp),
5808 std::basic_string<CharT>{})
5810 std::basic_ostringstream<CharT> os;
5811 os.exceptions(std::ios::failbit | std::ios::badbit);
5812 to_stream(os, fmt, tp);
5816template <
class CharT,
class Traits,
class Alloc,
class Streamable>
5818format(
const std::locale& loc,
const std::basic_string<CharT, Traits, Alloc>& fmt,
5819 const Streamable& tp)
5820 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt.c_str(), tp),
5821 std::basic_string<CharT, Traits, Alloc>{})
5823 std::basic_ostringstream<CharT, Traits, Alloc> os;
5824 os.exceptions(std::ios::failbit | std::ios::badbit);
5826 to_stream(os, fmt.c_str(), tp);
5830template <
class CharT,
class Traits,
class Alloc,
class Streamable>
5832format(
const std::basic_string<CharT, Traits, Alloc>& fmt,
const Streamable& tp)
5833 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt.c_str(), tp),
5834 std::basic_string<CharT, Traits, Alloc>{})
5836 std::basic_ostringstream<CharT, Traits, Alloc> os;
5837 os.exceptions(std::ios::failbit | std::ios::badbit);
5838 to_stream(os, fmt.c_str(), tp);
5847template <
class CharT,
class Traits>
5849read_char(std::basic_istream<CharT, Traits>& is, CharT fmt, std::ios::iostate& err)
5852 if (Traits::eq_int_type(ic, Traits::eof()) ||
5853 !Traits::eq(Traits::to_char_type(ic), fmt))
5855 err |= std::ios::failbit;
5856 is.setstate(std::ios::failbit);
5862template <
class CharT,
class Traits>
5864read_unsigned(std::basic_istream<CharT, Traits>& is,
unsigned m = 1,
unsigned M = 10)
5870 auto ic = is.peek();
5871 if (Traits::eq_int_type(ic, Traits::eof()))
5873 auto c =
static_cast<char>(Traits::to_char_type(ic));
5874 if (!(
'0' <= c && c <=
'9'))
5878 x = 10*x +
static_cast<unsigned>(c -
'0');
5883 is.setstate(std::ios::failbit);
5887template <
class CharT,
class Traits>
5889read_signed(std::basic_istream<CharT, Traits>& is,
unsigned m = 1,
unsigned M = 10)
5891 auto ic = is.peek();
5892 if (!Traits::eq_int_type(ic, Traits::eof()))
5894 auto c =
static_cast<char>(Traits::to_char_type(ic));
5895 if ((
'0' <= c && c <=
'9') || c ==
'-' || c ==
'+')
5897 if (c ==
'-' || c ==
'+')
5899 auto x =
static_cast<int>(read_unsigned(is, std::max(m, 1u), M));
5909 is.setstate(std::ios::failbit);
5913template <
class CharT,
class Traits>
5915read_long_double(std::basic_istream<CharT, Traits>& is,
unsigned m = 1,
unsigned M = 10)
5918 unsigned fcount = 0;
5919 unsigned long long i = 0;
5920 unsigned long long f = 0;
5921 bool parsing_fraction =
false;
5923 typename Traits::int_type decimal_point =
'.';
5925 auto decimal_point = Traits::to_int_type(
5926 std::use_facet<std::numpunct<CharT>>(is.getloc()).decimal_point());
5930 auto ic = is.peek();
5931 if (Traits::eq_int_type(ic, Traits::eof()))
5933 if (Traits::eq_int_type(ic, decimal_point))
5935 decimal_point = Traits::eof();
5936 parsing_fraction =
true;
5940 auto c =
static_cast<char>(Traits::to_char_type(ic));
5941 if (!(
'0' <= c && c <=
'9'))
5943 if (!parsing_fraction)
5945 i = 10*i +
static_cast<unsigned>(c -
'0');
5949 f = 10*f +
static_cast<unsigned>(c -
'0');
5959 is.setstate(std::ios::failbit);
5962 return static_cast<long double>(i) +
static_cast<long double>(f)/std::pow(10.L, fcount);
5986template <
class CharT,
class Traits>
5988read(std::basic_istream<CharT, Traits>&)
5992template <
class CharT,
class Traits,
class ...Args>
5994read(std::basic_istream<CharT, Traits>& is, CharT a0, Args&& ...args);
5996template <
class CharT,
class Traits,
class ...Args>
5998read(std::basic_istream<CharT, Traits>& is, rs a0, Args&& ...args);
6000template <
class CharT,
class Traits,
class ...Args>
6002read(std::basic_istream<CharT, Traits>& is, ru a0, Args&& ...args);
6004template <
class CharT,
class Traits,
class ...Args>
6006read(std::basic_istream<CharT, Traits>& is,
int a0, Args&& ...args);
6008template <
class CharT,
class Traits,
class ...Args>
6010read(std::basic_istream<CharT, Traits>& is, rld a0, Args&& ...args);
6012template <
class CharT,
class Traits,
class ...Args>
6014read(std::basic_istream<CharT, Traits>& is, CharT a0, Args&& ...args)
6019 auto ic = is.peek();
6020 if (Traits::eq_int_type(ic, Traits::eof()))
6022 is.setstate(std::ios::failbit | std::ios::eofbit);
6025 if (!Traits::eq(Traits::to_char_type(ic), a0))
6027 is.setstate(std::ios::failbit);
6032 read(is, std::forward<Args>(args)...);
6035template <
class CharT,
class Traits,
class ...Args>
6037read(std::basic_istream<CharT, Traits>& is, rs a0, Args&& ...args)
6039 auto x = read_signed(is, a0.m, a0.M);
6043 read(is, std::forward<Args>(args)...);
6046template <
class CharT,
class Traits,
class ...Args>
6048read(std::basic_istream<CharT, Traits>& is, ru a0, Args&& ...args)
6050 auto x = read_unsigned(is, a0.m, a0.M);
6053 a0.i =
static_cast<int>(x);
6054 read(is, std::forward<Args>(args)...);
6057template <
class CharT,
class Traits,
class ...Args>
6059read(std::basic_istream<CharT, Traits>& is,
int a0, Args&& ...args)
6063 auto u =
static_cast<unsigned>(a0);
6064 CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};
6068 *e++ =
static_cast<CharT
>(CharT(u % 10) + CharT{
'0'});
6071 std::reverse(buf, e);
6072 for (
auto p = buf; p != e && is.rdstate() == std::ios::goodbit; ++p)
6075 if (is.rdstate() == std::ios::goodbit)
6076 read(is, std::forward<Args>(args)...);
6079template <
class CharT,
class Traits,
class ...Args>
6081read(std::basic_istream<CharT, Traits>& is, rld a0, Args&& ...args)
6083 auto x = read_long_double(is, a0.m, a0.M);
6087 read(is, std::forward<Args>(args)...);
6090template <
class T,
class CharT,
class Traits>
6093checked_set(T& value, T from, T not_a_value, std::basic_ios<CharT, Traits>& is)
6097 if (value == not_a_value)
6098 value = std::move(from);
6099 else if (value != from)
6100 is.setstate(std::ios::failbit);
6106template <
class CharT,
class Traits,
class Duration,
class Alloc = std::allocator<CharT>>
6107std::basic_istream<CharT, Traits>&
6108from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
6109 fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev,
6110 std::chrono::minutes* offset)
6112 using std::numeric_limits;
6114 using std::chrono::duration;
6115 using std::chrono::duration_cast;
6116 using std::chrono::seconds;
6117 using std::chrono::minutes;
6118 using std::chrono::hours;
6119 using detail::round_i;
6120 typename std::basic_istream<CharT, Traits>::sentry ok{is,
true};
6123 gul17::date::detail::save_istream<CharT, Traits> ss(is);
6125 is.flags(std::ios::skipws | std::ios::dec);
6128 auto& f = std::use_facet<std::time_get<CharT>>(is.getloc());
6131 const CharT* command =
nullptr;
6132 auto modified = CharT{};
6135 constexpr const int not_a_year = numeric_limits<short>::min();
6136 constexpr const int not_a_2digit_year = 100;
6137 constexpr const int not_a_century = not_a_year / 100;
6138 constexpr const int not_a_month = 0;
6139 constexpr const int not_a_day = 0;
6140 constexpr const int not_a_hour = numeric_limits<int>::min();
6141 constexpr const int not_a_hour_12_value = 0;
6142 constexpr const int not_a_minute = not_a_hour;
6143 constexpr const Duration not_a_second = Duration::min();
6144 constexpr const int not_a_doy = -1;
6145 constexpr const int not_a_weekday = 8;
6146 constexpr const int not_a_week_num = 100;
6147 constexpr const int not_a_ampm = -1;
6148 constexpr const minutes not_a_offset = minutes::min();
6151 int y = not_a_2digit_year;
6152 int g = not_a_2digit_year;
6154 int C = not_a_century;
6155 int m = not_a_month;
6158 int wd = not_a_weekday;
6160 int I = not_a_hour_12_value;
6162 int M = not_a_minute;
6163 Duration s = not_a_second;
6164 int U = not_a_week_num;
6165 int V = not_a_week_num;
6166 int W = not_a_week_num;
6167 std::basic_string<CharT, Traits, Alloc> temp_abbrev;
6168 minutes temp_offset = not_a_offset;
6174 using detail::checked_set;
6175 for (; *fmt != CharT{} && !is.fail(); ++fmt)
6185 int trial_wd = not_a_weekday;
6186 if (*fmt ==
'a' || *fmt ==
'A')
6188 if (modified == CharT{})
6191 ios::iostate err = ios::goodbit;
6192 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6195 trial_wd = tm.tm_wday;
6197 auto nm = detail::weekday_names();
6198 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6204 read(is, CharT{
'%'}, width, modified, *fmt);
6209 if (modified == CharT{})
6211 if (modified != CharT{
'E'})
6214 read(is, ru{trial_wd, 1, width == -1 ?
6215 1u :
static_cast<unsigned>(width)});
6220 if (!(1 <= trial_wd && trial_wd <= 7))
6222 trial_wd = not_a_weekday;
6223 is.setstate(ios::failbit);
6225 else if (trial_wd == 7)
6230 if (!(0 <= trial_wd && trial_wd <= 6))
6232 trial_wd = not_a_weekday;
6233 is.setstate(ios::failbit);
6239 else if (modified == CharT{
'O'})
6241 ios::iostate err = ios::goodbit;
6242 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6245 trial_wd = tm.tm_wday;
6249 read(is, CharT{
'%'}, width, modified, *fmt);
6251 if (trial_wd != not_a_weekday)
6252 checked_set(wd, trial_wd, not_a_weekday, is);
6265 if (modified == CharT{})
6267 int ttm = not_a_month;
6269 ios::iostate err = ios::goodbit;
6270 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6271 if ((err & ios::failbit) == 0)
6272 ttm = tm.tm_mon + 1;
6275 auto nm = detail::month_names();
6276 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6280 checked_set(m, ttm, not_a_month, is);
6283 read(is, CharT{
'%'}, width, modified, *fmt);
6294 if (modified != CharT{
'O'})
6297 ios::iostate err = ios::goodbit;
6298 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6299 if ((err & ios::failbit) == 0)
6301 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6302 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6303 checked_set(d, tm.tm_mday, not_a_day, is);
6304 checked_set(H, tm.tm_hour, not_a_hour, is);
6305 checked_set(M, tm.tm_min, not_a_minute, is);
6306 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6312 auto nm = detail::weekday_names();
6313 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6314 checked_set(wd,
static_cast<int>(i % 7), not_a_weekday, is);
6316 nm = detail::month_names();
6317 i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6318 checked_set(m,
static_cast<int>(i % 12 + 1), not_a_month, is);
6321 read(is, rs{td, 1, 2});
6322 checked_set(d, td, not_a_day, is);
6324 using dfs = detail::decimal_format_seconds<Duration>;
6325 constexpr const auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6329 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6330 CharT{
':'}, rld{S, 1, w});
6331 checked_set(H, tH, not_a_hour, is);
6332 checked_set(M, tM, not_a_minute, is);
6333 checked_set(s, round_i<Duration>(duration<long double>{S}),
6336 int tY = not_a_year;
6337 read(is, rs{tY, 1, 4u});
6338 checked_set(Y, tY, not_a_year, is);
6342 read(is, CharT{
'%'}, width, modified, *fmt);
6353 if (modified != CharT{
'O'})
6356 ios::iostate err = ios::goodbit;
6357 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6358 if ((err & ios::failbit) == 0)
6360 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6361 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6362 checked_set(d, tm.tm_mday, not_a_day, is);
6367 int ty = not_a_2digit_year;
6368 int tm = not_a_month;
6370 read(is, ru{tm, 1, 2}, CharT{
'/'}, ru{td, 1, 2}, CharT{
'/'},
6372 checked_set(y, ty, not_a_2digit_year, is);
6373 checked_set(m, tm, not_a_month, is);
6374 checked_set(d, td, not_a_day, is);
6378 read(is, CharT{
'%'}, width, modified, *fmt);
6389 if (modified != CharT{
'O'})
6392 ios::iostate err = ios::goodbit;
6393 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6394 if ((err & ios::failbit) == 0)
6396 checked_set(H, tm.tm_hour, not_a_hour, is);
6397 checked_set(M, tm.tm_min, not_a_minute, is);
6398 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6404 using dfs = detail::decimal_format_seconds<Duration>;
6405 constexpr const auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6406 int tH = not_a_hour;
6407 int tM = not_a_minute;
6409 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6410 CharT{
':'}, rld{S, 1, w});
6411 checked_set(H, tH, not_a_hour, is);
6412 checked_set(M, tM, not_a_minute, is);
6413 checked_set(s, round_i<Duration>(duration<long double>{S}),
6418 read(is, CharT{
'%'}, width, modified, *fmt);
6429 int tC = not_a_century;
6431 if (modified == CharT{})
6434 read(is, rs{tC, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6439 ios::iostate err = ios::goodbit;
6440 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6441 if ((err & ios::failbit) == 0)
6443 auto tY = tm.tm_year + 1900;
6444 tC = (tY >= 0 ? tY : tY-99) / 100;
6449 checked_set(C, tC, not_a_century, is);
6460 if (modified == CharT{})
6462 int tn = not_a_month;
6464 int ty = not_a_2digit_year;
6465 read(is, ru{tn, 1, 2}, CharT{
'\0'}, CharT{
'/'}, CharT{
'\0'},
6466 ru{td, 1, 2}, CharT{
'\0'}, CharT{
'/'}, CharT{
'\0'},
6468 checked_set(y, ty, not_a_2digit_year, is);
6469 checked_set(m, tn, not_a_month, is);
6470 checked_set(d, td, not_a_day, is);
6473 read(is, CharT{
'%'}, width, modified, *fmt);
6484 if (modified == CharT{})
6486 int tY = not_a_year;
6487 int tn = not_a_month;
6489 read(is, rs{tY, 1, width == -1 ? 4u :
static_cast<unsigned>(width)},
6490 CharT{
'-'}, ru{tn, 1, 2}, CharT{
'-'}, ru{td, 1, 2});
6491 checked_set(Y, tY, not_a_year, is);
6492 checked_set(m, tn, not_a_month, is);
6493 checked_set(d, td, not_a_day, is);
6496 read(is, CharT{
'%'}, width, modified, *fmt);
6509 if (modified == CharT{})
6511 if (modified != CharT{
'E'})
6515 read(is, rs{td, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6516 checked_set(d, td, not_a_day, is);
6519 else if (modified == CharT{
'O'})
6521 ios::iostate err = ios::goodbit;
6522 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6526 if ((err & ios::failbit) == 0)
6527 checked_set(d, tm.tm_mday, not_a_day, is);
6532 read(is, CharT{
'%'}, width, modified, *fmt);
6544 if (modified == CharT{})
6546 if (modified != CharT{
'E'})
6549 int tH = not_a_hour;
6550 read(is, ru{tH, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6551 checked_set(H, tH, not_a_hour, is);
6554 else if (modified == CharT{
'O'})
6556 ios::iostate err = ios::goodbit;
6557 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6558 if ((err & ios::failbit) == 0)
6559 checked_set(H, tm.tm_hour, not_a_hour, is);
6564 read(is, CharT{
'%'}, width, modified, *fmt);
6575 if (modified == CharT{})
6577 int tI = not_a_hour_12_value;
6579 read(is, rs{tI, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6580 if (!(1 <= tI && tI <= 12))
6581 is.setstate(ios::failbit);
6582 checked_set(I, tI, not_a_hour_12_value, is);
6585 read(is, CharT{
'%'}, width, modified, *fmt);
6596 if (modified == CharT{})
6599 read(is, ru{tj, 1, width == -1 ? 3u :
static_cast<unsigned>(width)});
6600 checked_set(j, tj, not_a_doy, is);
6603 read(is, CharT{
'%'}, width, modified, *fmt);
6615 if (modified == CharT{})
6617 if (modified != CharT{
'E'})
6620 int tM = not_a_minute;
6621 read(is, ru{tM, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6622 checked_set(M, tM, not_a_minute, is);
6625 else if (modified == CharT{
'O'})
6627 ios::iostate err = ios::goodbit;
6628 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6629 if ((err & ios::failbit) == 0)
6630 checked_set(M, tm.tm_min, not_a_minute, is);
6635 read(is, CharT{
'%'}, width, modified, *fmt);
6647 if (modified == CharT{})
6649 if (modified != CharT{
'E'})
6652 int tn = not_a_month;
6653 read(is, rs{tn, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6654 checked_set(m, tn, not_a_month, is);
6657 else if (modified == CharT{
'O'})
6659 ios::iostate err = ios::goodbit;
6660 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6661 if ((err & ios::failbit) == 0)
6662 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6667 read(is, CharT{
'%'}, width, modified, *fmt);
6679 if (modified == CharT{})
6683 auto ic = is.peek();
6684 if (Traits::eq_int_type(ic, Traits::eof()))
6686 ios::iostate err = ios::eofbit;
6688 err |= ios::failbit;
6696 else if (*fmt ==
'n')
6697 is.setstate(ios::failbit);
6700 read(is, CharT{
'%'}, width, modified, *fmt);
6711 if (modified == CharT{})
6713 int tp = not_a_ampm;
6717 ios::iostate err = ios::goodbit;
6718 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6720 if (tm.tm_hour == 1)
6722 else if (tm.tm_hour == 13)
6727 auto nm = detail::ampm_names();
6728 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6729 tp =
static_cast<decltype(tp)
>(i);
6731 checked_set(p, tp, not_a_ampm, is);
6734 read(is, CharT{
'%'}, width, modified, *fmt);
6746 if (modified == CharT{})
6749 ios::iostate err = ios::goodbit;
6750 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6751 if ((err & ios::failbit) == 0)
6753 checked_set(H, tm.tm_hour, not_a_hour, is);
6754 checked_set(M, tm.tm_min, not_a_hour, is);
6755 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6761 using dfs = detail::decimal_format_seconds<Duration>;
6762 constexpr const auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6764 int tI = not_a_hour_12_value;
6765 int tM = not_a_minute;
6766 read(is, ru{tI, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6767 CharT{
':'}, rld{S, 1, w});
6768 checked_set(I, tI, not_a_hour_12_value, is);
6769 checked_set(M, tM, not_a_minute, is);
6770 checked_set(s, round_i<Duration>(duration<long double>{S}),
6773 auto nm = detail::ampm_names();
6774 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6775 checked_set(p,
static_cast<int>(i), not_a_ampm, is);
6779 read(is, CharT{
'%'}, width, modified, *fmt);
6790 if (modified == CharT{})
6792 int tH = not_a_hour;
6793 int tM = not_a_minute;
6794 read(is, ru{tH, 1, 2}, CharT{
'\0'}, CharT{
':'}, CharT{
'\0'},
6795 ru{tM, 1, 2}, CharT{
'\0'});
6796 checked_set(H, tH, not_a_hour, is);
6797 checked_set(M, tM, not_a_minute, is);
6800 read(is, CharT{
'%'}, width, modified, *fmt);
6812 if (modified == CharT{})
6814 if (modified != CharT{
'E'})
6817 using dfs = detail::decimal_format_seconds<Duration>;
6818 constexpr const auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6820 read(is, rld{S, 1, width == -1 ? w :
static_cast<unsigned>(width)});
6821 checked_set(s, round_i<Duration>(duration<long double>{S}),
6825 else if (modified == CharT{
'O'})
6827 ios::iostate err = ios::goodbit;
6828 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6829 if ((err & ios::failbit) == 0)
6830 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6836 read(is, CharT{
'%'}, width, modified, *fmt);
6847 if (modified == CharT{})
6849 using dfs = detail::decimal_format_seconds<Duration>;
6850 constexpr const auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6851 int tH = not_a_hour;
6852 int tM = not_a_minute;
6854 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6855 CharT{
':'}, rld{S, 1, w});
6856 checked_set(H, tH, not_a_hour, is);
6857 checked_set(M, tM, not_a_minute, is);
6858 checked_set(s, round_i<Duration>(duration<long double>{S}),
6862 read(is, CharT{
'%'}, width, modified, *fmt);
6874 if (modified == CharT{})
6876 if (modified != CharT{
'O'})
6879 int tY = not_a_year;
6880 read(is, rs{tY, 1, width == -1 ? 4u :
static_cast<unsigned>(width)});
6881 checked_set(Y, tY, not_a_year, is);
6884 else if (modified == CharT{
'E'})
6886 ios::iostate err = ios::goodbit;
6887 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6888 if ((err & ios::failbit) == 0)
6889 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6894 read(is, CharT{
'%'}, width, modified, *fmt);
6906 if (modified == CharT{})
6909 int ty = not_a_2digit_year;
6910 read(is, ru{ty, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6911 checked_set(y, ty, not_a_2digit_year, is);
6916 ios::iostate err = ios::goodbit;
6917 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6918 if ((err & ios::failbit) == 0)
6919 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6933 if (modified == CharT{})
6935 int tg = not_a_2digit_year;
6936 read(is, ru{tg, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6937 checked_set(g, tg, not_a_2digit_year, is);
6940 read(is, CharT{
'%'}, width, modified, *fmt);
6951 if (modified == CharT{})
6953 int tG = not_a_year;
6954 read(is, rs{tG, 1, width == -1 ? 4u :
static_cast<unsigned>(width)});
6955 checked_set(G, tG, not_a_year, is);
6958 read(is, CharT{
'%'}, width, modified, *fmt);
6969 if (modified == CharT{})
6971 int tU = not_a_week_num;
6972 read(is, ru{tU, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6973 checked_set(U, tU, not_a_week_num, is);
6976 read(is, CharT{
'%'}, width, modified, *fmt);
6987 if (modified == CharT{})
6989 int tV = not_a_week_num;
6990 read(is, ru{tV, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6991 checked_set(V, tV, not_a_week_num, is);
6994 read(is, CharT{
'%'}, width, modified, *fmt);
7005 if (modified == CharT{})
7007 int tW = not_a_week_num;
7008 read(is, ru{tW, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7009 checked_set(W, tW, not_a_week_num, is);
7012 read(is, CharT{
'%'}, width, modified, *fmt);
7024 if (modified == CharT{})
7030 read(is, CharT{
'%'}, width, modified, *fmt);
7042 if (modified == CharT{})
7045 read(is, CharT{
'%'}, width, modified, *fmt);
7057 minutes toff = not_a_offset;
7059 auto ic = is.peek();
7060 if (!Traits::eq_int_type(ic, Traits::eof()))
7062 auto c =
static_cast<char>(Traits::to_char_type(ic));
7066 if (modified == CharT{})
7068 read(is, rs{tH, 2, 2});
7070 toff = hours{std::abs(tH)};
7074 if (!Traits::eq_int_type(ic, Traits::eof()))
7076 auto c =
static_cast<char>(Traits::to_char_type(ic));
7077 if (
'0' <= c && c <=
'9')
7079 read(is, ru{tM, 2, 2});
7081 toff += minutes{tM};
7088 read(is, rs{tH, 1, 2});
7090 toff = hours{std::abs(tH)};
7094 if (!Traits::eq_int_type(ic, Traits::eof()))
7096 auto c =
static_cast<char>(Traits::to_char_type(ic));
7100 read(is, ru{tM, 2, 2});
7102 toff += minutes{tM};
7109 checked_set(temp_offset, toff, not_a_offset, is);
7120 if (modified == CharT{})
7122 std::basic_string<CharT, Traits, Alloc> buf;
7123 while (is.rdstate() == std::ios::goodbit)
7125 auto i = is.rdbuf()->sgetc();
7126 if (Traits::eq_int_type(i, Traits::eof()))
7128 is.setstate(ios::eofbit);
7131 auto wc = Traits::to_char_type(i);
7132 auto c =
static_cast<char>(wc);
7134 if (!(CharT{1} < wc && wc < CharT{127}) || !(isalnum(c) ||
7135 c ==
'_' || c ==
'/' || c ==
'-' || c ==
'+'))
7138 is.rdbuf()->sbumpc();
7141 is.setstate(ios::failbit);
7142 checked_set(temp_abbrev, buf, {}, is);
7145 read(is, CharT{
'%'}, width, modified, *fmt);
7156 if (width == -1 && modified == CharT{} &&
'0' <= *fmt && *fmt <=
'9')
7158 width =
static_cast<char>(*fmt) -
'0';
7159 while (
'0' <= fmt[1] && fmt[1] <=
'9')
7160 width = 10*width +
static_cast<char>(*++fmt) -
'0';
7164 if (modified == CharT{})
7165 read(is, CharT{
'%'}, width, *fmt);
7167 read(is, CharT{
'%'}, width, modified, *fmt);
7175 if (isspace(
static_cast<unsigned char>(*fmt)))
7188 if (is.rdstate() == ios::goodbit && command)
7190 if (modified == CharT{})
7191 read(is, CharT{
'%'}, width);
7193 read(is, CharT{
'%'}, width, modified);
7197 if (y != not_a_2digit_year)
7200 if (!(0 <= y && y <= 99))
7202 if (C == not_a_century)
7204 if (Y == not_a_year)
7213 C = (Y >= 0 ? Y : Y-100) / 100;
7220 tY = 100*(C+1) - (y == 0 ? 100 : y);
7221 if (Y != not_a_year && Y != tY)
7225 if (g != not_a_2digit_year)
7228 if (!(0 <= g && g <= 99))
7230 if (C == not_a_century)
7232 if (G == not_a_year)
7241 C = (G >= 0 ? G : G-100) / 100;
7248 tG = 100*(C+1) - (g == 0 ? 100 : g);
7249 if (G != not_a_year && G != tG)
7253 if (Y <
static_cast<int>(year::min()) || Y >
static_cast<int>(year::max()))
7255 bool computed =
false;
7256 if (G != not_a_year && V != not_a_week_num && wd != not_a_weekday)
7258 year_month_day ymd_trial = sys_days(year{G-1}/December/Thursday[last]) +
7259 (Monday-Thursday) + weeks{V-1} +
7260 (weekday{
static_cast<unsigned>(wd)}-Monday);
7261 if (Y == not_a_year)
7262 Y =
static_cast<int>(ymd_trial.year());
7263 else if (year{Y} != ymd_trial.year())
7265 if (m == not_a_month)
7266 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7267 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7270 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7271 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7275 if (Y != not_a_year && U != not_a_week_num && wd != not_a_weekday)
7277 year_month_day ymd_trial = sys_days(year{Y}/January/Sunday[1]) +
7279 (weekday{
static_cast<unsigned>(wd)} - Sunday);
7280 if (Y == not_a_year)
7281 Y =
static_cast<int>(ymd_trial.year());
7282 else if (year{Y} != ymd_trial.year())
7284 if (m == not_a_month)
7285 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7286 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7289 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7290 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7294 if (Y != not_a_year && W != not_a_week_num && wd != not_a_weekday)
7296 year_month_day ymd_trial = sys_days(year{Y}/January/Monday[1]) +
7298 (weekday{
static_cast<unsigned>(wd)} - Monday);
7299 if (Y == not_a_year)
7300 Y =
static_cast<int>(ymd_trial.year());
7301 else if (year{Y} != ymd_trial.year())
7303 if (m == not_a_month)
7304 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7305 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7308 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7309 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7313 if (j != not_a_doy && Y != not_a_year)
7315 auto ymd_trial = year_month_day{local_days(year{Y}/1/1) + days{j-1}};
7316 if (m == not_a_month)
7317 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7318 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7321 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7322 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7326 auto ymd = year{Y}/m/d;
7329 if (wd == not_a_weekday)
7330 wd =
static_cast<int>((weekday(sys_days(ymd)) - Sunday).count());
7331 else if (wd !=
static_cast<int>((weekday(sys_days(ymd)) - Sunday).count()))
7335 if (G != not_a_year || V != not_a_week_num)
7338 auto G_trial = year_month_day{sd + days{3}}.year();
7339 auto start = sys_days((G_trial - years{1})/December/Thursday[last]) +
7340 (Monday - Thursday);
7344 if (V != not_a_week_num)
7345 start = sys_days((G_trial - years{1})/December/Thursday[last])
7346 + (Monday - Thursday);
7348 if (G != not_a_year && G !=
static_cast<int>(G_trial))
7350 if (V != not_a_week_num)
7352 auto V_trial = duration_cast<weeks>(sd - start).count() + 1;
7357 if (U != not_a_week_num)
7359 auto start = sys_days(Sunday[1]/January/ymd.year());
7360 auto U_trial = floor<weeks>(sys_days(ymd) - start).count() + 1;
7364 if (W != not_a_week_num)
7366 auto start = sys_days(Monday[1]/January/ymd.year());
7367 auto W_trial = floor<weeks>(sys_days(ymd) - start).count() + 1;
7374 if (I != not_a_hour_12_value)
7376 if (!(1 <= I && I <= 12))
7378 if (p != not_a_ampm)
7386 if (H == not_a_hour)
7394 if (H != not_a_hour)
7398 if (H != 0 && H != 12)
7401 else if (!(I == H || I == H+12))
7410 if (H != not_a_hour)
7413 fds.tod = hh_mm_ss<Duration>{hours{H}};
7415 if (M != not_a_minute)
7418 fds.tod.m_ = minutes{M};
7420 if (s != not_a_second)
7423 fds.tod.s_ = detail::decimal_format_seconds<Duration>{s};
7428 fds.tod.h_ += hours{days{j}};
7430 if (wd != not_a_weekday)
7431 fds.wd = weekday{
static_cast<unsigned>(wd)};
7432 if (abbrev !=
nullptr)
7433 *abbrev = std::move(temp_abbrev);
7434 if (offset !=
nullptr && temp_offset != not_a_offset)
7435 *offset = temp_offset;
7440 is.setstate(ios::failbit);
7444template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7445std::basic_istream<CharT, Traits>&
7446from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, year& y,
7447 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7448 std::chrono::minutes* offset =
nullptr)
7450 using CT = std::chrono::seconds;
7452 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7453 if (!fds.ymd.year().ok())
7454 is.setstate(std::ios::failbit);
7460template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7461std::basic_istream<CharT, Traits>&
7462from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, month& m,
7463 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7464 std::chrono::minutes* offset =
nullptr)
7466 using CT = std::chrono::seconds;
7468 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7469 if (!fds.ymd.month().ok())
7470 is.setstate(std::ios::failbit);
7472 m = fds.ymd.month();
7476template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7477std::basic_istream<CharT, Traits>&
7478from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, day& d,
7479 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7480 std::chrono::minutes* offset =
nullptr)
7482 using CT = std::chrono::seconds;
7484 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7485 if (!fds.ymd.day().ok())
7486 is.setstate(std::ios::failbit);
7492template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7493std::basic_istream<CharT, Traits>&
7494from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, weekday& wd,
7495 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7496 std::chrono::minutes* offset =
nullptr)
7498 using CT = std::chrono::seconds;
7500 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7502 is.setstate(std::ios::failbit);
7508template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7509std::basic_istream<CharT, Traits>&
7510from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, year_month& ym,
7511 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7512 std::chrono::minutes* offset =
nullptr)
7514 using CT = std::chrono::seconds;
7516 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7517 if (!fds.ymd.month().ok())
7518 is.setstate(std::ios::failbit);
7520 ym = fds.ymd.year()/fds.ymd.month();
7524template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7525std::basic_istream<CharT, Traits>&
7526from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, month_day& md,
7527 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7528 std::chrono::minutes* offset =
nullptr)
7530 using CT = std::chrono::seconds;
7532 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7533 if (!fds.ymd.month().ok() || !fds.ymd.day().ok())
7534 is.setstate(std::ios::failbit);
7536 md = fds.ymd.month()/fds.ymd.day();
7540template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7541std::basic_istream<CharT, Traits>&
7542from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7543 year_month_day& ymd, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7544 std::chrono::minutes* offset =
nullptr)
7546 using CT = std::chrono::seconds;
7548 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7550 is.setstate(std::ios::failbit);
7556template <
class Duration,
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7557std::basic_istream<CharT, Traits>&
7558from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7559 sys_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7560 std::chrono::minutes* offset =
nullptr)
7562 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
7563 using detail::round_i;
7564 std::chrono::minutes offset_local{};
7565 auto offptr = offset ? offset : &offset_local;
7568 gul17::date::from_stream(is, fmt, fds, abbrev, offptr);
7569 if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
7570 is.setstate(std::ios::failbit);
7572 tp = round_i<Duration>(sys_days(fds.ymd) - *offptr + fds.tod.to_duration());
7576template <
class Duration,
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7577std::basic_istream<CharT, Traits>&
7578from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7579 local_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7580 std::chrono::minutes* offset =
nullptr)
7582 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
7583 using detail::round_i;
7586 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7587 if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
7588 is.setstate(std::ios::failbit);
7590 tp = round_i<Duration>(local_seconds{local_days(fds.ymd)} + fds.tod.to_duration());
7594template <
class Rep,
class Period,
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7595std::basic_istream<CharT, Traits>&
7596from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7597 std::chrono::duration<Rep, Period>& d,
7598 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7599 std::chrono::minutes* offset =
nullptr)
7601 using Duration = std::chrono::duration<Rep, Period>;
7602 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
7603 using detail::round_i;
7605 gul17::date::from_stream(is, fmt, fds, abbrev, offset);
7607 is.setstate(std::ios::failbit);
7609 d = round_i<Duration>(fds.tod.to_duration());
7613template <
class Parsable,
class CharT,
class Traits = std::
char_traits<CharT>,
7614 class Alloc = std::allocator<CharT>>
7617 const std::basic_string<CharT, Traits, Alloc> format_;
7619 std::basic_string<CharT, Traits, Alloc>* abbrev_;
7620 std::chrono::minutes* offset_;
7623 parse_manip(std::basic_string<CharT, Traits, Alloc> format, Parsable& tp,
7624 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7625 std::chrono::minutes* offset =
nullptr)
7626 : format_(std::move(format))
7632 parse_manip(
const CharT* format, Parsable& tp,
7633 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7634 std::chrono::minutes* offset =
nullptr)
7641 parse_manip(std::basic_string_view<CharT, Traits> format, Parsable& tp,
7642 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7643 std::chrono::minutes* offset =
nullptr)
7651template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7652std::basic_istream<CharT, Traits>&
7653operator>>(std::basic_istream<CharT, Traits>& is,
7654 const parse_manip<Parsable, CharT, Traits, Alloc>& x)
7656 return gul17::date::from_stream(is, x.format_.c_str(), x.tp_, x.abbrev_, x.offset_);
7659template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7661parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp)
7662 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7663 format.c_str(), tp),
7664 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp})
7666 return {format, tp};
7669template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7671parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
7672 std::basic_string<CharT, Traits, Alloc>& abbrev)
7673 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7674 format.c_str(), tp, &abbrev),
7675 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
7677 return {format, tp, &abbrev};
7680template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7682parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
7683 std::chrono::minutes& offset)
7684 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7686 std::declval<std::basic_string<CharT, Traits, Alloc>*>(),
7688 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp,
nullptr, &offset})
7690 return {format, tp,
nullptr, &offset};
7693template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7695parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
7696 std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
7697 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7698 format.c_str(), tp, &abbrev, &offset),
7699 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
7701 return {format, tp, &abbrev, &offset};
7706template <
class Parsable,
class CharT>
7708parse(
const CharT* format, Parsable& tp)
7709 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT>&>(), format, tp),
7710 parse_manip<Parsable, CharT>{format, tp})
7712 return {format, tp};
7715template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7717parse(
const CharT* format, Parsable& tp, std::basic_string<CharT, Traits, Alloc>& abbrev)
7718 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
7720 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
7722 return {format, tp, &abbrev};
7725template <
class Parsable,
class CharT>
7727parse(
const CharT* format, Parsable& tp, std::chrono::minutes& offset)
7728 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT>&>(), format,
7729 tp, std::declval<std::basic_string<CharT>*>(), &offset),
7730 parse_manip<Parsable, CharT>{format, tp,
nullptr, &offset})
7732 return {format, tp,
nullptr, &offset};
7735template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7737parse(
const CharT* format, Parsable& tp,
7738 std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
7739 ->
decltype(gul17::date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
7740 tp, &abbrev, &offset),
7741 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
7743 return {format, tp, &abbrev, &offset};
7748template <
class CharT,
class Traits,
class Rep,
class Period>
7750std::basic_ostream<CharT, Traits>&
7751operator<<(std::basic_ostream<CharT, Traits>& os,
7752 const std::chrono::duration<Rep, Period>& d)
7754 return os << detail::make_string<CharT, Traits>::from(d.count()) +
7755 detail::get_units<CharT>(
typename Period::type{});
7762# pragma warning(pop)
7766# pragma GCC diagnostic pop
auto constexpr bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition bit_manip.h:121
constexpr auto abs(ValueT n) noexcept -> std::enable_if_t< std::is_unsigned< ValueT >::value, ValueT >
Compute the absolute value of a number.
Definition num_util.h:53
Namespace gul17 contains all functions and classes of the General Utility Library.
Definition doxygen.h:26