SHA256
1
0
forked from pool/dateutils
Dominique Leuenberger 2015-09-01 22:36:48 +00:00 committed by Git OBS Bridge
commit 8cce5e9088
6 changed files with 19 additions and 358 deletions

View File

@ -1,242 +0,0 @@
From e1d38700985ebe944554821e4758b03bf011b18f Mon Sep 17 00:00:00 2001
From: Ruediger Meier <ruediger.meier@ga-group.nl>
Date: Fri, 12 Jun 2015 12:36:49 +0200
Subject: [PATCH] fix build for compilers without anonymous struct
initialisation
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
lib/date-core.h | 6 ++++++
lib/dt-core-strpf.c | 8 ++++++++
lib/dt-core-tz-glue.c | 16 ++++++++++++++++
lib/dt-core.c | 4 ++--
src/dround.c | 15 ++++++++++++++-
src/dseq.c | 27 ++++++++++-----------------
test/dtcore-add.c | 6 +++---
7 files changed, 59 insertions(+), 23 deletions(-)
diff --git a/lib/date-core.h b/lib/date-core.h
index 5b55154..044d69e 100644
--- a/lib/date-core.h
+++ b/lib/date-core.h
@@ -566,7 +566,13 @@ dt_make_ymcw(unsigned int y, unsigned int m, unsigned int c, unsigned int w)
static inline struct dt_ddur_s
dt_make_ddur(dt_durtyp_t typ, dt_dur_t d)
{
+#if defined HAVE_ANON_STRUCTS_INIT
return (struct dt_ddur_s){typ, .dv = d};
+#else
+ struct dt_ddur_s res = {typ};
+ res.dv = d;
+ return res;
+#endif
}
static inline dt_bizda_param_t
diff --git a/lib/dt-core-strpf.c b/lib/dt-core-strpf.c
index 9aec1fd..c19ae3a 100644
--- a/lib/dt-core-strpf.c
+++ b/lib/dt-core-strpf.c
@@ -133,7 +133,15 @@ __fixup_zdiff(struct dt_dt_s dt, int32_t zdiff)
{
/* apply time zone difference */
/* reuse dt for result */
+#if defined HAVE_ANON_STRUCTS_INIT
dt = dt_dtadd(dt, (struct dt_dtdur_s){DT_DURS, .dv = -zdiff});
+#else
+ {
+ struct dt_dtdur_s tmp = {DT_DURS};
+ tmp.dv = -zdiff;
+ dt = dt_dtadd(dt, tmp);
+ }
+#endif
dt.znfxd = 1;
return dt;
}
diff --git a/lib/dt-core-tz-glue.c b/lib/dt-core-tz-glue.c
index ee7d5cd..cb1314d 100644
--- a/lib/dt-core-tz-glue.c
+++ b/lib/dt-core-tz-glue.c
@@ -74,7 +74,15 @@ dtz_forgetz(struct dt_dt_s d, zif_t zone)
d_unix = zif_utc_time(zone, d_locl);
if (LIKELY((zdiff = d_unix - d_locl))) {
/* let dt_dtadd() do the magic */
+#if defined HAVE_ANON_STRUCTS_INIT
d = dt_dtadd(d, (struct dt_dtdur_s){DT_DURS, .dv = zdiff});
+#else
+ {
+ struct dt_dtdur_s tmp = {DT_DURS};
+ tmp.dv = zdiff;
+ d = dt_dtadd(d, tmp);
+ }
+#endif
d.znfxd = 1;
if (zdiff > 0) {
d.neg = 1;
@@ -108,7 +116,15 @@ dtz_enrichz(struct dt_dt_s d, zif_t zone)
d_locl = zif_local_time(zone, d_unix);
if (LIKELY((zdiff = d_locl - d_unix))) {
/* let dt_dtadd() do the magic */
+#if defined HAVE_ANON_STRUCTS_INIT
d = dt_dtadd(d, (struct dt_dtdur_s){DT_DURS, .dv = zdiff});
+#else
+ {
+ struct dt_dtdur_s tmp = {DT_DURS};
+ tmp.dv = zdiff;
+ d = dt_dtadd(d, tmp);
+ }
+#endif
if (zdiff > 0) {
d.zdiff = (uint16_t)(zdiff / ZDIFF_RES);
} else if (zdiff < 0) {
diff --git a/lib/dt-core.c b/lib/dt-core.c
index 76a78fe..99a0169 100644
--- a/lib/dt-core.c
+++ b/lib/dt-core.c
@@ -906,7 +906,7 @@ DEFUN struct dt_dtdur_s
dt_strpdtdur(const char *str, char **ep)
{
/* at the moment we allow only one format */
- struct dt_dtdur_s res = {.durtyp = (dt_dtdurtyp_t)DT_DURUNK};
+ struct dt_dtdur_s res = {(dt_dtdurtyp_t)DT_DURUNK};
const char *sp;
long int tmp;
@@ -1503,7 +1503,7 @@ dt_dtadd(struct dt_dt_s d, struct dt_dtdur_s dur)
DEFUN struct dt_dtdur_s
dt_dtdiff(dt_dtdurtyp_t tgttyp, struct dt_dt_s d1, struct dt_dt_s d2)
{
- struct dt_dtdur_s res = {.durtyp = (dt_dtdurtyp_t)DT_DURUNK};
+ struct dt_dtdur_s res = {(dt_dtdurtyp_t)DT_DURUNK};
int dt = 0;
if (!dt_sandwich_only_d_p(d1) && !dt_sandwich_only_d_p(d2)) {
diff --git a/src/dround.c b/src/dround.c
index 623aaf3..1142164 100644
--- a/src/dround.c
+++ b/src/dround.c
@@ -500,7 +500,7 @@ dt_io_strpdtrnd(struct __strpdtdur_st_s *st, const char *str)
char *sp = NULL;
struct strpd_s d = strpd_initialiser();
struct dt_spec_s s = spec_initialiser();
- struct dt_dtdur_s payload = {.durtyp = (dt_dtdurtyp_t)DT_DURUNK};
+ struct dt_dtdur_s payload = {(dt_dtdurtyp_t)DT_DURUNK};
bool negp = false;
bool coclp = true;
@@ -525,12 +525,19 @@ dt_io_strpdtrnd(struct __strpdtdur_st_s *st, const char *str)
s.spfl = DT_SPFL_S_WDAY;
s.abbr = DT_SPMOD_NORM;
if (__strpd_card(&d, str, s, &sp) >= 0) {
+#if defined HAVE_ANON_STRUCTS_INIT
payload.d = (struct dt_ddur_s){
DT_DURYMCW,
.neg = negp,
.cocl = coclp,
.ymcw.w = d.w,
};
+#else
+ payload.d.durtyp = DT_DURYMCW;
+ payload.d.neg = negp;
+ payload.d.cocl = coclp;
+ payload.d.ymcw.w = d.w;
+#endif
goto out;
}
@@ -538,11 +545,17 @@ dt_io_strpdtrnd(struct __strpdtdur_st_s *st, const char *str)
s.spfl = DT_SPFL_S_MON;
s.abbr = DT_SPMOD_NORM;
if (__strpd_card(&d, str, s, &sp) >= 0) {
+#if defined HAVE_ANON_STRUCTS_INIT
payload.d = (struct dt_ddur_s){
DT_DURYMD,
.neg = negp,
.ymd.m = d.m,
};
+#else
+ payload.d.durtyp = DT_DURYMD;
+ payload.d.neg = negp;
+ payload.d.ymd.m = d.m;
+#endif
goto out;
}
diff --git a/src/dseq.c b/src/dseq.c
index b4bf405..9dc58f1 100644
--- a/src/dseq.c
+++ b/src/dseq.c
@@ -426,29 +426,22 @@ __fixup_fst(struct dseq_clo_s *clo)
static struct dt_dtdur_s
tseq_guess_ite(struct dt_t_s beg, struct dt_t_s end)
{
+ struct dt_dtdur_s res = {0};
+
if (beg.hms.h != end.hms.h &&
- beg.hms.m == 0 && end.hms.m == 0&&
+ beg.hms.m == 0 && end.hms.m == 0 &&
beg.hms.s == 0 && end.hms.s == 0) {
- if (beg.u < end.u) {
- return (struct dt_dtdur_s){DT_DURH, .dv = 1};
- } else {
- return (struct dt_dtdur_s){DT_DURH, .dv = -1};
- }
+ res.durtyp = DT_DURH;
+ res.dv = (beg.u < end.u) ? 1 : -1;
} else if (beg.hms.m != end.hms.m &&
beg.hms.s == 0 && end.hms.s == 0) {
- if (beg.u < end.u) {
- return (struct dt_dtdur_s){DT_DURM, .dv = 1};
- } else {
- return (struct dt_dtdur_s){DT_DURM, .dv = -1};
- }
+ res.durtyp = DT_DURM;
+ res.dv = (beg.u < end.u) ? 1 : -1;
} else {
- if (beg.u < end.u) {
- return (struct dt_dtdur_s){DT_DURS, .dv = 1};
- } else {
- return (struct dt_dtdur_s){DT_DURS, .dv = -1};
- }
+ res.durtyp = DT_DURS;
+ res.dv = (beg.u < end.u) ? 1 : -1;
}
- /* no reach */
+ return res;
}
diff --git a/test/dtcore-add.c b/test/dtcore-add.c
index bfdea28..ff0c49e 100644
--- a/test/dtcore-add.c
+++ b/test/dtcore-add.c
@@ -67,7 +67,7 @@ add_t_only(void)
{
static const char str[] = "12:34:56";
struct dt_dt_s d;
- struct dt_dtdur_s dur = {.durtyp = (dt_dtdurtyp_t)DT_DURUNK};
+ struct dt_dtdur_s dur = {(dt_dtdurtyp_t)DT_DURUNK};
int res = 0;
/* 2012-03-28 (using no format) */
@@ -166,7 +166,7 @@ dt_add_t(void)
{
static const char str[] = "2012-03-28T23:12:01";
struct dt_dt_s d;
- struct dt_dtdur_s dur = {.durtyp = (dt_dtdurtyp_t)DT_DURUNK};
+ struct dt_dtdur_s dur = {(dt_dtdurtyp_t)DT_DURUNK};
int res = 0;
fprintf(stderr, "testing %s +1h ...\n", str);
@@ -221,7 +221,7 @@ dt_add_dt(void)
{
static const char str[] = "2012-03-28T23:55:55";
struct dt_dt_s d;
- struct dt_dtdur_s dur = {.durtyp = (dt_dtdurtyp_t)DT_DURUNK};
+ struct dt_dtdur_s dur = {(dt_dtdurtyp_t)DT_DURUNK};
int res = 0;
fprintf(stderr, "testing %s +1d1h ...\n", str);
--
1.8.4.5

View File

@ -1,107 +0,0 @@
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

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3eb0b1dbf4519c86bc890a12c78cc85eae2cc10c20ff894a90ed55140efeee7a
size 593700

3
dateutils-0.3.4.tar.xz Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1fe71d6f05705565612a61de848071bfb39fb604695c8052e8d7959c5f34a714
size 593016

View File

@ -1,3 +1,17 @@
-------------------------------------------------------------------
Mon Aug 31 08:39:17 UTC 2015 - sweet_f_a@gmx.de
- bump version 0.3.4, this is a bugfix release.
* Bugfixes:
- bug/39, MacOSX endianness detection
- bug/38, ddiff day-only durations on date/times
- dadd +2m bug is fixed, regression
* See info page examples and/or README.
- remove patches (upstream applied):
* 0001-fix-build-for-compilers-without-anonymous-struct-ini.patch
* 0002-fix-dateadd-unix-timestamp-bug.patch
------------------------------------------------------------------- -------------------------------------------------------------------
Sun Aug 2 15:36:05 UTC 2015 - mpluskal@suse.com Sun Aug 2 15:36:05 UTC 2015 - mpluskal@suse.com

View File

@ -16,7 +16,7 @@
# #
%define xversion 0.3.3 %define xversion 0.3.4
%define have_octave 0 %define have_octave 0
@ -39,15 +39,13 @@
%endif %endif
Name: dateutils Name: dateutils
Version: 0.3.3 Version: 0.3.4
Release: 0 Release: 0
Summary: Nifty command line date and time utilities Summary: Nifty command line date and time utilities
License: BSD-3-Clause License: BSD-3-Clause
Group: Productivity/Text/Utilities Group: Productivity/Text/Utilities
Url: https://github.com/hroptatyr/dateutils/ Url: https://github.com/hroptatyr/dateutils/
Source: https://bitbucket.org/hroptatyr/dateutils/downloads/%{name}-%{version}.tar.xz Source: https://bitbucket.org/hroptatyr/dateutils/downloads/%{name}-%{version}.tar.xz
Patch1: 0001-fix-build-for-compilers-without-anonymous-struct-ini.patch
Patch2: 0002-fix-dateadd-unix-timestamp-bug.patch
BuildRequires: pkgconfig BuildRequires: pkgconfig
BuildRequires: xz BuildRequires: xz
%if 0%{?suse_version} %if 0%{?suse_version}
@ -81,8 +79,6 @@ Dateutils can be used from within matlab or ocatave.
%prep %prep
%setup -q -n %{name}-%{xversion} %setup -q -n %{name}-%{xversion}
%patch1 -p1
%patch2 -p1
%build %build
%configure \ %configure \