I am working on an app where the user can set sample frequency between 1 - 8 hours, adjusted to closest full hour, to collect and process data.
Example-1, frequency set to 8 hour and starts @ 06:00:
06:00 -> 14:00 -> 22:00 -> 06:00 (add day)
Example-2, frequency set to 3 hour and starts @ 20:00:
20:00 - > 23:00 -> 02:00 (add day) -> 05:00
Example-3, frequency set to 3 hour and starts @ 08:00 = no problem with date change:
08:00 - > 11:00 -> 14:00 -> 17:00
I use the following format on the sample date-time "yyyy-MM-ddTHH:00:00Z" but the only date that is generated is current date meaning I need to add a day when crossing midnight.
My problem is that I have not figured out the logic how to determine, if required, when crossing over to the next date without to much spagetti code? ...given that the date change can happen in any of samples 2 - 4.
And then tried to determine but failed.
Any help would be appreciated.