Skip to content

Commit 822ca45

Browse files
committed
Merge in changes in timelib 2016.01
1 parent fa548e5 commit 822ca45

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

ext/date/lib/interval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
7070
rt->i += dst_m_corr;
7171
}
7272

73-
rt->days = abs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));
73+
rt->days = fabs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));
7474

7575
timelib_do_rel_normalize(rt->invert ? one : two, rt);
7676

ext/date/lib/parse_date.re

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,11 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
18121812
{ \
18131813
add_pbf_error(s, "Unexpected data found.", string, begin); \
18141814
}
1815+
#define TIMELIB_CHECK_SIGNED_NUMBER \
1816+
if (strchr("-0123456789", *ptr) == NULL) \
1817+
{ \
1818+
add_pbf_error(s, "Unexpected data found.", string, begin); \
1819+
}
18151820

18161821
static void timelib_time_reset_fields(timelib_time *time)
18171822
{
@@ -2016,7 +2021,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
20162021
timelib_eat_spaces((char **) &ptr);
20172022
break;
20182023
case 'U': /* epoch seconds */
2019-
TIMELIB_CHECK_NUMBER;
2024+
TIMELIB_CHECK_SIGNED_NUMBER;
20202025
TIMELIB_HAVE_RELATIVE();
20212026
tmp = timelib_get_unsigned_nr((char **) &ptr, 24);
20222027
s->time->y = 1970;

ext/date/lib/timelib.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ timelib_time* timelib_time_clone(timelib_time *orig)
6565
return tmp;
6666
}
6767

68+
int timelib_time_compare(timelib_time *t1, timelib_time *t2)
69+
{
70+
if (t1->sse == t2->sse) {
71+
if (t1->f == t2->f) {
72+
return 0;
73+
}
74+
75+
if (t1->sse < 0) {
76+
return (t1->f < t2->f) ? 1 : -1;
77+
} else {
78+
return (t1->f < t2->f) ? -1 : 1;
79+
}
80+
}
81+
82+
return (t1->sse < t2->sse) ? -1 : 1;
83+
}
84+
6885
timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *rel)
6986
{
7087
timelib_rel_time *tmp = timelib_rel_time_ctor();

ext/date/lib/timelib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ timelib_time* timelib_time_ctor(void);
138138
void timelib_time_set_option(timelib_time* tm, int option, void* option_value);
139139
void timelib_time_dtor(timelib_time* t);
140140
timelib_time* timelib_time_clone(timelib_time* orig);
141+
int timelib_time_compare(timelib_time *t1, timelib_time *t2);
141142

142143
timelib_time_offset* timelib_time_offset_ctor(void);
143144
void timelib_time_offset_dtor(timelib_time_offset* t);

0 commit comments

Comments
 (0)