]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
reference: announce leap second only on last day of June and December
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Jun 2014 12:55:00 +0000 (14:55 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Jun 2014 14:58:41 +0000 (16:58 +0200)
reference.c

index 503f672c2af49d465b3d90dd32b9602efb38a997..2d3c9cb02486012a9e726d777b1c0f4e25720755 100644 (file)
@@ -593,6 +593,15 @@ is_offset_ok(double offset)
 
 /* ================================================== */
 
+static int
+is_leap_second_day(struct tm *stm) {
+  /* Allow leap second only on the last day of June and December */
+  return (stm->tm_mon == 5 && stm->tm_mday == 30) ||
+         (stm->tm_mon == 11 && stm->tm_mday == 31);
+}
+
+/* ================================================== */
+
 static NTP_Leap
 get_tz_leap(time_t when)
 {
@@ -610,12 +619,7 @@ get_tz_leap(time_t when)
 
   stm = *gmtime(&when);
 
-  /* Check for leap second only in the latter half of June and December */
-  if (stm.tm_mon == 5 && stm.tm_mday > 14)
-    stm.tm_mday = 30;
-  else if (stm.tm_mon == 11 && stm.tm_mday > 14)
-    stm.tm_mday = 31;
-  else
+  if (!is_leap_second_day(&stm))
     return tz_leap;
 
   /* Temporarily switch to the timezone containing leap seconds */
@@ -657,7 +661,6 @@ get_tz_leap(time_t when)
 static void
 update_leap_status(NTP_Leap leap, time_t now)
 {
-  struct tm stm;
   int leap_sec;
 
   leap_sec = 0;
@@ -666,20 +669,16 @@ update_leap_status(NTP_Leap leap, time_t now)
     leap = get_tz_leap(now);
 
   if (leap == LEAP_InsertSecond || leap == LEAP_DeleteSecond) {
-    /* Insert/delete leap second only on June 30 or December 31
-       and in other months ignore the leap status completely */
-
-    stm = *gmtime(&now);
+    /* Check that leap second is allowed today */
 
-    if (stm.tm_mon != 5 && stm.tm_mon != 11) {
-      leap = LEAP_Normal;
-    } else if ((stm.tm_mon == 5 && stm.tm_mday == 30) ||
-        (stm.tm_mon == 11 && stm.tm_mday == 31)) {
+    if (is_leap_second_day(gmtime(&now))) {
       if (leap == LEAP_InsertSecond) {
         leap_sec = 1;
       } else {
         leap_sec = -1;
       }
+    } else {
+      leap = LEAP_Normal;
     }
   }