@@ -216,7 +216,7 @@ void run_material_farmer(
216216 std::to_string (farming_time_remaining.count ()) + " min" ,
217217 COLOR_PURPLE
218218 );
219- if (farming_time_remaining < std::chrono::minutes (0 )){
219+ if (farming_time_remaining <= std::chrono::minutes (0 )){
220220 console.log (" Time's up. Stop the Material farming program." , COLOR_RED);
221221 return ;
222222 }
@@ -229,7 +229,7 @@ void run_material_farmer(
229229 std::to_string (sandwich_time_remaining.count ()) + " min" ,
230230 COLOR_PURPLE
231231 );
232- if (sandwich_time_remaining < std::chrono::minutes (0 )){
232+ if (sandwich_time_remaining <= std::chrono::minutes (0 )){
233233 console.log (" Sandwich not active. Make a sandwich." );
234234 last_sandwich_time = make_sandwich_material_farm (env, console, context, options, stats);
235235 console.overlay ().add_log (" Sandwich made." );
@@ -393,9 +393,14 @@ WallClock make_sandwich_material_farm(
393393}
394394
395395// given the start time, and duration in minutes, return the number of remaining minutes
396+ // WARNING: this function may silently overflow if start_time is near WallClock::min() or WallClock::max()
396397std::chrono::minutes minutes_remaining (WallClock start_time, std::chrono::minutes minutes_duration){
397- return std::chrono::minutes (minutes_duration) -
398- std::chrono::duration_cast<std::chrono::minutes>(current_time () - start_time);
398+ if (start_time == WallClock::min ()){
399+ return std::chrono::minutes (0 );
400+ }else {
401+ auto elapsed_time = std::chrono::duration_cast<std::chrono::minutes>(current_time () - start_time);
402+ return minutes_duration - elapsed_time;
403+ }
399404}
400405
401406// from the North Province (Area 3) pokecenter, move to start position for Happiny dust farming
0 commit comments