Skip to content

Commit 2b093b6

Browse files
committed
clarify behavior in off-normal cases
1 parent 5437df6 commit 2b093b6

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/timer.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,15 @@ int Timer::dur() {
294294
int 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());

src/timer.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)