temp="$(mktemp)"
trap "rm -f '$temp'" EXIT
-timedatectl > "$temp"
+LC_ALL=C timedatectl > "$temp"
ut=$(sed '/Universal time:/ { s/^[^:]*: *//; p}; d' "$temp")
rtc=$(sed '/RTC time:/ { s/^[^:]*: *//; p}; d' "$temp")
ntpenabled=$(sed '/\(NTP enabled\|Network time on\):/ { s/^[^:]*: *//; p}; d' "$temp")
ntpsynced=$(sed '/NTP synchronized:/ { s/^[^:]*: *//; p}; d' "$temp")
uts=$(TZ=UTC date -d "$ut" +%s)
-rtcs=$(TZ=UTC date -d "$rtc" +%s)
-delta=$((uts - rtcs))
+rtcs=$(TZ=UTC date -d "$rtc" +%s 2>/dev/null || echo "N/A")
+if [ "$rtcs" != "N/A" ]; then
+ delta=$((uts - rtcs))
+fi
if [ "$SYNSTATUSONLY" -ge 1 ]; then
if [ "$ntpsynced" != "yes" ]; then
exit 1
fi
else
+ if [ "$rtcs" = "N/A" ]; then
+ echo "Warning: Cannot parse RTC $rtc."
+ exit 1
+ fi
+
if [ "$delta" -lt "-$MAX" ] ||
[ "$delta" -gt "$MAX" ]; then
echo "Warning: time desync $delta: RTC vs. system time: $rtc vs. $ut"