From 66fcd01f861c735b573f7e07e5d297c0996e0a50 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 11 Jun 2024 16:17:37 +0200 Subject: [PATCH] nmea: Fix conversion of leap second. 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 Reviewed-by: Jacob Keller --- nmea.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nmea.c b/nmea.c index 7f1d9a26..b84b42e9 100644 --- a/nmea.c +++ b/nmea.c @@ -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;