-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathiso_week.html
2932 lines (2363 loc) · 76.4 KB
/
iso_week.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>iso_week redirect</title>
<META http-equiv="refresh" content="5;URL=http://howardhinnant.github.io/date/iso_week.html">
<style>
p {text-align:justify}
li {text-align:justify}
blockquote.note
{
background-color:#E0E0E0;
padding-left: 15px;
padding-right: 15px;
padding-top: 1px;
padding-bottom: 1px;
}
ins {color:#00A000}
del {color:#A00000}
code {white-space:pre;}
</style>
</head>
<body>
<center>
The contents you are looking for have moved. You will be redirected to the new
location automatically in 5 seconds. Please bookmark the correct page at
<a href="http://howardhinnant.github.io/date/iso_week.html">http://howardhinnant.github.io/date/iso_week.html</a>
</center>
<!--
<address align=right>
<br/>
<br/>
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
2015-12-23<br/>
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"> <img alt="Creative
Commons License" style="border-width:0"
src="http://i.creativecommons.org/l/by/4.0/80x15.png" /></a><br /> This work is licensed
under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative
Commons Attribution 4.0 International License</a>.
</address>
<hr/>
<h1 align=center><code>iso_week</code></h1>
<h2>Contents</h2>
<ul>
<li><a href="#Introduction">Introduction</a></li>
<li><a href="#Implementation">Implementation</a></li>
<li><a href="#Overview">Overview</a></li>
<li><a href="#Reference">Reference</a></li>
</ul>
<a name="Introduction"></a><h2>Introduction</h2>
<p>
This paper fully documents an
<a href="https://en.wikipedia.org/wiki/ISO_week_date">ISO week date calendar</a>
that is fully interoperable with
<a href="date_v2.html"><code>date</code></a>.
</p>
<a name="Implementation"></a><h2>Implementation</h2>
<p>
This entire library is implemented in a single header:
<a href="https://github.com/HowardHinnant/date/blob/master/iso_week.h">iso_week.h</a>
and is open source using the MIT license.
</p>
<a name="Overview"></a><h2>Overview</h2>
<p>
This library creates field types that hold the year, week number and weekday
associated with a <a href="https://en.wikipedia.org/wiki/ISO_week_date">ISO week date</a>.
For example, to specify the Saturday of the 51st week of 2015 one can say:
</p>
<blockquote><pre>
#include "iso_week.h"
#include <iostream>
int
main()
{
using namespace iso_week::literals;
auto iso_date = sat/51/2015;
std::cout << iso_date << '\n';
}
</pre></blockquote>
<p>
The output of this program is:
</p>
<blockquote><pre>
2015-W51-Sat
</pre></blockquote>
<p>
In this example <code>iso_date</code> has type <code>iso_week::year_weeknum_weekday</code>,
and this type does nothing but hold the three quantities: <code>year</code>,
<code>weeknum</code> and <code>weekday</code>. This is such trivial functionality that
it almost seems useless. Anyone can write a type to be constructed from three values,
and then print them back out when requested.
</p>
<p>
The real power of <code>year_weeknum_weekday</code> is that it can implicitly convert to
and from <a href="date_v2.html#day_point"><code>day_point</code></a>. And
<a href="date_v2.html#day_point"><code>day_point</code></a> is just a type alias for:
</p>
<blockquote><pre>
std::chrono::time_point<std::chrono::system_clock, days>
</pre></blockquote>
<p>
This is the exact same <code>day_point</code> used by the
<a href="date_v2.html"><code>date</code></a> and <a href="tz.html">time zone</a>
libraries. And so by simply having conversions to and from <code>day_point</code>,
<code>iso_week::year_weeknum_weekday</code> becomes seamlessly interoperable with all
of the types in <a href="date_v2.html"><code>date</code></a> and
<a href="tz.html">time zone</a> such as <code>date::year_month_day</code> and
<code>date::Zone</code>:
</p>
<blockquote><pre>
#include "date.h"
#include "iso_week.h"
#include "tz.h"
#include <iostream>
int
main()
{
using namespace std::chrono;
using namespace date;
using namespace iso_week;
auto zone = locate_zone("America/New_York");
auto now = zone->to_local(system_clock::now());
auto dp = floor<days>(now.first);
auto iso_date = year_weeknum_weekday{dp};
auto civil_date = year_month_day{dp};
auto time = make_time(duration_cast<minutes>(now.first-dp));
std::cout << "It is currently " << time << ' ' << now.second << " on "
<< iso_date << " which is also " << civil_date << '\n';
}
</pre></blockquote>
<p>
Which just output for me:
</p>
<blockquote><pre>
It is currently 18:33 EST on 2015-W51-Sat which is also 2015-12-19
</pre></blockquote>
<p>
Or if you want to find the civil date of the last day of the ISO week year for 2015, then
(knowning the last day of the week is Sunday in this calendar) it is:
</p>
<blockquote><pre>
using namespace iso_week::literals;
std::cout << date::year_month_day{2015_y/last/sun} << '\n';
</pre></blockquote>
<p>
Which will output:
</p>
<blockquote><pre>
2016-01-03
</pre></blockquote>
<p>
And of course one can convert in the opposite direction:
</p>
<blockquote><pre>
using namespace date::literals;
std::cout << iso_week::year_weeknum_weekday{2016_y/1/3} << '\n';
</pre></blockquote>
<p>
Which will output:
</p>
<blockquote><pre>
2015-W53-Sun
</pre></blockquote>
<p>
In particular, note that for this day, the <code>iso_week::year</code> is 2015 and the
<code>date::year</code> is 2016.
</p>
<p>
This brings us to an important type-safety feature of these libraries: The
<code>iso_week::year</code> and the <code>date::year</code> are two <i>distinct</i> types.
They represent concepts that are <i>very</i> similar. They almost always have the same
value for the same <code>day_point</code>. But as in this example, they are occasionally
different. It is not unheard of for computer systems to conflate these two very similar
types, resulting in bugs that are hard to find because they are relatively rare. Having
the C++ type system help you keep these similar but different concepts distinct is a
solid step towards finding bugs at compile time!
</p>
<a name="Reference"></a><h2>Reference</h2>
<p>
Here is a detailed specification of the entire library. This specification is detailed
enough that you could write your own implementation from it if desired. But feel free
to use <a href="https://github.com/HowardHinnant/date/blob/master/iso_week.h">this one</a>
instead. Each type, and each operation is simple
and predictable.
</p>
<table>
<tr><td>durations</td><td> </td></tr>
<tr><td> </td><td><a href="#days"><code>days</code></a></td></tr>
<tr><td> </td><td><a href="#weeks"><code>weeks</code></a></td></tr>
<tr><td> </td><td><a href="#years"><code>years</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td>time_point</td><td> </td></tr>
<tr><td> </td><td><a href="#day_point"><code>day_point</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td>types</td><td> </td></tr>
<tr><td> </td><td><a href="#last_week"><code>last_week</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#weekday"><code>weekday</code></a></td></tr>
<tr><td> </td><td><a href="#weeknum"><code>weeknum</code></a></td></tr>
<tr><td> </td><td><a href="#year"><code>year</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#year_weeknum"><code>year_weeknum</code></a></td></tr>
<tr><td> </td><td><a href="#year_lastweek"><code>year_lastweek</code></a></td></tr>
<tr><td> </td><td><a href="#weeknum_weekday"><code>weeknum_weekday</code></a></td></tr>
<tr><td> </td><td><a href="#lastweek_weekday"><code>lastweek_weekday</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#year_weeknum_weekday"><code>year_weeknum_weekday</code></a></td></tr>
<tr><td> </td><td><a href="#year_lastweek_weekday"><code>year_lastweek_weekday</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td>date composition operators</td><td> </td></tr>
<tr><td> </td><td><a href="#_1"><code>constexpr year_weeknum operator/(const year& y, const weeknum& wn) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_2"><code>constexpr year_weeknum operator/(const year& y, int wn) noexcept;</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#_3"><code>constexpr year_lastweek operator/(const year& y, last_week wn) noexcept;</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#_4"><code>constexpr weeknum_weekday operator/(const weeknum& wn, const weekday& wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_5"><code>constexpr weeknum_weekday operator/(const weeknum& wn, int wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_6"><code>constexpr weeknum_weekday operator/(const weekday& wd, const weeknum& wn) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_7"><code>constexpr weeknum_weekday operator/(const weekday& wd, int wn) noexcept;</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#_8"><code>constexpr lastweek_weekday operator/(const last_week& wn, const weekday& wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_9"><code>constexpr lastweek_weekday operator/(const last_week& wn, int wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_10"><code>constexpr lastweek_weekday operator/(const weekday& wd, const last_week& wn) noexcept;</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#_11"><code>constexpr year_weeknum_weekday operator/(const year_weeknum& ywn, const weekday& wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_12"><code>constexpr year_weeknum_weekday operator/(const year_weeknum& ywn, int wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_13"><code>constexpr year_weeknum_weekday operator/(const weeknum_weekday& wnwd, const year& y) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_14"><code>constexpr year_weeknum_weekday operator/(const weeknum_weekday& wnwd, int y) noexcept;</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#_15"><code>constexpr year_lastweek_weekday operator/(const year_lastweek& ylw, const weekday& wd) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_16"><code>constexpr year_lastweek_weekday operator/(const year_lastweek& ylw, int wd) noexcept;</code></a></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td><a href="#_17"><code>constexpr year_lastweek_weekday operator/(const lastweek_weekday& lwwd, const year& y) noexcept;</code></a></td></tr>
<tr><td> </td><td><a href="#_18"><code>constexpr year_lastweek_weekday operator/(const lastweek_weekday& lwwd, int y) noexcept;</code></a></td></tr>
</table>
<p>
Everything here is contained in the namespace <code>iso_week</code>. The literal
operators, and the constexpr field literals (e.g. <code>sun</code>, <code>last</code>,
etc.) are in namespace <code>iso_week::literals</code> and imported into namespace
<code>iso_week</code>.
</p>
<a name="days"></a><h3><code>days</code></h3>
<blockquote>
<p>
<code>days</code> is a <code>std::chrono::duration</code> with a tick period of 24 hours.
This definition is not an SI unit but <a
href="http://www.bipm.org/en/publications/si-brochure/table6.html">is accepted for use
with SI</a>. <code>days</code> is the resultant type when subtracting two
<code>day_point</code>s.
</p>
<pre>
using days = std::chrono::duration
<int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
</pre></blockquote>
<a name="weeks"></a><h3><code>weeks</code></h3>
<blockquote>
<p>
<code>weeks</code> is a <code>std::chrono::duration</code> with a tick period of 7 days.
This definition is widely recognized and predates the Gregorian calendar. It is
consistent with <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a>.
<code>weeks</code> will implicitly convert to <code>days</code> but not vice-versa.
</p>
<pre>
using weeks = std::chrono::duration
<int, std::ratio_multiply<std::ratio<7>, days::period>>;
</pre></blockquote>
<a name="years"></a><h3><code>years</code></h3>
<blockquote>
<p>
<code>years</code> is a <code>std::chrono::duration</code> with a tick period of 365.2425
days. This definition accurately describes the length of the average year in the
ISO week calendar. <code>years</code> is the resultant type when subtracting two
<code>year</code> field-based time points. <code>years</code> is not implicitly
convertible to <code>days</code> or <code>weeks</code> nor vice-versa.
</p>
<pre>
using years = std::chrono::duration
<int, std::ratio_multiply<std::ratio<146097, 400>, days::period>>;
</pre></blockquote>
<a name="day_point"></a><h3><code>day_point</code></h3>
<blockquote>
<p>
<code>day_point</code> is a <code>std::chrono::time_point</code> using
<code>std::chrono::system_clock</code> and <code>days</code>. This makes
<code>day_point</code> interoperable with
<code>std::chrono::system_clock::time_point</code>. It is simply a count of days since
the epoch of <code>std::chrono::system_clock</code> which in every implementation is
Jan. 1, 1970. <code>day_point</code> is a serial-based time point with a resolution of
<code>days</code>.
</p>
<pre>
using day_point = std::chrono::time_point<std::chrono::system_clock, days>;
</pre>
</blockquote>
<a name="last_week"></a><h3><code>last_week</code></h3>
<blockquote>
<p>
<code>last_week</code> is a <code>struct</code> that is <code>CopyConstructible</code>.
There exists a <code>constexpr</code> instance of <code>last_week</code> named
<code>last</code>. This is simply a tag type. It is used to indicate the last week of
the year.
</p>
<pre>
struct last_week
{
explicit last_week() = default;
};
inline namespace literals
{
constexpr iso_week::last_week last{};
}
</pre>
<p>
I am leading the C++ standard here a little with the <code>explicit</code> qualifier on
the default constructor. This compiles today, but doesn't have quite the desired
semantics. But it will when
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_toc.html#1518">CWG 1518</a>
passes. This will make it so that <code>{}</code> won't implicitly convert to
<code>last_week</code>. This addresses the concern expressed in
<a href="http://cplusplus.github.io/LWG/lwg-toc.html#2510">LWG 2510</a>.
</p>
</blockquote>
<a name="weekday"></a><h3><code>weekday</code></h3>
<blockquote>
<p><b>Synopsis</b></p>
<pre>
class weekday
{
unsigned char wd_; // exposition only
public:
explicit constexpr weekday(unsigned wd) noexcept;
constexpr weekday(const day_point& dp) noexcept;
constexpr weekday(date::weekday wd) noexcept;
explicit weekday(int) = delete;
weekday& operator++() noexcept;
weekday operator++(int) noexcept;
weekday& operator--() noexcept;
weekday operator--(int) noexcept;
weekday& operator+=(const days& d) noexcept;
weekday& operator-=(const days& d) noexcept;
constexpr explicit operator unsigned() const noexcept;
constexpr operator date::weekday() const noexcept;
constexpr bool ok() const noexcept;
};
constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
constexpr weekday operator+(const weekday& x, const days& y) noexcept;
constexpr weekday operator+(const days& x, const weekday& y) noexcept;
constexpr weekday operator-(const weekday& x, const days& y) noexcept;
constexpr days operator-(const weekday& x, const weekday& y) noexcept;
std::ostream& operator<<(std::ostream& os, const weekday& wd);
inline namespace literals
{
constexpr weekday mon{1u};
constexpr weekday tue{2u};
constexpr weekday wed{3u};
constexpr weekday thu{4u};
constexpr weekday fri{5u};
constexpr weekday sat{6u};
constexpr weekday sun{7u};
} // namespace literals
</pre>
<p><b>Overview</b></p>
<p>
<code>weekday</code> represents a day of the week in the ISO week calendar. It should
only be representing values in the range 1 to 7, corresponding to Monday thru Sunday.
However it may hold values outside this range. It can be constructed with any
<code>unsigned</code> value, which will be subsequently truncated to fit into
<code>weekday</code>'s internal storage. <code>weekday</code> is equality comparable.
<code>weekday</code> is not less-than comparable because there is no universal consensus
on which day is the first day of the week. This design chooses the encoding of 1 to 7 to
represent Monday thru Sunday only because this is consistent with ISO 8601.
However <code>weekday</code>'s comparison and arithmetic operations treat the
days of the week as a circular range, with no beginning and no end. One can stream out a
<code>weekday</code> for debugging purposes. <code>weekday</code> has explicit conversions
to and from <code>unsigned</code>. There are 7 <code>weekday</code> constants, one for each
day of the week.
</p>
<p>
A <code>weekday</code> can be implicitly constructed from a <code>day_point</code>. This
is the computation that discovers the day of the week of an arbitrary date.
</p>
<p>
A <code>weekday</code> can be implicitly converted to or from a <code>date::weekday</code>.
<code>iso_week::weekday</code> and <code>date::weekday</code> are distinct types, though
they represent very similar concepts. <code>date::weekday</code> can be indexed, and
<code>iso_week::weekday</code> can not. <code>date::weekday</code> is encoded as
[0, 6] representing [Sunday, Saturday], while <code>iso_week::weekday</code> is encoded as
[1, 7] representing [Monday, Sunday]. The conversion functions will correctly translate
between these encodings.
</p>
<p><b>Specification</b></p>
<p>
<code>weekday</code> is a trivially copyable class type.</br>
<code>weekday</code> is a standard-layout class type.</br>
<code>weekday</code> is a literal class type.</br>
</p>
<pre>
explicit constexpr weekday::weekday(unsigned wd) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>weekday</code> by constructing
<code>wd_</code> with <code>wd</code>.
</p>
</blockquote>
<pre>
constexpr weekday(const day_point& dp) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>weekday</code> by computing what day
of the week corresponds to the <code>day_point dp</code>, and representing that day of
the week in <code>wd_</code>.
</p>
<p>
<i>Example:</i> If <code>dp</code> represents 1970-01-01, the constructed
<code>weekday</code> shall represent Thursday by storing 4 in <code>wd_</code>.
</p>
</blockquote>
<pre>
constexpr weekday(date::weekday wd) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>weekday</code> from a
<code>date::weekday</code>. This changes the underlying encoding from [0, 6] ->
[sun, sat] to [1, 7] -> [mon, sun].
</p>
</blockquote>
<pre>
weekday& weekday::operator++() noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> If <code>wd_ != 6</code>, <code>++wd_</code>. Otherwise sets
<code>wd_</code> to 0.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
weekday weekday::operator++(int) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>++(*this)</code>.
</p>
<p>
<i>Returns:</i> A copy of <code>*this</code> as it existed on entry to this member
function.
</p>
</blockquote>
<pre>
weekday& weekday::operator--() noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> If <code>wd_ != 0</code>, <code>--wd_</code>. Otherwise sets
<code>wd_</code> to 6.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
weekday weekday::operator--(int) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>--(*this)</code>.
</p>
<p>
<i>Returns:</i> A copy of <code>*this</code> as it existed on entry to this member
function.
</p>
</blockquote>
<pre>
weekday& weekday::operator+=(const days& d) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>*this = *this + d</code>.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
weekday& weekday::operator-=(const days& d) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>*this = *this - d</code>.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
constexpr explicit weekday::operator unsigned() const noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>wd_</code>.
</p>
</blockquote>
<pre>
constexpr operator date::weekday() const noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> An object of type <code>date::weekday</code> constructed from
<code>*this</code>. This changes the underlying encoding from [1, 7] -> [mon, sun] to
[0, 6] -> [sun, sat].
</p>
</blockquote>
<pre>
constexpr bool weekday::ok() const noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>1 <= wd_ && wd_ <= 7</code>.
</p>
</blockquote>
<pre>
constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>unsigned{x} == unsigned{y}</code>.
</p>
</blockquote>
<pre>
constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>!(x == y)</code>.
</p>
</blockquote>
<pre>
constexpr weekday operator+(const weekday& x, const days& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> A <code>weekday</code> for which <code>ok() == true</code> and is found as
if by incrementing (or decrementing if <code>y < days{0}</code>) <code>x</code>,
<code>y</code> times. If <code>weekday.ok() == false</code> prior to this operation,
behaves as if <code>*this</code> is first brought into the range [1, 7] by modular
arithmetic. [<i>Note:</i> For example <code>weekday{0}</code> becomes
<code>weekday{7}</code>. — <i>end note</i>]
</p>
<p>
<i>Complexity:</i> O(1) with respect to the value of <code>y</code>. That is, repeated
increments or decrements is not a valid implementation.
</p>
<p>
<i>Example:</i> <code>sun + days{6} == sat</code>.
</p>
</blockquote>
<pre>
constexpr weekday operator+(const days& x, const weekday& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>y + x</code>.
</p>
</blockquote>
<pre>
constexpr weekday operator-(const weekday& x, const days& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>x + -y</code>.
</p>
</blockquote>
<pre>
constexpr days operator-(const weekday& x, const weekday& y) noexcept;
</pre>
<blockquote>
<p>
<i>Requires:</i> <code>x.ok() == true</code> and <code>y.ok() == true</code>.
</p>
<p>
<i>Returns:</i> A value of <code>days</code> in the range of <code>days{0}</code> to
<code>days{6}</code> inclusive.
</p>
<p>
<i>Remarks:</i> The returned value <code>d</code> shall satisfy the equality:
<code>y + d == x</code>.
</p>
<p>
<i>Example:</i> <code>sat - sun == days{6}</code>.
</p>
</blockquote>
<pre>
std::ostream& operator<<(std::ostream& os, const weekday& wd);
</pre>
<blockquote>
<p>
<i>Effects:</i> If <code>ok() == true</code> outputs the same string that would be
output for the weekday field by <code>asctime</code>, assuming the conversion
<code>unsigned{date::weekday{*this}}</code>. Otherwise outputs
<code>unsigned{wd} << " is not a valid weekday"</code>.
</p>
<p>
<i>Returns:</i> <code>os</code>.
</p>
</blockquote>
</blockquote>
<a name="weeknum"></a><h3><code>weeknum</code></h3>
<blockquote>
<p><b>Synopsis</b></p>
<pre>
class weeknum
{
unsigned char wn_; // exposition only
public:
explicit constexpr weeknum(unsigned wn) noexcept;
weeknum& operator++() noexcept;
weeknum operator++(int) noexcept;
weeknum& operator--() noexcept;
weeknum operator--(int) noexcept;
weeknum& operator+=(const weeks& w) noexcept;
weeknum& operator-=(const weeks& w) noexcept;
constexpr explicit operator unsigned() const noexcept;
constexpr bool ok() const noexcept;
};
constexpr bool operator==(const weeknum& x, const weeknum& y) noexcept;
constexpr bool operator!=(const weeknum& x, const weeknum& y) noexcept;
constexpr bool operator< (const weeknum& x, const weeknum& y) noexcept;
constexpr bool operator> (const weeknum& x, const weeknum& y) noexcept;
constexpr bool operator<=(const weeknum& x, const weeknum& y) noexcept;
constexpr bool operator>=(const weeknum& x, const weeknum& y) noexcept;
constexpr weeknum operator+(const weeknum& x, const weeks& y) noexcept;
constexpr weeknum operator+(const weeks& x, const weeknum& y) noexcept;
constexpr weeknum operator-(const weeknum& x, const weeks& y) noexcept;
constexpr weeks operator-(const weeknum& x, const weeknum& y) noexcept;
std::ostream& operator<<(std::ostream& os, const weeknum& wn);
inline namespace literals
{
constexpr weeknum operator "" _w(unsigned long long wn) noexcept;
}
</pre>
<p><b>Overview</b></p>
<p>
<code>weeknum</code> represents a week number of of the ISO week-year [1, 53]. It should
only be representing values in the range 1 to 53. However it may hold values outside this
range. It can be constructed with any <code>unsigned</code> value, which will be
subsequently truncated to fit into <code>weeknum</code>'s internal storage.
<code>weeknum</code> is equality and less-than comparable, and participates in basic
arithmetic with <code>weeks</code> representing the quantity between any two
<code>weeknum</code>'s. One can stream out a <code>weeknum</code> for debugging
purposes. <code>weeknum</code> has explicit conversions to and from <code>unsigned</code>.
</p>
<p><b>Specification</b></p>
<p>
<code>weeknum</code> is a trivially copyable class type.</br>
<code>weeknum</code> is a standard-layout class type.</br>
<code>weeknum</code> is a literal class type.</br>
</p>
<pre>
explicit constexpr weeknum::weeknum(unsigned wn) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> Constructs an object of type <code>weeknum</code> by constructing
<code>wn_</code> with <code>wn</code>.
</p>
</blockquote>
<pre>
weeknum& weeknum::operator++() noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>++wn_</code>.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
weeknum weeknum::operator++(int) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>++(*this)</code>.
</p>
<p>
<i>Returns:</i> A copy of <code>*this</code> as it existed on entry to this member
function.
</p>
</blockquote>
<pre>
weeknum& weeknum::operator--() noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>--wn_</code>.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
weeknum weeknum::operator--(int) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>--(*this)</code>.
</p>
<p>
<i>Returns:</i> A copy of <code>*this</code> as it existed on entry to this member
function.
</p>
</blockquote>
<pre>
weeknum& weeknum::operator+=(const weeks& w) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>*this = *this + w</code>.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
weeknum& weeknum::operator-=(const weeks& w) noexcept;
</pre>
<blockquote>
<p>
<i>Effects:</i> <code>*this = *this - w</code>.
</p>
<p>
<i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
<pre>
constexpr explicit weeknum::operator unsigned() const noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>wn_</code>.
</p>
</blockquote>
<pre>
constexpr bool weeknum::ok() const noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>1 <= wn_ && wn_ <= 53</code>.
</p>
</blockquote>
<pre>
constexpr bool operator==(const weeknum& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>unsigned{x} == unsigned{y}</code>.
</p>
</blockquote>
<pre>
constexpr bool operator!=(const weeknum& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>!(x == y)</code>.
</p>
</blockquote>
<pre>
constexpr bool operator< (const weeknum& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>unsigned{x} < unsigned{y}</code>.
</p>
</blockquote>
<pre>
constexpr bool operator> (const weeknum& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>y < x</code>.
</p>
</blockquote>
<pre>
constexpr bool operator<=(const weeknum& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>!(y < x)</code>.
</p>
</blockquote>
<pre>
constexpr bool operator>=(const weeknum& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>!(x < y)</code>.
</p>
</blockquote>
<pre>
constexpr weeknum operator+(const weeknum& x, const weeks& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>weeknum{unsigned{x} + static_cast<unsigned>(y.count())}</code>
</p>
</blockquote>
<pre>
constexpr weeknum operator+(const weeks& x, const weeknum& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>y + x</code>.
</p>
</blockquote>
<pre>
constexpr weeknum operator-(const weeknum& x, const weeks& y) noexcept;
</pre>
<blockquote>
<p>
<i>Returns:</i> <code>x + -y</code>.
</p>
</blockquote>