This pull request aims at fixing an issue with time conversion. In my understanding, the current implementation of watch_utility_date_time_to_unix_time is incorrect. The function converts a watch_date_time struct to a Unix timestamp. However, It does not return the correct timestamp for leap years. I couldn't figure out exactly where the incorrect calculation occurs, but the following test cases help illustrate the problem:
Leap year: 2020-01-01 00:00:00 GMT. This date should should be converted to 1577836800.
Non-leap year: 2021-01-01 00:00:00 GMT. This date should should be converted to 1609459200.
The following code displays both values in the simulator.
In the current implementation the first test case returns 1577923200 (incorrect) and the second 1609459200 (correct).
Instead of reverse engineering the current implementation of watch_utility_convert_to_unix_time, I adapted the corresponding code from musl libc, which has already been used in other parts of the project. The code is surprisingly complex and I suspect that the old version misses some edge cases. With this pull request, both Unix times are now calculated correctly.
I am a little nervous about this fix, as it affects a large number of watch faces (16 complications and 3 clocks). If this is a misunderstanding on my part, I apologize for the inconvenience and the false alarm.
This pull request aims at fixing an issue with time conversion. In my understanding, the current implementation of
watch_utility_date_time_to_unix_time
is incorrect. The function converts awatch_date_time
struct to a Unix timestamp. However, It does not return the correct timestamp for leap years. I couldn't figure out exactly where the incorrect calculation occurs, but the following test cases help illustrate the problem:2020-01-01 00:00:00 GMT
. This date should should be converted to1577836800
.2021-01-01 00:00:00 GMT
. This date should should be converted to1609459200
.The following code displays both values in the simulator.
In the current implementation the first test case returns
1577923200
(incorrect) and the second1609459200
(correct).Instead of reverse engineering the current implementation of
watch_utility_convert_to_unix_time
, I adapted the corresponding code from musl libc, which has already been used in other parts of the project. The code is surprisingly complex and I suspect that the old version misses some edge cases. With this pull request, both Unix times are now calculated correctly.I am a little nervous about this fix, as it affects a large number of watch faces (16 complications and 3 clocks). If this is a misunderstanding on my part, I apologize for the inconvenience and the false alarm.
Best regards, Konrad