Skip to content

Add "N" and "o" format specifiers to idate() #7586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ PHP NEWS
- FPM:
. Emit error for invalid port setting. (David Carlier)

- Date:
. idate() now accepts format specifiers "N" and "o"

- Intl:
. Update all grandfathered language tags with preferred values
. Fixed GH-7939 (Cannot unserialize IntlTimeZone objects). (cmb)
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ PHP 8.2 UPGRADE NOTES
. Added CURLINFO_EFFECTIVE_METHOD option and returning the effective
HTTP method in curl_getinfo() return value.

- Date:
. idate() now accepts format specifiers "N" and "o".

- OCI8:
. Added an oci8.prefetch_lob_size directive and oci_set_prefetch_lob()
function to tune LOB query performance by reducing the number of
Expand Down
2 changes: 2 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ PHPAPI int php_idate(char format, time_t ts, bool localtime)
/* day */
case 'd': case 'j': retval = (int) t->d; break;

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

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

/* Swatch Beat a.k.a. Internet Time */
case 'B':
Expand Down
4 changes: 3 additions & 1 deletion ext/standard/tests/time/idate.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ idate() function
--FILE--
<?php
date_default_timezone_set('GMT0');
$tmp = "UYzymndjHGhgistwLBIW";
$tmp = "UYozymndjHGhgistwNLBIW";
for($a = 0;$a < strlen($tmp); $a++){
echo $tmp[$a], ': ', idate($tmp[$a], 1043324459)."\n";
}
?>
--EXPECT--
U: 1043324459
Y: 2003
o: 2003
z: 22
y: 3
m: 1
Expand All @@ -25,6 +26,7 @@ i: 20
s: 59
t: 31
w: 4
N: 4
L: 0
B: 556
I: 0
Expand Down
23 changes: 23 additions & 0 deletions ext/standard/tests/time/idate_iso.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
idate() function : isoweek
--FILE--
<?php
date_default_timezone_set('GMT0');
$tmp = "UwNW";
for($a = 0;$a < strlen($tmp); $a++){
echo $tmp[$a], ': ', idate($tmp[$a], 1041808859)."\n";
}
$tmp = "UYoW";
for($a = 0;$a < strlen($tmp); $a++){
echo $tmp[$a], ': ', idate($tmp[$a], 1072912859)."\n";
}
?>
--EXPECT--
U: 1041808859
w: 0
N: 7
W: 1
U: 1072912859
Y: 2003
o: 2004
W: 1