From c3804b0d989ceee750d0fdd17ed46a76d6673406 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Wed, 20 Jan 2021 13:02:43 +0300 Subject: [PATCH 1/3] Parse time >= 100 hours for multi-day routes. --- include/just_gtfs/just_gtfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/just_gtfs/just_gtfs.h b/include/just_gtfs/just_gtfs.h index a499433..b650cc4 100644 --- a/include/just_gtfs/just_gtfs.h +++ b/include/just_gtfs/just_gtfs.h @@ -516,8 +516,8 @@ inline Time::Time(const std::string & raw_time_str) : raw_time(raw_time_str) return; const size_t len = raw_time.size(); - if (!(len == 7 || len == 8) || (raw_time[len - 3] != ':' && raw_time[len - 6] != ':')) - throw InvalidFieldFormat("Time is not in [H]H:MM:SS format: " + raw_time_str); + if (!(len >= 7 && len <= 9) || (raw_time[len - 3] != ':' && raw_time[len - 6] != ':')) + throw InvalidFieldFormat("Time is not in [[H]H]H:MM:SS format: " + raw_time_str); hh = static_cast(std::stoi(raw_time.substr(0, len - 6))); mm = static_cast(std::stoi(raw_time.substr(len - 5, 2))); From cc3d82a25e4bc87b8a57024c28a3ce01fa4549cd Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Wed, 20 Jan 2021 13:24:17 +0300 Subject: [PATCH 2/3] Fix time format check. --- include/just_gtfs/just_gtfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/just_gtfs/just_gtfs.h b/include/just_gtfs/just_gtfs.h index b650cc4..4077c02 100644 --- a/include/just_gtfs/just_gtfs.h +++ b/include/just_gtfs/just_gtfs.h @@ -516,7 +516,7 @@ inline Time::Time(const std::string & raw_time_str) : raw_time(raw_time_str) return; const size_t len = raw_time.size(); - if (!(len >= 7 && len <= 9) || (raw_time[len - 3] != ':' && raw_time[len - 6] != ':')) + if (!(len >= 7 && len <= 9) || raw_time[len - 3] != ':' || raw_time[len - 6] != ':') throw InvalidFieldFormat("Time is not in [[H]H]H:MM:SS format: " + raw_time_str); hh = static_cast(std::stoi(raw_time.substr(0, len - 6))); From f5c932d16a434e29418c3c2947c5b9e2b7ddb41a Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Wed, 20 Jan 2021 14:05:15 +0300 Subject: [PATCH 3/3] Add more time format tests. --- tests/unit_tests.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit_tests.cpp b/tests/unit_tests.cpp index e43af3d..4fc646e 100644 --- a/tests/unit_tests.cpp +++ b/tests/unit_tests.cpp @@ -23,6 +23,14 @@ TEST_CASE("Time in HH:MM:SS format") CHECK_EQ(stop_time.get_total_seconds(), 39 * 60 * 60 + 45 * 60 + 30); } +TEST_CASE("Time in HHH:MM:SS format") +{ + Time stop_time("103:05:21"); + CHECK_EQ(stop_time.get_hh_mm_ss(), std::make_tuple(103, 5, 21)); + CHECK_EQ(stop_time.get_raw_time(), "103:05:21"); + CHECK_EQ(stop_time.get_total_seconds(), 103 * 60 * 60 + 5 * 60 + 21); +} + TEST_CASE("Time from integers 1") { Time stop_time(14, 30, 0); @@ -44,6 +52,7 @@ TEST_CASE("Invalid time format") CHECK_THROWS_AS(Time("12/10/00"), const InvalidFieldFormat &); CHECK_THROWS_AS(Time("12:100:00"), const InvalidFieldFormat &); CHECK_THROWS_AS(Time("12:10:100"), const InvalidFieldFormat &); + CHECK_THROWS_AS(Time("12:10/10"), const InvalidFieldFormat &); } TEST_CASE("Time not provided")