"If you restart your Arduino, say, five hours later, this time value will not make much sense anymore." It will keep the value because the Arduino has an RTC attached.
Yes, but how do you make sure that the above
RTC.adjust(DateTime(__DATE__, __TIME__)); line is executed only once after each compilation and NOT executed during later restarts?
If you call that
adjust every time your Arduino starts, it will simply override your current RTC time with the hardcoded compilation time, thus completely defeating the purpose of having a RTC clock. If you compiled your program on January 1, 2019, every time you start your Arduino it will bash January 1, 2019 into your RTC clock.
I use my Arduino for lots of tasks, one being a clock for my grandkids which uses different coloured leds to show the time. When the grandkids come to stay I set up the clock, and for that I need the real time where we actually are and not the time where some random server is. The RTC keeps the time for the whole of their visit of two or three days, and then I dismantle the setup and use the Arduino for other things.
That's great, but what if you will simply need to power off/power on the clock? In this case a RTC clock with battery backup is actually quite useful, since it will continue to keep proper time while your Arduino is powered off/restarting.
Meanwhile, it appears that when you power up your Arduino, instead of reading proper time from the RTC clock, you simply do
RTC.adjust(DateTime(__DATE__, __TIME__));. I.e. you ignore the proper time and instead override it with some inaccurate values from the past.
Again, were in your code is that
RTC.adjust(DateTime(__DATE__, __TIME__)); located?