Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/just_gtfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlga Khlopkova <mesozoic.drones@gmail.com>2021-01-20 14:23:22 +0300
committerGitHub <noreply@github.com>2021-01-20 14:23:22 +0300
commit574b946dce6ee2392af91f632521633448878b75 (patch)
treedb58b98a0bb18192a6231af36a234e8808a66332
parent46996effa65b4db75f357180467968aed89cdf55 (diff)
parentf5c932d16a434e29418c3c2947c5b9e2b7ddb41a (diff)
Merge pull request #7 from tatiana-yan/master
Parse time >= 100 hours for multi-day routes.
-rw-r--r--include/just_gtfs/just_gtfs.h4
-rw-r--r--tests/unit_tests.cpp9
2 files changed, 11 insertions, 2 deletions
diff --git a/include/just_gtfs/just_gtfs.h b/include/just_gtfs/just_gtfs.h
index a499433..4077c02 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<uint16_t>(std::stoi(raw_time.substr(0, len - 6)));
mm = static_cast<uint16_t>(std::stoi(raw_time.substr(len - 5, 2)));
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")