Skip to content

Commit 2bb4d82

Browse files
author
Derick Rethans
committed
- Fixed bug #35143 (gettimeofday() ignores current time zone).
- Fixed tests due to class constants patch.
1 parent 4020933 commit 2bb4d82

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77
- Fixed bug #35273 (Error in mapping soap - java types). (Dmitry)
88
- Fixed bug #35243 (php_mblen() crashes when compiled with thread-safety
99
on Linux). (Patch: shulmanb at il dot ibm dot com, Jani)
10+
- Fixed bug #35143 (gettimeofday() ignores current time zone). (Derick)
1011
- Fixed bug #33153 (crash in mssql_next result). (Frank)
1112
- Fixed bug #33963 (mssql_bind() fails on input parameters). (Frank)
1213
- Fixed bug #33201 (Crash when fetching some data types). (Frank)

ext/date/php_date.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static char* guess_timezone(TSRMLS_D)
363363
return "UTC";
364364
}
365365

366-
static timelib_tzinfo *get_timezone_info(TSRMLS_D)
366+
PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D)
367367
{
368368
char *tz;
369369
timelib_tzinfo *tzi;

ext/date/php_date.h

+1
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ PHPAPI char *php_format_date(char *format, int format_len, time_t ts, int localt
9999

100100
/* Mechanism to set new TZ database */
101101
PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
102+
PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D);
102103

103104
#endif /* PHP_DATE_H */

ext/date/tests/bug35143.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #35143 (gettimeofday() ignores current time zone)
3+
--FILE--
4+
<?php
5+
date_default_timezone_set("UTC");
6+
7+
var_dump(date_default_timezone_get());
8+
var_dump(gettimeofday());
9+
?>
10+
--EXPECTF--
11+
string(3) "UTC"
12+
array(4) {
13+
["sec"]=>
14+
int(%d)
15+
["usec"]=>
16+
int(%d)
17+
["minuteswest"]=>
18+
int(0)
19+
["dsttime"]=>
20+
int(0)
21+
}

ext/date/tests/date_create-2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ date_create() function [2]
66
<?php
77
date_default_timezone_set("GMT");
88
$d = date_create("2005-07-18 22:10:00 +0400");
9-
echo $d->format(DATE_RFC822), "\n";
9+
echo $d->format(date::RFC822), "\n";
1010
?>
1111
--EXPECT--
1212
Mon, 18 Jul 2005 22:10:00 GMT+0400

ext/date/tests/date_modify-1.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ date_modify() function [1]
66
<?php
77
date_default_timezone_set("Pacific/Kwajalein");
88
$ts = date_create("Thu Aug 19 1993 23:59:59");
9-
echo date_format($ts, DATE_RFC822), "\n";
9+
echo date_format($ts, date::RFC822), "\n";
1010
$ts->modify("+1 second");
11-
echo date_format($ts, DATE_RFC822), "\n";
11+
echo date_format($ts, date::RFC822), "\n";
1212

1313
date_default_timezone_set("Europe/Amsterdam");
1414
$ts = date_create("Sun Mar 27 01:59:59 2005");
15-
echo date_format($ts, DATE_RFC822), "\n";
15+
echo date_format($ts, date::RFC822), "\n";
1616
$ts->modify("+1 second");
17-
echo date_format($ts, DATE_RFC822), "\n";
17+
echo date_format($ts, date::RFC822), "\n";
1818

1919
$ts = date_create("Sun Oct 30 01:59:59 2005");
20-
echo date_format($ts, DATE_RFC822), "\n";
20+
echo date_format($ts, date::RFC822), "\n";
2121
$ts->modify("+ 1 hour 1 second");
22-
echo date_format($ts, DATE_RFC822), "\n";
22+
echo date_format($ts, date::RFC822), "\n";
2323
?>
2424
--EXPECT--
2525
Thu, 19 Aug 1993 23:59:59 KWAT

ext/date/tests/date_modify-2.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ date_modify() function [2]
66
<?php
77
date_default_timezone_set("GMT");
88
$d = date_create("2005-07-18 22:10:00 +0400");
9-
echo date_format($d, DATE_RFC822), "\n";
9+
echo date_format($d, date::RFC822), "\n";
1010
date_modify($d, "+1 hour");
11-
echo date_format($d, DATE_RFC822), "\n";
11+
echo date_format($d, date::RFC822), "\n";
1212
?>
1313
--EXPECT--
1414
Mon, 18 Jul 2005 22:10:00 GMT+0400

ext/standard/microtime.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <errno.h>
4444

4545
#include "microtime.h"
46+
#include "ext/date/php_date.h"
4647

4748
#define NUL '\0'
4849
#define MICRO_IN_SEC 1000000.00
@@ -68,15 +69,18 @@ static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)
6869
}
6970

7071
if (mode) {
72+
timelib_time_offset *offset;
73+
74+
offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info(TSRMLS_C));
75+
7176
array_init(return_value);
7277
add_assoc_long(return_value, "sec", tp.tv_sec);
7378
add_assoc_long(return_value, "usec", tp.tv_usec);
74-
#ifdef PHP_WIN32
75-
add_assoc_long(return_value, "minuteswest", tz.tz_minuteswest/SEC_IN_MIN);
76-
#else
77-
add_assoc_long(return_value, "minuteswest", tz.tz_minuteswest);
78-
#endif
79-
add_assoc_long(return_value, "dsttime", tz.tz_dsttime);
79+
80+
add_assoc_long(return_value, "minuteswest", -offset->offset / SEC_IN_MIN);
81+
add_assoc_long(return_value, "dsttime", offset->is_dst);
82+
83+
timelib_time_offset_dtor(offset);
8084
} else {
8185
char ret[100];
8286

0 commit comments

Comments
 (0)