Debian Codegraph @

docs/julian.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <title>julian</title>
6
7 <meta name="color-scheme" content="light dark" />
8 <style>
9 li, p {text-align:justify}
10 ins {color:#00A000}
11 del {color:#A00000}
12 code {white-space:pre;}
13 @media (prefers-color-scheme: dark)
14 {
15 ins {color:#88FF88}
16 del {color:#FF5555}
17 }
18 </style>
19 </head>
20 <body>
21
22 <address align=right>
23 <br/>
24 <br/>
25 <a href="mailto:[email protected]">Howard E. Hinnant</a><br/>
26 2016-06-26<br/>
27 </address>
28 <hr/>
29 <h1 align=center><code>julian</code></h1>
30
31 <h2>Contents</h2>
32
33 <ul>
34 <li><a href="https://github.com/HowardHinnant/date">github link</a></li>
35 <li><a href="#Introduction">Introduction</a></li>
36 </ul>
37
38 <a name="Introduction"></a><h2>Introduction</h2>
39
40 <p>
41 This is a Julian calendar in the style of
42 <a href="date.html">date.h</a>.
43 Everything is the same here as for
44 <a href="date.html">date.h</a>,
45 except that the calendrical arithmetic implements a proleptic Julian calendar.
46 </p>
47
48 <p>
49 The <code>julian</code> calendar can interoperate with
50 <a href="date.html">date.h</a> and <a href="tz.html">tz.h</a> just by
51 paying attention to the namespace. For example to convert the <i>civil</i>
52 date <code>2016_y/jun/26</code> to a julian date, just do:
53 </p>
54
55 <blockquote><pre>
56 #include "julian.h"
57 #include &lt;iostream&gt;
58
59 int
60 main()
61 {
62 using namespace date::literals;
63 std::cout &lt;&lt; julian::year_month_day{2016_y/jun/26} &lt;&lt; '\n';
64 }
65 </pre></blockquote>
66
67 <p>
68 This outputs:
69 </p>
70
71 <blockquote><pre>
72 2016-06-13
73 </pre></blockquote>
74
75 <p>
76 And here is the reverse conversion:
77 </p>
78
79 <blockquote><pre>
80 #include "julian.h"
81 #include &lt;iostream&gt;
82
83 int
84 main()
85 {
86 using namespace julian::literals;
87 std::cout &lt;&lt; date::year_month_day{2016_y/jun/13} &lt;&lt; '\n';
88 }
89 </pre></blockquote>
90
91 <p>
92 Which outputs:
93 </p>
94
95 <blockquote><pre>
96 2016-06-26
97 </pre></blockquote>
98
99 <p>
100 You can even convert directly to the ISO-week-based calendar:
101 </p>
102
103 <blockquote><pre>
104 #include "iso_week.h"
105 #include "julian.h"
106 #include &lt;iostream&gt;
107
108 int
109 main()
110 {
111 using namespace julian::literals;
112 std::cout &lt;&lt; iso_week::year_weeknum_weekday{2016_y/jun/13} &lt;&lt; '\n';
113 }
114 </pre></blockquote>
115
116 <p>
117 Which outputs:
118 </p>
119
120 <blockquote><pre>
121 2016-W25-Sun
122 </pre></blockquote>
123
124 <p>
125
126 <p>
127 You can find the current local julian date and time with:
128 </p>
129
130 <blockquote><pre>
131 #include "julian.h"
132 #include "tz.h"
133 #include &lt;iostream&gt;
134
135 int
136 main()
137 {
138 auto zt = date::make_zoned(date::current_zone(), std::chrono::system_clock::now());
139 auto ld = date::floor&lt;date::days&gt;(zt.get_local_time());
140 julian::year_month_day ymd{ld};
141 auto time = date::make_time(zt.get_local_time() - ld);
142 std::cout &lt;&lt; ymd &lt;&lt; ' ' &lt;&lt; time &lt;&lt; '\n';
143 }
144 </pre></blockquote>
145
146 <p>
147 Example output:
148 </p>
149
150 <blockquote><pre>
151 2016-06-13 18:38:30.049598
152 </pre></blockquote>
153
154
155 </body>
156 </html>