Previously in our app we were using json files where time_offset value for negative time zones was just negative time in seconds (e.g. -18000). After switching to fit file, we started saving time_offset in the database in minutes (i.e. time_offset from fit file divided by 60). Unfortunately, no one expected that time_offset for negative time zones would be expressed differently.
Now in the database I have, for example, the x value, which I need to multiply by 60 to get the y value corresponding to the time_offset from the fit file. I need to add the y value to the timestamp from the fit file and convert the result to a 32-bit number. Then subtracting this 32-bit digit from timestamp, I get time_offset in seconds:
x | y | timestamp | sum | 32bit integer | time_offset in seconds | hours | |
(time_offset from our db) | time_offset from fit file(x*60) | timestamp from fit file | y + timestamp | sum | 0 | "-(timestamp - 32bit integer)" | time_offset in seconds/60/60 | |
1 | 71582488.2666666 | 4294949296 | 1646575923 | 5941525219 | 1646557923 | -18000 | -5 |
2 | 71582548.2666666 | 4294952896 | 1667158354 | 5962111250 | 1667143954 | -14400 | -4 |
3 | 71582713.2666666 | 4294962796 | 1667140674 | 5962103470 | 1667136174 | -4500 | -1.25 |
4 | 71582773.2666666 | 4294966396 | 1661463139 | 5956429535 | 1661462239 | -900 | -0.25 |
5 | 71582787.3333333 | 4294967240 | 1647715116 | 5942682356 | 1647715060 | -56 | -0.015555556 |
This approach I found here: https://forums.garmin.com/developer/connect-iq/i/bug-reports/corrupt-time_offset-in-a-watch-app-fit-file-when-time-zone-is-negative however, it seems to fit just first two x values.
I also have some values in database which seems NOT to fit above algorithm at all.
x | y | |
(time_offset from our db) | time_offset from fit file(x*60) | |
1 | 1 | 60 |
2 | 43 | 2580 |
3 | 58.6 | 3516 |
4 | 59.01666667 | 3541 |
5 | 59.23333333 | 3554 |
6 | 59.93333333 | 3596 |
7 | 60.7 | 3642 |
8 | 61 | 3660 |
9 | 89 | 5340 |
10 | 118.6 | 7116 |
11 | 119 | 7140 |
12 | 119.2333333 | 7154 |
13 | 119.9166667 | 7195 |
14 | 119.9333333 | 7196 |
15 | 120.7 | 7242 |
16 | 121 | 7260 |
17 | 195 | 11700 |
18 | 281.0333333 | 16862 |
19 | 313.5666667 | 18814 |
20 | 719 | 43140 |
21 | 780 | 46800 |
Could someone explain what is the proper algorithm to convert time_offset from fit file for negative time zones, to seconds?