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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>julian</title>
<meta name="color-scheme" content="light dark" />
<style>
li, p {text-align:justify}
ins {color:#00A000}
del {color:#A00000}
code {white-space:pre;}
@media (prefers-color-scheme: dark)
{
ins {color:#88FF88}
del {color:#FF5555}
}
</style>
</head>
<body>
<address align=right>
<br/>
<br/>
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
2016-06-26<br/>
</address>
<hr/>
<h1 align=center><code>julian</code></h1>
<h2>Contents</h2>
<ul>
<li><a href="https://github.com/HowardHinnant/date">github link</a></li>
<li><a href="#Introduction">Introduction</a></li>
</ul>
<a name="Introduction"></a><h2>Introduction</h2>
<p>
This is a Julian calendar in the style of
<a href="date.html">date.h</a>.
Everything is the same here as for
<a href="date.html">date.h</a>,
except that the calendrical arithmetic implements a proleptic Julian calendar.
</p>
<p>
The <code>julian</code> calendar can interoperate with
<a href="date.html">date.h</a> and <a href="tz.html">tz.h</a> just by
paying attention to the namespace. For example to convert the <i>civil</i>
date <code>2016_y/jun/26</code> to a julian date, just do:
</p>
<blockquote><pre>
#include "julian.h"
#include <iostream>
int
main()
{
using namespace date::literals;
std::cout << julian::year_month_day{2016_y/jun/26} << '\n';
}
</pre></blockquote>
<p>
This outputs:
</p>
<blockquote><pre>
2016-06-13
</pre></blockquote>
<p>
And here is the reverse conversion:
</p>
<blockquote><pre>
#include "julian.h"
#include <iostream>
int
main()
{
using namespace julian::literals;
std::cout << date::year_month_day{2016_y/jun/13} << '\n';
}
</pre></blockquote>
<p>
Which outputs:
</p>
<blockquote><pre>
2016-06-26
</pre></blockquote>
<p>
You can even convert directly to the ISO-week-based calendar:
</p>
<blockquote><pre>
#include "iso_week.h"
#include "julian.h"
#include <iostream>
int
main()
{
using namespace julian::literals;
std::cout << iso_week::year_weeknum_weekday{2016_y/jun/13} << '\n';
}
</pre></blockquote>
<p>
Which outputs:
</p>
<blockquote><pre>
2016-W25-Sun
</pre></blockquote>
<p>
<p>
You can find the current local julian date and time with:
</p>
<blockquote><pre>
#include "julian.h"
#include "tz.h"
#include <iostream>
int
main()
{
auto zt = date::make_zoned(date::current_zone(), std::chrono::system_clock::now());
auto ld = date::floor<date::days>(zt.get_local_time());
julian::year_month_day ymd{ld};
auto time = date::make_time(zt.get_local_time() - ld);
std::cout << ymd << ' ' << time << '\n';
}
</pre></blockquote>
<p>
Example output:
</p>
<blockquote><pre>
2016-06-13 18:38:30.049598
</pre></blockquote>
</body>
</html>
|