Skip to content

Commit f06fb22

Browse files
committed
Merged pull request #7586
2 parents f948370 + 12702a2 commit f06fb22

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ PHP NEWS
1717
- Date:
1818
. Fixed GH-8458 (DateInterval::createFromDateString does not throw if
1919
non-relative items are present). (Derick)
20+
. idate() now accepts format specifiers "N" (ISO Day-of-Week) and "o" (ISO
21+
Year). (Pavel Djundik)
2022

2123
- FPM:
2224
. Emit error for invalid port setting. (David Carlier)

ext/date/php_date.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ PHPAPI int php_idate(char format, time_t ts, bool localtime)
882882
/* day */
883883
case 'd': case 'j': retval = (int) t->d; break;
884884

885+
case 'N': retval = (int) timelib_iso_day_of_week(t->y, t->m, t->d); break;
885886
case 'w': retval = (int) timelib_day_of_week(t->y, t->m, t->d); break;
886887
case 'z': retval = (int) timelib_day_of_year(t->y, t->m, t->d); break;
887888

@@ -896,6 +897,7 @@ PHPAPI int php_idate(char format, time_t ts, bool localtime)
896897
case 'L': retval = (int) timelib_is_leap((int) t->y); break;
897898
case 'y': retval = (int) (t->y % 100); break;
898899
case 'Y': retval = (int) t->y; break;
900+
case 'o': retval = (int) isoyear; break; /* iso year */
899901

900902
/* Swatch Beat a.k.a. Internet Time */
901903
case 'B':

ext/standard/tests/time/idate.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ idate() function
33
--FILE--
44
<?php
55
date_default_timezone_set('GMT0');
6-
$tmp = "UYzymndjHGhgistwLBIW";
6+
$tmp = "UYozymndjHGhgistwNLBIW";
77
for($a = 0;$a < strlen($tmp); $a++){
88
echo $tmp[$a], ': ', idate($tmp[$a], 1043324459)."\n";
99
}
1010
?>
1111
--EXPECT--
1212
U: 1043324459
1313
Y: 2003
14+
o: 2003
1415
z: 22
1516
y: 3
1617
m: 1
@@ -25,6 +26,7 @@ i: 20
2526
s: 59
2627
t: 31
2728
w: 4
29+
N: 4
2830
L: 0
2931
B: 556
3032
I: 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
idate() function: ISO Day-of-Week and ISO Year
3+
--FILE--
4+
<?php
5+
date_default_timezone_set('UTC');
6+
$tmp = "UwNW";
7+
for ($a = 0; $a < strlen($tmp); $a++){
8+
echo $tmp[$a], ': ', idate($tmp[$a], 1041808859), "\n";
9+
}
10+
$tmp = "UYoW";
11+
for ($a = 0; $a < strlen($tmp); $a++){
12+
echo $tmp[$a], ': ', idate($tmp[$a], 1072912859), "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
U: 1041808859
17+
w: 0
18+
N: 7
19+
W: 1
20+
U: 1072912859
21+
Y: 2003
22+
o: 2004
23+
W: 1

0 commit comments

Comments
 (0)