Skip to content

Commit e4679ef

Browse files
committed
Fixed date/diff where the difference in hour is less than 1
1 parent 5ab2749 commit e4679ef

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

ext/date/lib/timelib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec)
200200

201201
void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h)
202202
{
203-
if (hour > 0) {
203+
if (hour >= 0) {
204204
*h = ((double)hour + (double)min / 60 + (double)sec / 3600);
205205
} else {
206206
*h = ((double)hour - (double)min / 60 - (double)sec / 3600);
@@ -209,7 +209,7 @@ void timelib_hms_to_decimal_hour(int hour, int min, int sec, double *h)
209209

210210
void timelib_hmsf_to_decimal_hour(int hour, int min, int sec, int us, double *h)
211211
{
212-
if (hour > 0) {
212+
if (hour >= 0) {
213213
*h = ((double)hour + (double)min / MINS_PER_HOUR + (double)sec / SECS_PER_HOUR) + (double)us / USECS_PER_HOUR;
214214
} else {
215215
*h = ((double)hour - (double)min / MINS_PER_HOUR - (double)sec / SECS_PER_HOUR) - (double)us / USECS_PER_HOUR;

ext/date/lib/timelib.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
# include "timelib_config.h"
3131
#endif
3232

33-
#define TIMELIB_VERSION 202110
34-
#define TIMELIB_EXTENDED_VERSION 20211001
35-
#define TIMELIB_ASCII_VERSION "2021.10"
33+
#define TIMELIB_VERSION 202111
34+
#define TIMELIB_EXTENDED_VERSION 20211101
35+
#define TIMELIB_ASCII_VERSION "2021.11"
3636

3737
#include <stdlib.h>
3838
#include <stdbool.h>

ext/date/tests/bug81458.phpt

+7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ $second = new DateTime('2018-07-02 00:00:00.000000 America/Toronto');
77

88
var_dump($first->diff($second)->days);
99
var_dump($first->diff($second)->d);
10+
11+
date_default_timezone_set('UTC');
12+
$a = new DateTime('2018-12-01 00:00');
13+
$b = new DateTime('2018-12-02 00:01');
14+
15+
var_dump($a->diff($b)->days);
1016
?>
1117
--EXPECT--
1218
int(1)
1319
int(1)
20+
int(1)

0 commit comments

Comments
 (0)