summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormcq8 <php@mcq8.be>2016-06-03 19:28:20 +0000
committerNikita Popov <nikita.ppv@gmail.com>2017-03-09 16:44:02 +0100
commitb224e7426713befd7449117afd68355231f9077e (patch)
tree9c198570b6c6e0f42373cd4d7993f24791c2972a
parentbab0b99f376dac9170ac81382a5ed526938d595a (diff)
downloadphp-git-b224e7426713befd7449117afd68355231f9077e.tar.gz
Fixed bug #72096 Swatch time value incorrect for dates before 1970
-rw-r--r--NEWS3
-rw-r--r--ext/date/php_date.c18
-rw-r--r--ext/date/tests/bug72096.phpt34
3 files changed, 47 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index bb94fce46b..1498b60978 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2017 PHP 7.0.18
+- Date:
+ . Fixed bug #72096 (Swatch time value incorrect for dates before 1970). (mcq8)
+
- DOM:
. Fixed bug #74004 (LIBXML_NOWARNING flag ingnored on loadHTML*).
(somedaysummer)
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 8f81117d11..630354cc7a 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1141,11 +1141,12 @@ static zend_string *date_format(char *format, size_t format_len, timelib_time *t
case 'a': length = slprintf(buffer, 32, "%s", t->h >= 12 ? "pm" : "am"); break;
case 'A': length = slprintf(buffer, 32, "%s", t->h >= 12 ? "PM" : "AM"); break;
case 'B': {
- int retval = (((((long)t->sse)-(((long)t->sse) - ((((long)t->sse) % 86400) + 3600))) * 10) / 864);
- while (retval < 0) {
- retval += 1000;
+ int retval = ((((long)t->sse)-(((long)t->sse) - ((((long)t->sse) % 86400) + 3600))) * 10);
+ if (retval < 0) {
+ retval += 864000;
}
- retval = retval % 1000;
+ /* Make sure to do this on a positive int to avoid rounding errors */
+ retval = (retval / 864) % 1000;
length = slprintf(buffer, 32, "%03d", retval);
break;
}
@@ -1336,11 +1337,12 @@ PHPAPI int php_idate(char format, time_t ts, int localtime)
/* Swatch Beat a.k.a. Internet Time */
case 'B':
- retval = (((((long)t->sse)-(((long)t->sse) - ((((long)t->sse) % 86400) + 3600))) * 10) / 864);
- while (retval < 0) {
- retval += 1000;
+ retval = ((((long)t->sse)-(((long)t->sse) - ((((long)t->sse) % 86400) + 3600))) * 10);
+ if (retval < 0) {
+ retval += 864000;
}
- retval = retval % 1000;
+ /* Make sure to do this on a positive int to avoid rounding errors */
+ retval = (retval / 864) % 1000;
break;
/* time */
diff --git a/ext/date/tests/bug72096.phpt b/ext/date/tests/bug72096.phpt
new file mode 100644
index 0000000000..1a4a219287
--- /dev/null
+++ b/ext/date/tests/bug72096.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #72096: Swatch time value incorrect for dates before 1970
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+for ($unix = 1461283200; $unix <= 1461369600; $unix += 8000) {
+ echo "Time:", gmdate('Y-m-d H:i:s = B', $unix), PHP_EOL;
+ echo "Time:", gmdate('Y-m-d H:i:s = B', $unix - 82 * 365 * 24 * 3600), PHP_EOL;
+}
+?>
+--EXPECT--
+Time:2016-04-22 00:00:00 = 041
+Time:1934-05-13 00:00:00 = 041
+Time:2016-04-22 02:13:20 = 134
+Time:1934-05-13 02:13:20 = 134
+Time:2016-04-22 04:26:40 = 226
+Time:1934-05-13 04:26:40 = 226
+Time:2016-04-22 06:40:00 = 319
+Time:1934-05-13 06:40:00 = 319
+Time:2016-04-22 08:53:20 = 412
+Time:1934-05-13 08:53:20 = 412
+Time:2016-04-22 11:06:40 = 504
+Time:1934-05-13 11:06:40 = 504
+Time:2016-04-22 13:20:00 = 597
+Time:1934-05-13 13:20:00 = 597
+Time:2016-04-22 15:33:20 = 689
+Time:1934-05-13 15:33:20 = 689
+Time:2016-04-22 17:46:40 = 782
+Time:1934-05-13 17:46:40 = 782
+Time:2016-04-22 20:00:00 = 875
+Time:1934-05-13 20:00:00 = 875
+Time:2016-04-22 22:13:20 = 967
+Time:1934-05-13 22:13:20 = 967