core/clock/rotate.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * @file rotate.c | ||
| 3 | * @brief Working out which one is up from the clock. | ||
| 4 | * | ||
| 5 | * @ingroup lib_core | ||
| 6 | */ | ||
| 7 | #include "rotate.h" | ||
| 8 | |||
| 9 | 23 | int rotate_index(int year, int yday, int hour, int minute, int interval_min, int count) | |
| 10 | { | ||
| 11 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (count <= 0) |
| 12 | { | ||
| 13 | ✗ | return 0; | |
| 14 | } | ||
| 15 | |||
| 16 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 21 times.
|
23 | if (interval_min <= 0) |
| 17 | { | ||
| 18 | 2 | return 0; | |
| 19 | } | ||
| 20 | |||
| 21 | // a plain running count of minutes that only has to climb as time passes. the days-in-a-year | ||
| 22 | // figure is a round 366 rather than the real length, so crossing into a non-leap new year jumps | ||
| 23 | // the counter by an extra day. the rotation skips ahead there rather than stepping by one, and | ||
| 24 | // for a count that divides the jump it can land on the same one twice. one ragged boundary a year | ||
| 25 | 21 | long minutes = (((long)year * 366 + yday) * 24 + hour) * 60 + minute; | |
| 26 | 21 | long bucket = minutes / interval_min; | |
| 27 | |||
| 28 | // normalise in case the clock is before 1900 and the minute count comes out negative | ||
| 29 | 21 | return (int)(((bucket % count) + count) % count); | |
| 30 | } | ||
| 31 |