Skip to content

Commit

Permalink
Fixed interpolation generating invalid times
Browse files Browse the repository at this point in the history
  • Loading branch information
vesavlad committed Mar 5, 2022
1 parent db4e594 commit 336734d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libs/gtfs/src/gtfs/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ time::time(const std::string & raw_time_str) : raw_time(raw_time_str)
mm = static_cast<uint16_t>(std::stoi(raw_time.substr(len - 5, 2)));
ss = static_cast<uint16_t>(std::stoi(raw_time.substr(len - 2)));

if (mm > 60 || ss > 60)
if (mm > 59 || ss > 59)
throw invalid_field_format("time minutes/seconds wrong value: " + std::to_string(mm) +
" minutes, " + std::to_string(ss) + " seconds");

Expand All @@ -55,7 +55,7 @@ time::time(size_t seconds)
mm = seconds / 60;
ss = seconds % 60;

if (mm > 60 || ss > 60)
if (mm > 59 || ss > 59)
throw invalid_field_format("time is out of range: " + std::to_string(mm) + "minutes " +
std::to_string(ss) + "seconds");

Expand All @@ -68,7 +68,7 @@ time::time(size_t seconds)
time::time(uint16_t hours, uint16_t minutes, uint16_t seconds)
: hh(hours), mm(minutes), ss(seconds)
{
if (mm > 60 || ss > 60)
if (mm > 59 || ss > 59)
throw invalid_field_format("time is out of range: " + std::to_string(mm) + "minutes " +
std::to_string(ss) + "seconds");

Expand All @@ -92,14 +92,14 @@ time& time::add_seconds(size_t seconds)
auto s = seconds % 60;

ss += s;
if (ss > 60)
if (ss > 59)
{
ss = ss % 60;
mm++;
}

mm += m;
if (mm > 60)
if (mm >= 59)
{
mm = mm % 60;
hh++;
Expand Down

0 comments on commit 336734d

Please sign in to comment.