dateutils/0002-fix-dateadd-unix-timestamp-bug.patch

108 lines
2.8 KiB
Diff
Raw Normal View History

From 6bf090ff595eb6e8da2a3be4812ddad3411d70ee Mon Sep 17 00:00:00 2001
From: Ruediger Meier <ruediger.meier@ga-group.nl>
Date: Mon, 15 Jun 2015 10:56:42 +0200
Subject: [PATCH] fix dateadd unix timestamp bug
Squashed commit of the following:
commit c9f4ec3ad2c3272387b25718b9f8d421537d2d6a
Author: Sebastian Freundt <freundt@ga-group.nl>
Date: Mon Jun 15 08:07:12 2015 +0000
fix, PEBKAC, actually add hours and minutes if requested to sexy date/times
commit 8bc0fd838e782b8c24a2024d33da39c544aaa345
Author: Sebastian Freundt <freundt@ga-group.nl>
Date: Mon Jun 15 07:34:02 2015 +0000
test, add regression tests for dateadd(1) +2m bug
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
lib/dt-core.c | 13 ++++++++-----
test/Makefile.am | 2 ++
test/dtadd.049.clit | 6 ++++++
test/dtadd.050.clit | 5 +++++
4 files changed, 21 insertions(+), 5 deletions(-)
create mode 100644 test/dtadd.049.clit
create mode 100644 test/dtadd.050.clit
diff --git a/lib/dt-core.c b/lib/dt-core.c
index 99a0169..17afb90 100644
--- a/lib/dt-core.c
+++ b/lib/dt-core.c
@@ -249,26 +249,29 @@ __sexy_add(dt_sexy_t sx, struct dt_dtdur_s dur)
/* sexy add
* only works for continuous types (DAISY, etc.)
* we need to take leap seconds into account here */
- signed int delta = 0;
+ dt_ssexy_t dv = dur.dv;
switch (dur.durtyp) {
case DT_DURH:
+ dv *= MINS_PER_HOUR;
case DT_DURM:
+ dv *= SECS_PER_MIN;
case DT_DURS:
+ break;
case DT_DURNANO:
- delta = dur.dv;
+ dv /= NANOS_PER_SEC;
break;
case DT_DURD:
case DT_DURBD:
- delta = dur.d.dv * SECS_PER_DAY;
+ dv = dur.d.dv * SECS_PER_DAY;
/*@fallthrough@*/
case DT_DURUNK:
- delta += dur.t.sdur;
+ dv += dur.t.sdur;
default:
break;
}
/* just go through with it */
- return sx + delta;
+ return sx + dv;
}
#if defined WITH_LEAP_SECONDS && defined SKIP_LEAP_ARITH
diff --git a/test/Makefile.am b/test/Makefile.am
index 83acebb..11ac574 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -686,6 +686,8 @@ dt_tests += dtadd.045.clit
dt_tests += dtadd.046.clit
dt_tests += dtadd.047.clit
dt_tests += dtadd.048.clit
+dt_tests += dtadd.049.clit
+dt_tests += dtadd.050.clit
dt_tests += dtgrep.001.clit
dt_tests += dtgrep.002.clit
diff --git a/test/dtadd.049.clit b/test/dtadd.049.clit
new file mode 100644
index 0000000..d8300d0
--- /dev/null
+++ b/test/dtadd.049.clit
@@ -0,0 +1,6 @@
+#!/usr/bin/clitoris ## -*- shell-script -*-
+
+$ dadd -z "Europe/Berlin" "2015-06-13T00:18:20" "+2m" -f "%Y%m%d %T Europe/Berlin"
+20150613 02:20:20 Europe/Berlin
+$
+
diff --git a/test/dtadd.050.clit b/test/dtadd.050.clit
new file mode 100644
index 0000000..36ae2cd
--- /dev/null
+++ b/test/dtadd.050.clit
@@ -0,0 +1,5 @@
+#!/usr/bin/clitoris ## -*- shell-script -*-
+
+$ dadd -z "Europe/Berlin" "@1434147500" "+2m" -f "%Y%m%d %T Europe/Berlin"
+20150613 00:20:20 Europe/Berlin
+$
--
1.8.4.5