bool terrama2::core::isValidDataSetName(const std::string& mask, const Filter& filter, const std::string& timezone, const std::string& name, std::shared_ptr< te::dt::TimeInstantTZ >& fileTimestamp) { if(!isValidDatedMask(mask)) { QString errMsg = QObject::tr("The mask don't have the minimal needed parameters of a date!"); TERRAMA2_LOG_ERROR() << errMsg; throw terrama2::core::UtilityException() << ErrorDescription(errMsg); } auto regexString = terramaMask2Regex(mask); boost::regex expression(regexString); boost::match_results< std::string::const_iterator > match; if(!boost::regex_match(name, match, expression, boost::match_default)) return false; if((match["YEAR"] != "" || match["YEAR2DIGITS"] != "") && match["MONTH"] != "" && match["DAY"] != "") { std::string ts; if(match["YEAR"] != "") { ts = match["YEAR"].str(); } else { int year = std::stoi(match["YEAR2DIGITS"].str()); if(year < 80) ts = "20" + match["YEAR2DIGITS"].str(); else ts = "19" + match["YEAR2DIGITS"].str(); } ts += match["MONTH"].str(); ts += match["DAY"].str(); // if the name has only date part, it presumes that time is 23:59:59 ts += "T"; ts += (match["HOUR"] == "" ? "23" : match["HOUR"].str()); ts += (match["MINUTES"] == "" ? "59" : match["MINUTES"].str()); ts += (match["SECONDS"] == "" ? "59" : match["SECONDS"].str()); boost::posix_time::ptime boostDate(boost::posix_time::from_iso_string(ts)); boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone(timezone)); boost::local_time::local_date_time date(boostDate.date(), boostDate.time_of_day(), zone, true); fileTimestamp.reset(new te::dt::TimeInstantTZ(date)); if(!isValidTimestamp(filter, fileTimestamp)) return false; } else { fileTimestamp.reset(); } return true; }
bool terrama2::core::isValidDataSetName(const std::string& mask, const Filter& filter, std::string& timezone, const std::string& name, std::shared_ptr< te::dt::TimeInstantTZ >& fileTimestamp) { if(!isValidDatedMask(mask)) { QString errMsg = QObject::tr("The mask don't have the minimal needed parameters of a date!"); TERRAMA2_LOG_ERROR() << errMsg; throw terrama2::core::UtilityException() << ErrorDescription(errMsg); } /* yyyy year with 4 digits [0-9]{4} yy year with 2 digits [0-9]{2} MM month with 2 digits 0[1-9]|1[012] dd day with 2 digits 0[1-9]|[12][0-9]|3[01] hh hout with 2 digits [0-1][0-9]|2[0-4] mm minutes with 2 digits [0-5][0-9] ss seconds with 2 digits [0-5][0-9] */ QString m(mask.c_str()); m.replace("yyyy", "(?<YEAR>[0-9]{4})"); m.replace("yy", "(?<YEAR2DIGITS>[0-9]{2})"); m.replace("MM", "(?<MONTH>0[1-9]|1[012])"); m.replace("dd", "(?<DAY>0[1-9]|[12][0-9]|3[01])"); m.replace("hh", "(?<HOUR>[0-1][0-9]|2[0-4])"); m.replace("mm", "(?<MINUTES>[0-5][0-9])"); m.replace("ss", "(?<SECONDS>[0-5][0-9])"); // add a extension validation in case of the name has it m += "(?<EXTENSIONS>\\..+)?"; boost::regex expression(m.toStdString()); boost::match_results< std::string::const_iterator > match; if(!boost::regex_match(name, match, expression, boost::match_default)) return false; if((match["YEAR"] != "" || match["YEAR2DIGITS"] != "") && match["MONTH"] != "" && match["DAY"] != "") { std::string ts; if(match["YEAR"] != "") { ts = match["YEAR"].str(); } else { int year = std::stoi(match["YEAR2DIGITS"].str()); if(year < 80) ts = "20" + match["YEAR2DIGITS"].str(); else ts = "19" + match["YEAR2DIGITS"].str(); } ts += match["MONTH"].str(); ts += match["DAY"].str(); // if the name has only date part, it presumes that time is 00:00:00 ts += "T"; ts += (match["HOUR"] == "" ? "00" : match["HOUR"].str()); ts += (match["MINUTES"] == "" ? "00" : match["MINUTES"].str()); ts += (match["SECONDS"] == "" ? "00" : match["SECONDS"].str()); boost::posix_time::ptime boostDate(boost::posix_time::from_iso_string(ts)); boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone(timezone)); boost::local_time::local_date_time date(boostDate.date(), boostDate.time_of_day(), zone, true); fileTimestamp.reset(new te::dt::TimeInstantTZ(date)); if(!isValidTimestamp(filter, fileTimestamp)) return false; } else { fileTimestamp.reset(); } return true; }