/ /カレンダーライブラリC ++ - c ++、日付、カレンダー

カレンダーライブラリC ++ - c ++、日付、カレンダー

私は最近、QUANTLIB C ++でカレンダー関数を使用して以下を実行しました。

残念ながら、QUANTLIBを使用しているプロジェクトはコンパイルするには長すぎます。私は、以下に示すように、複数の異なる形式の日付の文字列を解釈することに興味があります(これはquantlibによって可能になります)。また、さまざまな形式のさまざまな日付の違いなども見たいと思います。

私の質問は、そこには私がこれらのすべてのことを可能にする別のC + +ライブラリがあります(うまくいけば、私のプロジェクトで速くコンパイルするもの)?

以下の単純なプロジェクトは、コンパイルするために永遠にかかるようです。

私の唯一の前提条件は、静的にコンパイルすることです。

#include <iostream>
#include <ql/quantlib.hpp>
#include <ql/utilities/dataparsers.hpp>


using namespace std;
using namespace QuantLib;

int main()
{

Calendar cal = Australia();
const Date dt(21, Aug, 1971);

bool itis = false;

itis = cal.isBusinessDay(dt);
cout << "business day yes? " << itis << endl;
cout << "The calendar country is: " << cal.name() << endl;


// now convert a string to a date.
string mydate = "05/08/2016";
const Date d = DateParser::parseFormatted(mydate,"%d/%m/%Y");


cout << "The year of this date is: " <<  d.year() << endl;
cout << "The month of this date is: " <<  d.month() << endl;
cout << "The day of this date is: " <<  d.dayOfMonth() << endl;
cout << "The date " << mydate << " is a business day yes? " << cal.isBusinessDay(d) << endl;


}

回答:

回答№1は2

この 日付ライブラリ 完全に文書化されたオープンソースであり、必要な部分はヘッダーのみであり、非常に高速にコンパイルされます。これは、C ++ 11以上を必要とします。 <chrono>.

あなたの例は次のようになります:

#include "date/date.h"
#include <iostream>
#include <sstream>

using namespace std;
using namespace date;

int main()
{
const auto dt = 21_d/aug/1971;
auto wd = weekday{dt};

auto itis = wd != sun && wd != sat;
cout << "business day yes? " << itis << endl;

// now convert a string to a date.
istringstream mydate{"05/08/2016"};
local_days ld;
mydate >> parse("%d/%m/%Y", ld);
auto d = year_month_day{ld};
wd = weekday{ld};

cout << "The year of this date is: " <<  d.year() << "n";
cout << "The month of this date is: " <<  d.month() << "n";
cout << "The day of this date is: " <<  d.day() << "n";
cout << "The date " << d << " is a business day yes? " << (wd != sun && wd != sat) << "n";
}

上記のプログラムは、

business day yes? 0
The year of this date is: 2016
The month of this date is: Aug
The day of this date is: 05
The date 2016-08-05 is a business day yes? 1

唯一の欠点は、 isBusinessDay。しかし、この図書館では、曜日を見つけるのは非常に簡単です(上記のように)。そして、あなたはこのライブラリを簡単に使ってもっと完成しました isBusinessDay オーストラリアの休日のリストがある場合。例えば:

bool
isBusinessDay(year_month_day ymd)
{
sys_days sd = ymd;
weekday wd = sd;
if (wd == sat || wd == sun)  // weekend
return false;
if (sd == mon[2]/jun/ymd.year())  // Queen"s Birthday
return false;
// ...
return true;
}