Unexpected behavior in timer display

I have been staring at this code for a week now and have tried many things. I cant seem to figure out why the seconds do not display from 0-59. What i end up with with is a second counter that continues well past 60. The minutes and hours seem to act appropriately.
It seems as if the code in this line is being ignored
if (seconds > 59) {seconds = seconds - (60 * minutes * hours);}

I have tried moving declarations outside the function; forcing UL on the "60" variables; and any thing else i could think of.

I did not conceive this code myself, but borrowed it from someone else's project and (tried to) modify it to my needs. This is an excerpt that will be incorporated into a larger program. I try to break programs into smaller verifiable segments then marry them together for the compete project.
Most of my code learning has occurred by this method of code reuse and modification..

it is a simple timer with a pushbutton reset. There are added display lines for diagnosis that will be removed.

If I could get someone to take a peek and point me in the right direction i would be very appreciative.

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

int timerPin=7; //pushbutton timer button
int timerPinStatus;  //timer reset button state

void setup() {
    Serial.begin(9600);
    lcd.init();  
    lcd.backlight();     
    pinMode(timerPin, INPUT_PULLUP);    
}

void loop() {      
  timer(); //stopwatch timer function   
}   
 
void timer(){
 // timer code
   timerPinStatus=digitalRead(timerPin);
   static unsigned long baseTime = 0;                //Stores time since last reset button press
   unsigned long currTime = millis() - baseTime;     //Adjusted "current time"
   unsigned long seconds = currTime/1000;            //Convert to seconds
   unsigned long minutes = currTime/60000;           //Convert to minutes
   unsigned long hours = currTime/3600000;           //convert to hours
        
    if (timerPinStatus==LOW){                     //If buttonPin is pressed, reset
       baseTime = millis();}           
   static unsigned long lastRefresh = 0;
   int refreshRate = 1000;   
   if (currTime - lastRefresh >= refreshRate){     //Refresh the display     
     lastRefresh = currTime;}                      //Store last time refreshed

       // test output for diagnostic
       lcd.setCursor(0,1);
       lcd.print(seconds);                        // prints total seconds from last reset
       lcd.print("  ");
       lcd.print(minutes);
       lcd.print("  ");
       lcd.print(hours);
           
       lcd.setCursor(0, 3);
       lcd.print("RunTime: ");

       
     if (hours < 10)     {lcd.print("0");}
                         lcd.print(hours);
                         lcd.print(":");
     if (minutes > 59)  {minutes = minutes - (60 * hours);}                    
     if (minutes < 10)  {lcd.print("0");}       
                         lcd.print(minutes); 
                         lcd.print(":");
     if (seconds > 59)  {seconds = seconds - (60 * minutes * hours);}       //should print 0-59 seconds ?                                     
     if (seconds < 10)  {lcd.print("0");}       
                         lcd.print(seconds);

       // diagnostic output                  
      lcd.setCursor(0, 2);
      //lcd.print(currTime);
      lcd.print("    ");
      lcd.print(lastRefresh);
      }
 if (seconds > 59)  {seconds = seconds - (60 * minutes * hours);}

Try changing this line to

if (seconds > 59){seconds = seconds - (60*minutes + 3600*hours);}

Thanks. it works as advertised now..:slight_smile:
The solution makes sense now that i see it..