Skip to content

Commit b0ce642

Browse files
committed
Merge branch 'issue69-fraction-normalise' into v2017
2 parents 0e1ee18 + e26f743 commit b0ce642

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ CFLAGS=-Wdeclaration-after-statement ${FLAGS}
88

99
CPPFLAGS=${FLAGS}
1010

11-
LDFLAGS=-lm -fsanitize=undefined -l:libubsan.so.1
11+
LDFLAGS=-lm -fsanitize=undefined -l:libubsan.so
1212

1313
TEST_LDFLAGS=-lCppUTest
1414

15-
CC=gcc-8
15+
CC=gcc
1616
MANUAL_TESTS=tests/tester-parse-interval \
1717
tests/tester-parse-tz tests/tester-iso-week tests/test-abbr-to-id \
1818
tests/enumerate-timezones tests/date_from_isodate

tests/c/issues.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "CppUTest/TestHarness.h"
22
#include "timelib.h"
3+
#include <string.h>
34

45
TEST_GROUP(issues)
56
{
@@ -280,3 +281,36 @@ TEST(issues, issue0051_test2)
280281
timelib_rel_time_dtor(diff);
281282
timelib_tzinfo_dtor(tzi);
282283
}
284+
285+
TEST(issues, issue0069)
286+
{
287+
char str1[] = "2019-10-14T15:08:23.123+02:00";
288+
char str2[] = "-50000 msec";
289+
timelib_time *t1 = timelib_strtotime(str1, sizeof(str1), NULL, timelib_builtin_db(), timelib_parse_tzfile);
290+
timelib_time *t2 = timelib_strtotime(str2, sizeof(str2), NULL, timelib_builtin_db(), timelib_parse_tzfile);
291+
int dummy_error;
292+
timelib_tzinfo *tzi;
293+
294+
tzi = timelib_parse_tzfile((char*) "UTC", timelib_builtin_db(), &dummy_error);
295+
296+
timelib_update_ts(t1, tzi);
297+
298+
memcpy(&t1->relative, &t2->relative, sizeof(timelib_rel_time));
299+
t1->have_relative = 1;
300+
t1->sse_uptodate = 0;
301+
302+
timelib_update_ts(t1, NULL);
303+
timelib_update_from_sse(t1);
304+
t1->have_relative = 0;
305+
306+
memset(&t1->relative, 0, sizeof(timelib_rel_time));
307+
308+
LONGS_EQUAL(123000, t1->us);
309+
LONGS_EQUAL(33, t1->s);
310+
LONGS_EQUAL( 7, t1->i);
311+
LONGS_EQUAL(15, t1->h);
312+
313+
timelib_time_dtor(t1);
314+
timelib_time_dtor(t2);
315+
timelib_tzinfo_dtor(tzi);
316+
}

tm2unixtime.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 24
3333
static int days_in_month_leap[13] = { 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3434
static int days_in_month[13] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3535

36-
static void do_range_limit_fraction(timelib_sll *fraction, timelib_sll *seconds)
37-
{
38-
if (*fraction < 0) {
39-
*fraction += 1000000;
40-
*seconds -= 1;
41-
}
42-
if (*fraction >= 1000000) {
43-
*fraction -= 1000000;
44-
*seconds += 1;
45-
}
46-
}
47-
4836
static void do_range_limit(timelib_sll start, timelib_sll end, timelib_sll adj, timelib_sll *a, timelib_sll *b)
4937
{
5038
if (*a < start) {
@@ -194,7 +182,7 @@ static void do_adjust_for_weekday(timelib_time* time)
194182

195183
void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
196184
{
197-
do_range_limit_fraction(&rt->us, &rt->s);
185+
do_range_limit(0, 1000000, 1000000, &rt->us, &rt->s);
198186
do_range_limit(0, 60, 60, &rt->s, &rt->i);
199187
do_range_limit(0, 60, 60, &rt->i, &rt->h);
200188
do_range_limit(0, 24, 24, &rt->h, &rt->d);
@@ -234,7 +222,7 @@ static void magic_date_calc(timelib_time *time)
234222

235223
void timelib_do_normalize(timelib_time* time)
236224
{
237-
if (time->us != TIMELIB_UNSET) do_range_limit_fraction(&time->us, &time->s);
225+
if (time->us != TIMELIB_UNSET) do_range_limit(0, 1000000, 1000000, &time->us, &time->s);
238226
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i);
239227
if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h);
240228
if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d);

0 commit comments

Comments
 (0)