diff options
author | Derick Rethans <github@derickrethans.nl> | 2016-10-05 11:24:15 -0400 |
---|---|---|
committer | Derick Rethans <github@derickrethans.nl> | 2016-10-05 15:03:06 -0400 |
commit | 55626549d81d0feadb1d160be78fcf2b898a48cc (patch) | |
tree | a00c6239804f2ad68ccc3470e63e83eb18f7897f /ext/date/lib/tm2unixtime.c | |
parent | d5b77d66626b138a83b6c0d16f746893fefa29ee (diff) | |
download | php-git-microseconds.tar.gz |
Improve support for microseconds with Date/Timemicroseconds
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.
Diffstat (limited to 'ext/date/lib/tm2unixtime.c')
-rw-r--r-- | ext/date/lib/tm2unixtime.c | 15 |
1 files changed, 15 insertions, 0 deletions
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; |