Go Down

Topic: Time Maths (Read 549 times) previous topic - next topic

jonwhitear

#5
Nov 26, 2012, 03:48 am Last Edit: Nov 26, 2012, 10:23 am by jonwhitear Reason: 1
Thanks for the pointers folks.

time_t is indeed already in seconds When I first tried this, I got some unexpected results manipulating the time_t directly (e.g. adding 3600 seconds to it to increment the hour) so I thought there must be a reason why I couldn't do that. I've tried this again now and it's working as expected. Fortunately that means I don't need to check for overflows now.

My button read function does only register a button press once.

Edit: For the sake of completeness, here's the working function...

Code: [Select]
time_t ModifyScreenElementTime(time_t InputTime)

  if (ReadButton(LEFT) == BUTTON_PRESS) InputTime += 60;         // Increment Input time by 1 minute
  if (ReadButton(RIGHT) == BUTTON_PRESS) InputTime -= 60;        // Decrement Input time by 1 minute
  if (ReadButton(LEFT) == BUTTON_PRESS_HOLD) InputTime += 3600;  // Increment Input time by 1 hour
  if (ReadButton(RIGHT) == BUTTON_PRESS_HOLD) InputTime -= 3600; // Decrement Input time by 1 hour
 
  if (InputTime < now()) InputTime = now(); //Timer can't start before now
  return InputTime;
}


Cheers,

Jon

Go Up