Skip to content

Commit

Permalink
Fixed date/diff where the difference in hour is less than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Nov 18, 2021
1 parent 5ab2749 commit e4679ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ext/date/lib/timelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec)

void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h)
{
if (hour > 0) {
if (hour >= 0) {
*h = ((double)hour + (double)min / 60 + (double)sec / 3600);
} else {
*h = ((double)hour - (double)min / 60 - (double)sec / 3600);
Expand All @@ -209,7 +209,7 @@ void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h)

void timelib_hmsf_to_decimal_hour(int hour, int min, int sec, int us, double *h)
{
if (hour > 0) {
if (hour >= 0) {
*h = ((double)hour + (double)min / MINS_PER_HOUR + (double)sec / SECS_PER_HOUR) + (double)us / USECS_PER_HOUR;
} else {
*h = ((double)hour - (double)min / MINS_PER_HOUR - (double)sec / SECS_PER_HOUR) - (double)us / USECS_PER_HOUR;
Expand Down
6 changes: 3 additions & 3 deletions ext/date/lib/timelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
# include "timelib_config.h"
#endif

#define TIMELIB_VERSION 202110
#define TIMELIB_EXTENDED_VERSION 20211001
#define TIMELIB_ASCII_VERSION "2021.10"
#define TIMELIB_VERSION 202111
#define TIMELIB_EXTENDED_VERSION 20211101
#define TIMELIB_ASCII_VERSION "2021.11"

#include <stdlib.h>
#include <stdbool.h>
Expand Down
7 changes: 7 additions & 0 deletions ext/date/tests/bug81458.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ $second = new DateTime('2018-07-02 00:00:00.000000 America/Toronto');

var_dump($first->diff($second)->days);
var_dump($first->diff($second)->d);

date_default_timezone_set('UTC');
$a = new DateTime('2018-12-01 00:00');
$b = new DateTime('2018-12-02 00:01');

var_dump($a->diff($b)->days);
?>
--EXPECT--
int(1)
int(1)
int(1)

1 comment on commit e4679ef

@dstogov
Copy link
Member

@dstogov dstogov commented on e4679ef Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symfony unit tests are failed at https://dev.azure.com/phpazuredevops/PHP/_build/results?buildId=21620&view=logs&j=55323bc0-ded7-5cf3-3d38-be3edc0baeb7&t=f80d6aea-40f2-5bf8-d445-b86523fdd0f3

Testing /home/vsts/work/1/s/symfony/src/Symfony/Component/VarDumper
.............../home/vsts/work/1/s/ext/date/lib/interval.c:70:44: runtime error: signed integer overflow: -7200 + -9223372036854775808 cannot be represented in type 'long long int'
    #0 0x5619ec350b56 in timelib_diff /home/vsts/work/1/s/ext/date/lib/interval.c:70
    #1 0x5619ec248237 in zif_date_diff /home/vsts/work/1/s/ext/date/php_date.c:3383
    #2 0x5619ee4afd42 in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER /home/vsts/work/1/s/Zend/zend_vm_execute.h:1870
    #3 0x5619ee7685b9 in execute_ex /home/vsts/work/1/s/Zend/zend_vm_execute.h:54555
    #4 0x5619ee7852e5 in zend_execute /home/vsts/work/1/s/Zend/zend_vm_execute.h:58882
    #5 0x5619ee389fbd in zend_execute_scripts /home/vsts/work/1/s/Zend/zend.c:1761
    #6 0x5619ee020aa5 in php_execute_script /home/vsts/work/1/s/main/main.c:2534
    #7 0x5619eeb5f294 in do_cli /home/vsts/work/1/s/sapi/cli/php_cli.c:965
    #8 0x5619eeb63207 in main /home/vsts/work/1/s/sapi/cli/php_cli.c:1367
    #9 0x7f2646aa20b2 in __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #10 0x5619ec209b1d in _start (/usr/bin/php+0x3e09b1d)

Please sign in to comment.