]> granicus.if.org Git - php/commitdiff
Merge in changes in timelib 2016.01
authorDerick Rethans <github@derickrethans.nl>
Fri, 29 Jan 2016 14:21:55 +0000 (15:21 +0100)
committerDerick Rethans <github@derickrethans.nl>
Fri, 29 Jan 2016 14:21:55 +0000 (15:21 +0100)
ext/date/lib/interval.c
ext/date/lib/parse_date.re
ext/date/lib/timelib.c
ext/date/lib/timelib.h

index 6a3403fc3e6d70b155e5fc46d3376a44f8fc5ca2..9c1cc3b273d8059d2fe57d653d0f451d3f4ca45e 100644 (file)
@@ -70,7 +70,7 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
                rt->i += dst_m_corr;
        }
 
-       rt->days = abs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));
+       rt->days = fabs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));
 
        timelib_do_rel_normalize(rt->invert ? one : two, rt);
 
index 3ff00bec3e74c82299ae50be22904b17a9a18c61..3d4cf6bb61fa28147acaf831185fcdd23fdb8e17 100644 (file)
@@ -1812,6 +1812,11 @@ timelib_time* timelib_strtotime(char *s, size_t len, struct timelib_error_contai
                {                                                              \
                        add_pbf_error(s, "Unexpected data found.", string, begin); \
                }
+#define TIMELIB_CHECK_SIGNED_NUMBER                                    \
+               if (strchr("-0123456789", *ptr) == NULL)                       \
+               {                                                              \
+                       add_pbf_error(s, "Unexpected data found.", string, begin); \
+               }
 
 static void timelib_time_reset_fields(timelib_time *time)
 {
@@ -2016,7 +2021,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, size_t len,
                                timelib_eat_spaces((char **) &ptr);
                                break;
                        case 'U': /* epoch seconds */
-                               TIMELIB_CHECK_NUMBER;
+                               TIMELIB_CHECK_SIGNED_NUMBER;
                                TIMELIB_HAVE_RELATIVE();
                                tmp = timelib_get_unsigned_nr((char **) &ptr, 24);
                                s->time->y = 1970;
index 73cdfa2d8594d9c1a3f0b24a5c0354194565c03e..b938d9f99834603a49c6b02700a17c6a8ebec01f 100644 (file)
@@ -65,6 +65,23 @@ timelib_time* timelib_time_clone(timelib_time *orig)
        return tmp;
 }
 
+int timelib_time_compare(timelib_time *t1, timelib_time *t2)
+{
+       if (t1->sse == t2->sse) {
+               if (t1->f == t2->f) {
+                       return 0;
+               }
+
+               if (t1->sse < 0) {
+                       return (t1->f < t2->f) ? 1 : -1;
+               } else {
+                       return (t1->f < t2->f) ? -1 : 1;
+               }
+       }
+
+       return (t1->sse < t2->sse) ? -1 : 1;
+}
+
 timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *rel)
 {
        timelib_rel_time *tmp = timelib_rel_time_ctor();
index 125b8b21ad1d82c8a100ee80c3a88813daa0eaea..fe1069bddea18c6cdf6730ad72f37be51e85b7e4 100644 (file)
@@ -138,6 +138,7 @@ timelib_time* timelib_time_ctor(void);
 void timelib_time_set_option(timelib_time* tm, int option, void* option_value);
 void timelib_time_dtor(timelib_time* t);
 timelib_time* timelib_time_clone(timelib_time* orig);
+int timelib_time_compare(timelib_time *t1, timelib_time *t2);
 
 timelib_time_offset* timelib_time_offset_ctor(void);
 void timelib_time_offset_dtor(timelib_time_offset* t);