Skip to content

Commit 7d7a3d7

Browse files
committed
Fix #78649 Provide ICU RELATIVE_ constants
1 parent 85ea04b commit 7d7a3d7

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

ext/intl/dateformat/dateformat.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void dateformat_register_constants( INIT_FUNC_ARGS )
4444
DATEFORMATTER_EXPOSE_CLASS_CONST( MEDIUM );
4545
DATEFORMATTER_EXPOSE_CLASS_CONST( SHORT );
4646
DATEFORMATTER_EXPOSE_CLASS_CONST( NONE );
47+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_FULL", UDAT_FULL_RELATIVE );
48+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_LONG", UDAT_LONG_RELATIVE );
49+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_MEDIUM", UDAT_MEDIUM_RELATIVE );
50+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_SHORT", UDAT_SHORT_RELATIVE );
4751

4852
/*
4953
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "GREGORIAN", DATEF_GREGORIAN );
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
datefmt_format_code() with relative formats
3+
--SKIPIF--
4+
<?php if (!extension_loaded("intl")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getYesterday());
9+
printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getYesterday());
10+
printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getYesterday());
11+
printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getYesterday());
12+
13+
printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getToday());
14+
printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getToday());
15+
printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getToday());
16+
printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getToday());
17+
18+
printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getTomorrow());
19+
printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getTomorrow());
20+
printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getTomorrow());
21+
printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getTomorrow());
22+
23+
function printFormat(int $dateFormat, int $timeFormat, DateTimeImmutable $time) {
24+
$formatter = new IntlDateFormatter(
25+
"en_US",
26+
$dateFormat,
27+
$timeFormat,
28+
"America/Los_Angeles",
29+
IntlDateFormatter::GREGORIAN
30+
);
31+
32+
echo $formatter->format($time) . "\n";
33+
}
34+
35+
function getToday(): DateTimeImmutable {
36+
return new DateTimeImmutable();
37+
}
38+
39+
function getYesterday(): DateTimeImmutable {
40+
return new DateTimeImmutable("-1 day");
41+
}
42+
43+
function getTomorrow(): DateTimeImmutable {
44+
return new DateTimeImmutable("+1 day");
45+
}
46+
47+
--EXPECT--
48+
yesterday
49+
yesterday
50+
yesterday
51+
yesterday
52+
today
53+
today
54+
today
55+
today
56+
tomorrow
57+
tomorrow
58+
tomorrow
59+
tomorrow

0 commit comments

Comments
 (0)