「🔨」 fix(ex00): fixed date parsing to be more precise :D
This commit is contained in:
@@ -15,6 +15,14 @@ Date::Date(std::string str)
|
||||
{
|
||||
// check format (4 char & isdigit into dash into 2 char isdigit & < 1 && isdigit & < 2, and same for day except ahah funny cuz 30 and 31 and 28 and 29 agfjasfgfjahkfga)
|
||||
_value = 0;
|
||||
for (size_t i = 0; str[i]; ++i)
|
||||
{
|
||||
if (!isdigit(str[i]) && !((i == (str.length() - 6) || i == (str.length() - 3)) && str[i] == '-'))
|
||||
{
|
||||
std::cout << str.length() - 6 << i << std::endl;
|
||||
throw std::invalid_argument("invalid date.");
|
||||
}
|
||||
}
|
||||
for (std::string::iterator it = str.begin(); it < str.end(); ++it)
|
||||
{
|
||||
if (!isdigit(*it))
|
||||
@@ -22,7 +30,6 @@ Date::Date(std::string str)
|
||||
_value *= 10;
|
||||
_value += *it - '0';
|
||||
}
|
||||
|
||||
int year = _value / 10000;
|
||||
int month = (_value / 100) % 100;
|
||||
int day = _value % 100;
|
||||
@@ -167,7 +174,7 @@ void BitcoinExchange::str(std::string filename)
|
||||
continue ;
|
||||
}
|
||||
try {
|
||||
Date date(date_str);
|
||||
Date date(trim(date_str));
|
||||
if (date < _data.begin()->first)
|
||||
{
|
||||
std::cout << "Error: input date too low." << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user