diff --git a/Extractor/ExtractionHelperFunctions.h b/Extractor/ExtractionHelperFunctions.h index 08a1e14ef..6771939a9 100644 --- a/Extractor/ExtractionHelperFunctions.h +++ b/Extractor/ExtractionHelperFunctions.h @@ -28,12 +28,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include + #include "../Util/StringUtil.h" +namespace qi = boost::spirit::qi; + //TODO: Move into LUA inline bool durationIsValid(const std::string &s) { - boost::regex e ("((\\d|\\d\\d):)*(\\d|\\d\\d)",boost::regex_constants::icase|boost::regex_constants::perl); + boost::regex e ("((\\d|\\d\\d):(\\d|\\d\\d):(\\d|\\d\\d))|((\\d|\\d\\d):(\\d|\\d\\d))|(\\d|\\d\\d)",boost::regex_constants::icase|boost::regex_constants::perl); std::vector< std::string > result; boost::algorithm::split_regex( result, s, boost::regex( ":" ) ) ; @@ -42,17 +45,28 @@ inline bool durationIsValid(const std::string &s) { } inline unsigned parseDuration(const std::string &s) { - int hours = 0; - int minutes = 0; - boost::regex e ("((\\d|\\d\\d):)*(\\d|\\d\\d)",boost::regex_constants::icase|boost::regex_constants::perl); + unsigned hours = 0; + unsigned minutes = 0; + unsigned seconds = 0; + boost::regex e ("((\\d|\\d\\d):(\\d|\\d\\d):(\\d|\\d\\d))|((\\d|\\d\\d):(\\d|\\d\\d))|(\\d|\\d\\d)",boost::regex_constants::icase|boost::regex_constants::perl); std::vector< std::string > result; boost::algorithm::split_regex( result, s, boost::regex( ":" ) ) ; bool matched = regex_match(s, e); if(matched) { - hours = (result.size()== 2) ? stringToInt(result[0]) : 0; - minutes = (result.size()== 2) ? stringToInt(result[1]) : stringToInt(result[0]); - return 600*(hours*60+minutes); + if(1 == result.size()) { + minutes = stringToInt(result[0]); + } + if(2 == result.size()) { + minutes = stringToInt(result[1]); + hours = stringToInt(result[0]); + } + if(3 == result.size()) { + seconds = stringToInt(result[2]); + minutes = stringToInt(result[1]); + hours = stringToInt(result[0]); + } + return 10*(3600*hours+60*minutes+seconds); } return UINT_MAX; } @@ -66,5 +80,4 @@ inline int parseMaxspeed(std::string input) { //call-by-value on purpose. return n; } - #endif /* EXTRACTIONHELPERFUNCTIONS_H_ */ diff --git a/features/testbot/duration.feature b/features/testbot/duration.feature index d22f28c4b..ab6571ce5 100644 --- a/features/testbot/duration.feature +++ b/features/testbot/duration.feature @@ -6,9 +6,9 @@ Feature: Durations Scenario: Duration of ways Given the node map - | a | b | | | | - | | | | e | | - | | c | | | d | + | a | b | | | | f | + | | | | e | | | + | | c | | | d | | And the ways | nodes | highway | duration | @@ -16,6 +16,7 @@ Feature: Durations | bc | primary | 0:10 | | cd | primary | 1:00 | | de | primary | 10:00 | + | ef | primary | 01:02:03 | When I route I should get | from | to | route | distance | time | @@ -23,6 +24,7 @@ Feature: Durations | b | c | bc | 200m +-1 | 600s +-1 | | c | d | cd | 300m +-1 | 3600s +-1 | | d | e | de | 144m +-2 | 36000s +-1 | + | e | f | ef | 224m +-2 | 3723s +-1 | @todo Scenario: Partial duration of ways