Skip to content

Commit

Permalink
Merge pull request #7 from tatiana-yan/master
Browse files Browse the repository at this point in the history
Parse time >= 100 hours for multi-day routes.
  • Loading branch information
mesozoic-drones authored Jan 20, 2021
2 parents 46996ef + f5c932d commit 574b946
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/just_gtfs/just_gtfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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")
Expand Down

0 comments on commit 574b946

Please sign in to comment.