Overflow of millis

Hi, I have started working on an app that will work long term. It will be powered by a battery that will be recharged from the grid/solar panel. So unless there is some problem, the app can run for up to a few years.

The processes will be queued using millis() function. This is where the overflow problem occurs. So I was looking for a solution and I found actually a very simple one.
Instead of:

if(lastJob + 2000 <= millis()){

Use:

if ((unsigned long)(millis() - lastJob) > 2000){

Which I verified with this dump:

if ((unsigned long)(millis() - lastJob) > 2000)
  {
    Serial.print(millis() - lastJob);
    Serial.print("/");
    Serial.println(millis());
    lastJob = millis();
  }

And I guess it works, but I wonder how it's really going to be in the long run. The millis() method did once reach its limit based on the data type.

Or am I understanding the whole thing wrong?

if you do it like demonstrated in the "Blink Without Delay" example the rollover is no problem.

The cast to 'unsigned long' is not needed. The millis() function returns 'unsigned long' and 'lastjob', which SHOULD be 'unsigned long' will get promoted to 'unsigned long' if it is some other integer type.

Accelerated quick test ...

void setup() {
  Serial.begin(115200);
  uint32_t ms = 0xFFFFFFFC;
  for (int i = 0; i < 10; i++) {
    Serial.print((ms + i) - ms);
    Serial.print("/");
    Serial.println(ms + i);
  }
}

void loop() {
}

The subtraction method will definitely work. If I switch my Casio calculator into hex mode, and enter 10 - FFF0 = I get 20. Well actually I get FFFF0020, but an unsigned long only has the four least significant bytes.