From 55626549d81d0feadb1d160be78fcf2b898a48cc Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 5 Oct 2016 11:24:15 -0400 Subject: Improve support for microseconds with Date/Time It fixes several bugs: - Fixed bug #45554 (Inconsistent behavior of the u format char). - Fixed bug #48225 (DateTime parser doesn't set microseconds for "now"). - Fixed bug #52514 (microseconds are missing in DateTime class). - Fixed bug #52519 (microseconds in DateInterval are missing). - Fixed bug #68506 (General DateTime improvments needed for microseconds to become useful). - Fixed bug #73109 (timelib_meridian doesn't parse dots correctly). - Fixed bug #73247 (DateTime constructor does not initialise microseconds property). It also updates timelib to 2016.04, and updates a data mapping file, which causes changes to the volatile abbreviations tests. --- ext/date/lib/tm2unixtime.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ext/date/lib/tm2unixtime.c') diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c index 57e0cef1be..0d65006de4 100644 --- a/ext/date/lib/tm2unixtime.c +++ b/ext/date/lib/tm2unixtime.c @@ -32,6 +32,18 @@ static int month_tab[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 24 static int days_in_month_leap[13] = { 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static int days_in_month[13] = { 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +static void do_range_limit_fraction(double *fraction, timelib_sll *seconds) +{ + if (*fraction < 0) { + *fraction += 1; + *seconds -= 1; + } + if (*fraction > 1) { + *fraction -= 1; + *seconds += 1; + } +} + static void do_range_limit(timelib_sll start, timelib_sll end, timelib_sll adj, timelib_sll *a, timelib_sll *b) { if (*a < start) { @@ -192,6 +204,7 @@ void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt) void timelib_do_normalize(timelib_time* time) { + if (time->s != TIMELIB_UNSET) do_range_limit_fraction(&time->f, &time->s); if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i); if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h); if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d); @@ -209,6 +222,8 @@ static void do_adjust_relative(timelib_time* time) timelib_do_normalize(time); if (time->have_relative) { + time->f += time->relative.f; + time->s += time->relative.s; time->i += time->relative.i; time->h += time->relative.h; -- cgit v1.2.1