File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -294,7 +294,15 @@ int Timer::dur() {
294294int Timer::CalcTimeDiff (int year, int month) {
295295
296296 int start_time = si_.y0 * cyclusYear + si_.m0 * cyclusMonth;
297- int time = year * cyclusYear + month * cyclusMonth;
297+ int time = std::min (year,0 ) * cyclusYear + std::min (month,0 ) * cyclusMonth;
298+
299+ // if time is 0, then invalid combination of year and month were given
300+ if time == 0 {
301+ CLOG (LEV_WARN) << " Invalid year and month combination given to Timer::CalcTimeDiff. Returning 0. "
302+ " Year: " << year << " Month: " << month;
303+
304+ return 0 ;
305+ }
298306
299307 // Casting because ctx_->dt() is uint64_t and so negatives don't play nice
300308 return (time - start_time) / static_cast <int >(ctx_->dt ());
Original file line number Diff line number Diff line change @@ -75,14 +75,13 @@ class Timer {
7575 // / @return the duration, in months
7676 int dur ();
7777
78- // / Returns the number of months between the simulation start
78+ // / Returns the number of time steps between the simulation start
7979 // / time and another time stamp.
8080 // /
81- // / @param year of alternate time stamp
82- // / @param month of alternate time stamp
81+ // / @param year of alternate time stamp (must be greater than 0)
82+ // / @param month of alternate time stamp (must be greater than 0)
8383 // /
8484 // / @return the difference between the simulation start time and another time
85- // / @warning Only valid for times that occur after the simulation start time.
8685 int CalcTimeDiff (int year, int month);
8786
8887 private:
You can’t perform that action at this time.
0 commit comments