27#include <boost/algorithm/string/case_conv.hpp>
28#include <boost/utility/string_view.hpp>
35 const boost::string_view All_MONTH_CODES =
"FGHJKMNQUVXZ";
46 if (!mainCycle)
return true;
64 if (std::isdigit(
static_cast<unsigned char>(in[1])) == 0)
68 const boost::string_view validMonthCodes = mainCycle ?
"HMUZ" : All_MONTH_CODES;
69 return validMonthCodes.find(std::toupper(in[0])) != boost::string_view::npos;
74 date <<
" is not an ASX date");
77 const char monthCode = All_MONTH_CODES[
date.
month()-1];
78 const char yearDigit =
static_cast<char>(
static_cast<int>(
'0') + (
date.
year() % 10));
79 std::string
code{monthCode, yearDigit};
81 #ifdef QL_EXTRA_SAFETY_CHECKS
83 "the result " <<
code <<
84 " is an invalid ASX code");
91 const Date& refDate) {
93 asxCode <<
" is not a valid ASX code");
95 const Date referenceDate = (refDate !=
Date() ?
99 const char ms = std::toupper(asxCode.front());
100 const std::size_t idxZeroBased = All_MONTH_CODES.find(ms);
101 QL_ASSERT(idxZeroBased != All_MONTH_CODES.npos,
"invalid ASX month letter. code: " + asxCode);
107 Year y =
static_cast<int>(asxCode[1]) -
static_cast<int>(
'0');
108 QL_ASSERT((
y>=0) && (
y <= 9),
"invalid ASX year digit. code: " + asxCode);
112 if (
y==0 && referenceDate.
year()<=1909)
y+=10;
113 const Year referenceYear = (referenceDate.
year() % 10);
114 y += referenceDate.
year() - referenceYear;
126 Size offset = mainCycle ? 3 : 1;
127 Size skipMonths = offset-(m%offset);
128 if (skipMonths != offset || refDate.
dayOfMonth() > 14) {
129 skipMonths +=
Size(m);
130 if (skipMonths<=12) {
146 const Date& referenceDate) {
147 Date asxDate =
date(ASXcode, referenceDate);
148 return nextDate(asxDate+1, mainCycle);
159 const Date& referenceDate) {
ASX-related date functions.
static Date nthWeekday(Size n, Weekday w, Month m, Year y)
n-th given weekday in the given month and year
static Settings & instance()
access to the unique instance
Classes used to parse data for input.
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_ASSERT(condition, message)
throw an error if the given condition is not verified
std::size_t Size
size of a container
global repository for run-time library settings
static Date date(const std::string &asxCode, const Date &referenceDate=Date())
static std::string nextCode(const Date &d=Date(), bool mainCycle=true)
next ASX code following the given date
static Date nextDate(const Date &d=Date(), bool mainCycle=true)
next ASX date following the given date
static bool isASXcode(const std::string &in, bool mainCycle=true)
returns whether or not the given string is an ASX code
static std::string code(const Date &asxDate)
static bool isASXdate(const Date &d, bool mainCycle=true)
returns whether or not the given date is an ASX date