summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/djbtime-internal.h6
-rw-r--r--src/libstddjb/ltm64_from_tai.c21
-rw-r--r--src/libstddjb/ltm64_from_utc.c20
-rw-r--r--src/libstddjb/skalibs_tzisright.c17
-rw-r--r--src/libstddjb/tai_from_ltm64.c21
5 files changed, 42 insertions, 43 deletions
diff --git a/src/libstddjb/djbtime-internal.h b/src/libstddjb/djbtime-internal.h
index 26ffc81..819b88a 100644
--- a/src/libstddjb/djbtime-internal.h
+++ b/src/libstddjb/djbtime-internal.h
@@ -6,7 +6,7 @@
#include <skalibs/uint64.h>
-/* Leap second handling, for UTC <--> TAI conversions */
+ /* Leap second handling, for UTC <--> TAI conversions */
#define LEAPSECS_MAX 39
#define LEAPSECS_FILE SKALIBS_ETC "/leapsecs.dat"
@@ -20,4 +20,8 @@ extern int leapsecs_sub_r (uint64 *, char const *, uint64 *) ;
#define leapsecs_sub(t) leapsecs_sub_r((t), LEAPSECS_FILE, leapsecs_here)
+ /* Run-time test: does the current timezone handle leap seconds ? */
+
+extern int skalibs_tzisright (void) ;
+
#endif
diff --git a/src/libstddjb/ltm64_from_tai.c b/src/libstddjb/ltm64_from_tai.c
index c0650c5..9161a79 100644
--- a/src/libstddjb/ltm64_from_tai.c
+++ b/src/libstddjb/ltm64_from_tai.c
@@ -1,23 +1,16 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/tai.h>
#include <skalibs/djbtime.h>
-
-#ifdef SKALIBS_FLAG_TZISRIGHT
+#include "djbtime-internal.h"
int ltm64_from_tai (uint64 *u, tai_t const *t)
{
- *u = t->x - 10U ;
- return 1 ;
+ switch (skalibs_tzisright())
+ {
+ case 1 : *u = t->x - 10U ; return 1 ;
+ case 0 : return utc_from_tai(u, t) ;
+ default : return 0 ;
+ }
}
-
-#else
-
-int ltm64_from_tai (uint64 *u, tai_t const *t)
-{
- return utc_from_tai(u, t) ;
-}
-
-#endif
diff --git a/src/libstddjb/ltm64_from_utc.c b/src/libstddjb/ltm64_from_utc.c
index 8d66813..28907c9 100644
--- a/src/libstddjb/ltm64_from_utc.c
+++ b/src/libstddjb/ltm64_from_utc.c
@@ -1,23 +1,15 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/djbtime.h>
#include "djbtime-internal.h"
-#ifdef SKALIBS_FLAG_TZISRIGHT
-
int ltm64_from_utc (uint64 *u)
{
- return (leapsecs_add(u, 0) >= 0) ;
+ switch (skalibs_tzisright())
+ {
+ case 1 : return leapsecs_add(u, 0) >= 0 ;
+ case 0 : return 1 ;
+ default : return 0 ;
+ }
}
-
-#else
-
-int ltm64_from_utc (uint64 *u)
-{
- (void)u ;
- return 1 ;
-}
-
-#endif
diff --git a/src/libstddjb/skalibs_tzisright.c b/src/libstddjb/skalibs_tzisright.c
new file mode 100644
index 0000000..f8414a6
--- /dev/null
+++ b/src/libstddjb/skalibs_tzisright.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <time.h>
+#include "djbtime-internal.h"
+
+int skalibs_tzisright ()
+{
+ static int tzisright = -1 ;
+ if (tzisright < 0)
+ {
+ struct tm tm ;
+ time_t t = 78796800 ;
+ if (localtime_r(&t, &tm)) tzisright = tm.tm_sec == 60 ;
+ }
+ return tzisright ;
+}
diff --git a/src/libstddjb/tai_from_ltm64.c b/src/libstddjb/tai_from_ltm64.c
index 2538c00..12a7394 100644
--- a/src/libstddjb/tai_from_ltm64.c
+++ b/src/libstddjb/tai_from_ltm64.c
@@ -1,23 +1,16 @@
/* ISC license. */
-#include <skalibs/config.h>
#include <skalibs/uint64.h>
#include <skalibs/tai.h>
#include <skalibs/djbtime.h>
-
-#ifdef SKALIBS_FLAG_TZISRIGHT
+#include "djbtime-internal.h"
int tai_from_ltm64 (tai_t *t, uint64 u)
{
- tai_u64(t, u + 10U) ;
- return 1 ;
+ switch (skalibs_tzisright())
+ {
+ case 1 : tai_u64(t, u + 10U) ; return 1 ;
+ case 0 : return tai_from_utc(t, u) ;
+ default : return 0 ;
+ }
}
-
-#else
-
-int tai_from_ltm64 (tai_t *t, uint64 u)
-{
- return tai_from_utc(t, u) ;
-}
-
-#endif