Using millis() for timing from data-logger example sketch

My question relates to timing data logger entries, where precise timing is necessary to avoid accumulating errors.
The code walkthrough for the "Light and Temperature Logger" example for the Adafruit data logger shield nestles the timing calculation into the delay() function, which is really slick.

void loop(void)
{
  DateTime now;
 
  // delay for the amount of time we want between readings
 // LOG_INTERVAL is in milliseconds
  
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));

 //rest of logging code

I understand that (millis() % LOG_INTERVAL) is compensating for the time it took to to run the rest of the loop, but I don't understand why we must subtract 1 from LOG_INTERVAL. Is it compensating for the time it takes to run that nested expression, and assuming it is 1 millisecond?

aman33331:
which is really slick.

If I can prove the snippet occasionally fails will you still consider it "slick"?

Given the fact that you don't understand it why do you believe it to be superior ("slick")?

aman33331:
...precise timing...

Only by a roll of the dice.

This tutorial: Overview | Adafruit Data Logger Shield | Adafruit Learning System ?
With this shield: Adafruit Assembled Data Logging shield for Arduino : ID 1141 : $13.95 : Adafruit Industries, Unique & fun DIY electronics and kits ?
Here is the delay() "explained": Code Walkthrough | Adafruit Data Logger Shield | Adafruit Learning System.

That delay is used to take a sample every second.

#define LOG_INTERVAL  1000
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));

I think the "-1" is for the code inside the loop(). But as Coding Badly already wrote, that line of code is a mistake. I suggest you ignore that code. Don't think about it, it is wrong anyway.

To understand millis(), you should read the Blink Without Delay page: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay.
That example does also something every second. It can be used to blink a led, but also to take a sample of light and temperature and write it to a file.

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R