@agraham - thanks for that. Maintaining a date for the hardware in the app is definitely another approach, that I hadn't thought of.
@udg - Thanks also. I'm not sure your code would work too differently to the original, there's still a cut-off point where it won't work (the chosen threshold). But using the time difference might is another approach that I hadn't thought of that.
I need to think both of these options through, and maybe use a combination of them & the original code.
@MicroDrie - thanks for your response as well. Apologies, my initial post was a little vague I guess.
why don't you just log the real time as a date and time entry with the time message from some hardware when you got it?
The hardware is a data logger that stores data/events into time periods (hourly for example). I need to use the time reported by the hardware so that I know what period it is in in relation to its own time.
The only acceptable answer to that is: The time on some hardware is synchronized with the reference time with no date, but between setting the time and sending that time there can be arise a few seconds, minutes, or hours delay.
Yes, the hardware time is synchronised once a day, so it
shouldn't drift too far before the next synchronisation. Hence the code in post 1 should be enough 99.9% of the time. I'm just trying to cover all bases here and (perhaps stupidly) cope with the 0.1% of occasions when it drifts more than 1 hour.
"Why make it hard when it can do a lot harder?"
I'm not sure what you mean by this?