summaryrefslogtreecommitdiff
path: root/ext/date/php_date.c
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 /ext/date/php_date.c
parentbab0b99f376dac9170ac81382a5ed526938d595a (diff)
downloadphp-git-b224e7426713befd7449117afd68355231f9077e.tar.gz
Fixed bug #72096 Swatch time value incorrect for dates before 1970
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r--ext/date/php_date.c18
1 files changed, 10 insertions, 8 deletions
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 */