Skip to content

Commit 932c952

Browse files
committed
Merge branch 'PHP-7.0'
2 parents cef8d93 + c572968 commit 932c952

File tree

4 files changed

+81
-32
lines changed

4 files changed

+81
-32
lines changed

ext/date/lib/timelib.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -310,33 +310,33 @@ void timelib_dump_rel_time(timelib_rel_time *d)
310310

311311
timelib_long timelib_parse_tz_cor(char **ptr)
312312
{
313-
char *begin = *ptr, *end;
314-
timelib_long tmp;
315-
316-
while (isdigit(**ptr) || **ptr == ':') {
317-
++*ptr;
318-
}
319-
end = *ptr;
320-
switch (end - begin) {
321-
case 1:
322-
case 2:
323-
return HOUR(strtol(begin, NULL, 10));
324-
break;
325-
case 3:
326-
case 4:
327-
if (begin[1] == ':') {
328-
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);
329-
return tmp;
330-
} else if (begin[2] == ':') {
331-
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
332-
return tmp;
333-
} else {
334-
tmp = strtol(begin, NULL, 10);
335-
return HOUR(tmp / 100) + tmp % 100;
336-
}
337-
case 5:
338-
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
339-
return tmp;
340-
}
341-
return 0;
313+
char *begin = *ptr, *end;
314+
timelib_long tmp;
315+
316+
while (isdigit(**ptr) || **ptr == ':') {
317+
++*ptr;
318+
}
319+
end = *ptr;
320+
switch (end - begin) {
321+
case 1: /* H */
322+
case 2: /* HH */
323+
return HOUR(strtol(begin, NULL, 10));
324+
break;
325+
case 3: /* H:M */
326+
case 4: /* H:MM, HH:M, HHMM */
327+
if (begin[1] == ':') {
328+
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);
329+
return tmp;
330+
} else if (begin[2] == ':') {
331+
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
332+
return tmp;
333+
} else {
334+
tmp = strtol(begin, NULL, 10);
335+
return HOUR(tmp / 100) + tmp % 100;
336+
}
337+
case 5: /* HH:MM */
338+
tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
339+
return tmp;
340+
}
341+
return 0;
342342
}

ext/date/lib/timelib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
# define timelib_free free
3939
#endif
4040

41-
#define TIMELIB_VERSION 201502
42-
#define TIMELIB_ASCII_VERSION "2015.02"
41+
#define TIMELIB_VERSION 201602
42+
#define TIMELIB_ASCII_VERSION "2016.02"
4343

4444
#define TIMELIB_NONE 0x00
4545
#define TIMELIB_OVERRIDE_TIME 0x01

ext/date/lib/tm2unixtime.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,17 @@ static void do_adjust_for_weekday(timelib_time* time)
152152
current_dow = timelib_day_of_week(time->y, time->m, time->d);
153153
if (time->relative.weekday_behavior == 2)
154154
{
155-
if (time->relative.weekday == 0) {
155+
/* To make "this week" work, where the current DOW is a "sunday" */
156+
if (current_dow == 0 && time->relative.weekday != 0) {
157+
time->relative.weekday = -6;
158+
}
159+
160+
/* To make "sunday this week" work, where the current DOW is not a
161+
* "sunday" */
162+
if (time->relative.weekday == 0 && current_dow != 0) {
156163
time->relative.weekday = 7;
157164
}
165+
158166
time->d -= current_dow;
159167
time->d += time->relative.weekday;
160168
return;

ext/date/tests/bug63740.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bug #63740 (strtotime seems to use both sunday and monday as start of week)
3+
--FILE--
4+
<?php
5+
$dates = [
6+
'2015-07-04',
7+
'2015-07-05',
8+
'2015-07-06',
9+
'2015-07-07',
10+
'2015-07-08',
11+
'2015-07-09',
12+
'2015-07-10',
13+
'2015-07-11',
14+
'2015-07-12',
15+
'2015-07-13',
16+
'2015-07-14',
17+
];
18+
19+
foreach ( $dates as $date )
20+
{
21+
$dt = new DateTimeImmutable( "$date 00:00 UTC" );
22+
23+
echo $dt->format( "D Y-m-d H:i" ), "";
24+
25+
$dtn = $dt->modify( "this week" );
26+
27+
echo $dtn->format( "D Y-m-d H:i" ), "\n";
28+
}
29+
?>
30+
--EXPECT--
31+
Sat 2015-07-04 00:00 → Mon 2015-06-29 00:00
32+
Sun 2015-07-05 00:00 → Mon 2015-06-29 00:00
33+
Mon 2015-07-06 00:00 → Mon 2015-07-06 00:00
34+
Tue 2015-07-07 00:00 → Mon 2015-07-06 00:00
35+
Wed 2015-07-08 00:00 → Mon 2015-07-06 00:00
36+
Thu 2015-07-09 00:00 → Mon 2015-07-06 00:00
37+
Fri 2015-07-10 00:00 → Mon 2015-07-06 00:00
38+
Sat 2015-07-11 00:00 → Mon 2015-07-06 00:00
39+
Sun 2015-07-12 00:00 → Mon 2015-07-06 00:00
40+
Mon 2015-07-13 00:00 → Mon 2015-07-13 00:00
41+
Tue 2015-07-14 00:00 → Mon 2015-07-13 00:00

0 commit comments

Comments
 (0)