Skip to content

Commit

Permalink
nmea: Fix conversion of leap second.
Browse files Browse the repository at this point in the history
When a leap second is inserted, the RMC message reports time of
23:59:60, which overflows in mktime() to 0:00:00 after the leap second
with an incremented TAI-UTC offset. This causes a one-second error in
the offset meaured by ts2phc.

Check the seconds field of the RMC message and convert 60 to 59 to make
the timestamp ambiguous per is_utc_ambiguous() and ignored by ts2phc to
avoid updating the clock with the one-second error.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
  • Loading branch information
mlichvar authored and richardcochran committed Jul 30, 2024
1 parent e110cd9 commit 66fcd01
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nmea.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ static int nmea_scan_rmc(struct nmea_parser *np, struct nmea_rmc *result)
if (cnt != 3) {
return -1;
}
/* Convert an inserted leap second to ambiguous 23:59:59 */
if (tm.tm_sec == 60)
tm.tm_sec = 59;
tm.tm_year += 100;
tm.tm_mon--;
tm.tm_isdst = 0;
Expand Down

0 comments on commit 66fcd01

Please sign in to comment.