simple time keeping

Hello.

I have been reading up on how to use my DS3231 (A.wickart library) for time keeping and I have been finding that trying to use 12 hour, 24 hour and even UNIX time requires a lot of structuring and is just plain complicated for projects that do not need to run until our planet stops spinning.

I am still going to use the RTC to provide a time stamp for memory purposes and display time date for an LCD display (not displayed in post code and is outside of the scope of my up coming question). But for time related functions I made a simple timer to do what I feel "unix time" set out to do; Take time and make it a universal value that can be calculated from.

My question: Will my code be too processor and memory intensive?

If yes please explain from your understanding what might be a better way? (simplicity is ace functionality is king)

//global variables

long start_time = 0; 
long seconds = 0;
long minutes = 0;
long hours = 0;
long days = 0;

void setup() {

}

void loop() {

  if(millis() - start_time > 1000){
    seconds++;
    start_time = millis();
  }

  if(seconds > 60){
    minutes++;
    minutes = 0;
  }
  
  if(minutes > 60){
    hours++;
    hours = 0;
  }

   if(hours > 24){
    days++;
    days = 0;
  }
  

}

Compile the code and You will know about the memory usage from the compiler report.
Run the code and You will se if the processor manages or not. Using some Serial.print and Serial Monitor can give inside information.

Yes,your code will be 100% processor-intensive.

True.
I don't understand the logic in this piece of code:

 if(seconds > 60){
    minutes++;
    minutes = 0;// Reset the recently increased minutes to zero
  }
  
  if(minutes > 60){
    hours++;
    hours = 0;
  }

   if(hours > 24){
    days++;
    days = 0;
  }

When can I expect the introduction of your universal time system, will it be an ANSI standard? It's about time someone simplified Epoch time. How silly of all those people who blindly tolerated the burdensome inconvenience of it, all these 60 years. Also that ridiculously complicated 12/24 hour system idea, what drunken Roman came up with that? Think of all the wasted opportunities, these last 1,800 years.

Will my code be too processor and memory intensive?

Doesn't matter, because it won't work anyway. As noted above, there are several serious errors.

Check out the Time library (TimeLib.h). It makes most things to do with timing and dates pretty easy. As you might discover, hours, minutes, days etc. are extremely inconvenient for event timing.

You could try something like this.
Please be aware that this code requires you to have a 16x2 LCD display. It also requires you to know how to correctly wire that display to your Arduino. But, even if you don't have such a display, you can still examine the code to see how it does the timing.

// how_long_running.ino
// by odometer  2018-12-14

// This sketch answers the question: "How long have I been running?"
// The answer is shown on a 16x2 LCD character display.

#include <LiquidCrystal.h>

// declare and initialize variables
int nowDays    = 0; // "days" part of elapsed time
int nowHours   = 0; // "hours" part of elapsed time
int nowMinutes = 0; // "minutes" part of elapsed time
int nowSeconds = 0; // "seconds" part of elapsed time
int nowTenths  = 0; // "tenths of seconds" part of elapsed time
unsigned long microsAtLastTenth = 0UL; // value of micros() at most recent 1/10 second

// a pretty important constant
const unsigned long MICROS_PER_TENTH = 100000UL; // number of microseconds per 1/10 second

// here we specify what pins our LCD is on
//                RS  EN  D4  D5  D6  D7
LiquidCrystal lcd(12, 11,  5,  4,  3,  2);

void setup() {
 
  // start the LCD going
  lcd.begin(16, 2);
 
  // display the time (which at this point will be all zeros)
  updateTimeDisplay();
 
}

void loop() {
 
  // check if it is time for the clock to advance
  if ((micros() - microsAtLastTenth) >= MICROS_PER_TENTH) {
   
    // make the clock advance 1/10 of a second
    nowTenths++;
   
    // make sure that the next advance happens exactly when it is due
    // (they should happen exactly at intervals of 1/10 of a second)
    microsAtLastTenth += MICROS_PER_TENTH;
   
    // our clock needs to do more than count tenths of seconds
    // it also needs to count whole seconds, and minutes, and hours, and days
    // so let's go ahead and do that

    // too many tenths?
    if (nowTenths >= 10) {
      // trade 10 tenths for 1 second
      nowTenths -= 10;
      nowSeconds++;
    }
   
    // too many seconds?
    if (nowSeconds >= 60) {
      // trade 60 seconds for 1 minute
      nowSeconds -= 60;
      nowMinutes++;
    }
   
    // too many minutes?
    if (nowMinutes >= 60) {
      // trade 60 minutes for 1 hour
      nowMinutes -= 60;
      nowHours++;
    }
   
    // too many hours?
    if (nowHours >= 24) {
      // trade 24 hours for 1 day
      nowHours -= 24;
      nowDays++;
    }
   
    // update the display so we can see the new time
    updateTimeDisplay();
   
  }
 
}


void updateTimeDisplay () {
  // function to update the display to show the current elapsed time
  //
  // we want the display to look like this
  //   Position: 01234567890123456
  //     Line 0:  days  h  m  s 
  //     Line 1:     0 00:00:00.0

  // declare a buffer for storing a string (we'll need it later)
  // we expect to need only 16 characters, but to be safe, let's make room for 20
  // so we allow 20 characters worth of room, plus 1 extra for the null terminator
  // (Always allow 1 character extra worth of room for the null terminator!)
  char buf[21];

  // move to the top line of the display
  lcd.setCursor(0,0);
 
  // show the units
  lcd.print(" days  h  m  s  ");
 
  // convert the elapsed time to a string
  // for days, allow 5 digits worth of room
  // for hours, minutes, and seconds, allow 2 digits for each, and use leading zeros
  // for tenths, allow 1 digit worth of room
  sprintf(buf, "%5d %02d:%02d:%02d.%1d", nowDays, nowHours, nowMinutes, nowSeconds, nowTenths);

  // move to the bottom line of the display 
  lcd.setCursor(0,1);
 
  // show the string for the elapsed time
  lcd.print(buf);
}