2016-07-04 16:32:31 -04:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
|
|
"http://www.w3.org/TR/html4/loose.dtd">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>islamic</title>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
<address align=right>
|
|
|
|
<br/>
|
|
|
|
<br/>
|
|
|
|
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
|
|
|
|
2016-07-04<br/>
|
|
|
|
</address>
|
|
|
|
<hr/>
|
|
|
|
<h1 align=center><code>islamic</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 an Islamic calendar in the style of
|
|
|
|
<a href="date.html">date.h</a>.
|
|
|
|
Everthing is the same here as for
|
|
|
|
<a href="date.html">date.h</a>,
|
|
|
|
except that the calendrical arithmetic implements a proleptic
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Tabular_Islamic_calendar">Tabular Islamic calendar</a>.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
The <code>islamic</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/jul/4</code> to an islamic date, just do:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
#include "islamic.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
using namespace date::literals;
|
|
|
|
std::cout << islamic::year_month_day{2016_y/jul/4} << '\n';
|
|
|
|
}
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
This outputs:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
1437-09-28
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
And here is the reverse conversion:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
#include "islamic.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
using namespace islamic::literals;
|
|
|
|
std::cout << date::year_month_day{1437_y/9/28} << '\n';
|
|
|
|
}
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Which outputs:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
2016-07-04
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
You can even convert directly to the ISO-week-based calendar:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
#include "islamic.h"
|
|
|
|
#include "iso_week.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
using namespace islamic::literals;
|
|
|
|
std::cout << iso_week::year_weeknum_weekday{2016_y/jun/13} << '\n';
|
|
|
|
}
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Which outputs:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
2016-W27-Mon
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
You can find the current local islamic date and time with:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
#include "islamic.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());
|
2016-07-04 16:33:59 -04:00
|
|
|
islamic::year_month_day ymd{ld};
|
2016-07-04 16:32:31 -04:00
|
|
|
auto time = date::make_time(zt.get_local_time() - ld);
|
|
|
|
std::cout << ymd << ' ' << time << '\n';
|
|
|
|
}
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Example output:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<blockquote><pre>
|
|
|
|
1437-09-28 16:24:56.578240
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
This calendar assumes that the Islamic day starts at midnight, like the civil
|
|
|
|
calendar. This is because the only thing that is customized to the Islamic
|
|
|
|
calendar is the calendar itself (days precision time keeping). For time-keeping
|
|
|
|
finer than days, the <code><chrono></code> library is still in use. The
|
|
|
|
Islamic calendar simply converts to and from <code>sys_days</code> (a
|
|
|
|
days-precision <code>std::chrono::time_point</code>) like every other calendar.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|