/ / कैलेंडर लाइब्रेरी C ++ - c ++, दिनांक, कैलेंडर

कैलेंडर लाइब्रेरी सी ++ - सी ++, तिथि, कैलेंडर

मैंने हाल ही में QUANTLIB C ++ में कैलेंडर फ़ंक्शन का उपयोग नीचे प्रदर्शन करने के लिए किया है।

दुर्भाग्य से किसी भी परियोजना का उपयोग QUANTLIB लेता हैसंकलन करने के लिए बहुत लंबा है। मैं कई अलग-अलग स्वरूपों में तारीखों के तारों की व्याख्या करने में दिलचस्पी रखता हूं (जो क्वांटलिब मुझे करने में सक्षम बनाता है), जैसा कि नीचे दिखाया गया है। मैं विभिन्न प्रारूपों में विभिन्न तिथियों के बीच अंतर भी खोजना चाहता हूं।

मेरा सवाल यह है कि क्या वहाँ एक और सी ++ लाइब्रेरी है जो मुझे इन सभी चीजों को करने में सक्षम बनाती है (उम्मीद है कि जो मेरी परियोजनाओं को तेजी से संकलित करेगी)?

नीचे सरल परियोजना हमेशा के लिए संकलित करने के लिए लगता है।

मेरी एकमात्र शर्त यह है कि यह सांख्यिकीय रूप से संकलित है।

#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;


}

उत्तर:

जवाब के लिए 2 № 1

इस दिनांक पुस्तकालय पूरी तरह से प्रलेखित, खुला-स्रोत है, और आपको जिस भाग की आवश्यकता है वह हेडर-ओनली है और बहुत तेजी से संकलित करता है। इसे बनाने के लिए 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;
}