Right, so 72 entries is a sort-of limit. That should maybe be mentioned somewhere in the developer documentation to avoid anyone hitting issues.
However, as this the Simulator and a development device those limits shouldn't apply.
Anyway, thanks, but that still doesn't help.
Even if I change the timeline to have just one day of 72 timeline entries (every 20 minutes for 24 hours), the widgets are still out of whack after just a few minutes.
Due to the way timers work in SwiftUI, we developers are having to write a ton of fragile code to work around Apple's limited implementation.
I want to show my users a countdown timer that has something like 12 days, 13:45:18. If I use the standard Text.init(date, style: .timer) I will get something like 301:45:18.
The developer docs show this example: Example output: 2:32 36:59:01
Who in their right mind would ever want to see a countdown of 36 hours 59 minutes 1 second? No one. Users want to see "1 day 12 hours 59 minutes 1 second", or a friendlier "1 day, 12:59:01". And I can't just modulus the hours to remove 24 hour chunks because that doesn't cover different timezones and calendars. Even if I could, there's no way of intercepting the 36 hours bit of the timer output and changing it anyway.
I have to write code that figures out how many hours, minutes and seconds should be displayed - which should never be more than 23:59:59 - to then be applied to the countdown timer, then display the larger units separately, i.e. "1 day".
Apple's current implementation does not allow for this, so I'm having to write code that figures this out. And I've done it. And that code runs correctly. When I view the previews in Xcode I can see the correct timeline entries.
Using Christmas at 9:00:00am as an example:
A timeline entry is added with a date of Date.now, which for argument's sake is 11th December at 11:33:00pm.
The event date - the actual date of the event, i.e. 9am on 25th December - is therefore 13 days, 9 hours and 27 minutes away.
My widget should show 13 days 9:27:00, and it does.
(Ignore the slight discrepancy between typing this and taking a screenshot, but you can see that the first entry in the timeline is 13 days 9:26:19.)
Look at entry 3: the entry date is one minute later than 11:33:00pm, so it's showing a countdown timer of 13 days 9:25:19, i.e. one minute later. If I scroll through the preview entries I see each entry is 20 minutes closer to Christmas than before. This is correct.
Now, when I deploy this to a device or even the Simulator, I see completely Whacko-Jacko timers.
Here's a screenshot of a macOS Sequoia desktop widget (which is the same as that seen on my iPhone), showing 13 days 1:22:14 taken at 23:42:46:
If you add 13 days 1:22:14 to 11th Dec 23:42:46 you get 25th Dec at 1:05:00am. How is that a valid countdown to 9:00:00am on Christmas Day?!
Oh, and here's one that's apparently being refreshed every 20 minutes but has still managed to go over 23:59:59:
As I said, I'm very close to just removing widgets altogether because they simply do not work as advertised, and your countdown timers are inflexible and unusable.
I feel I also need to point out how you've managed to invent an extra second with your timers... When a normal timer is counting down to 0:00 and then counts into negative time, it goes:
0:03... 0:02... 0:01... 0:00... -0.01... -0.02... -0:03
Your timers go:
0:03... 0:02... 0:01... 0:00... 0:00... -0.01... -0.02... -0:03
How about I just send you a zip file of my entire application and you can figure out how to get it to work properly?
I apologise if you feel this is an attack, but I have been dealing with this crud for years and I'm getting nowhere. There is likely a really simple fix, and if one of you wishes to spend some time writing a function that calculates the difference between two dates and puts those values into a user-friendly countdown timer, then please do so. I would be immensely grateful.