Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113836 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60363 invoked from network); 28 Mar 2021 19:20:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2021 19:20:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 59AF81804D8 for ; Sun, 28 Mar 2021 12:17:48 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail02.x-net.at (mail02.x-net.at [83.65.141.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 28 Mar 2021 12:17:47 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 7C8203800D1 for ; Sun, 28 Mar 2021 21:17:45 +0200 (CEST) Received: from mail02.x-net.at ([127.0.0.1]) by localhost (x-zimbra02.x [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ZPLes1Dyi9fl for ; Sun, 28 Mar 2021 21:17:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 3024C38071B for ; Sun, 28 Mar 2021 21:17:42 +0200 (CEST) X-Virus-Scanned: amavisd-new at x-t.at Received: from mail02.x-net.at ([127.0.0.1]) by localhost (x-zimbra02.x [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wccDConPX1hp for ; Sun, 28 Mar 2021 21:17:42 +0200 (CEST) Received: from x-zimbra02.x (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 04B853800D1 for ; Sun, 28 Mar 2021 21:17:42 +0200 (CEST) Date: Sun, 28 Mar 2021 21:17:41 +0200 (CEST) To: internals Message-ID: <1794729934.336885.1616959061913.JavaMail.zimbra@dafert.at> In-Reply-To: References: <1722754661.329421.1616943259775.JavaMail.zimbra@dafert.at> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_4a37b8b0-9d0e-4a83-a3a4-1f49bb1d8f24" X-Mailer: Zimbra 8.8.15_GA_3959 (ZimbraWebClient - FF87 (Linux)/8.8.15_GA_3953) Thread-Topic: Proposal: add IntlDateTimePatternGenerator Thread-Index: 5zLXl95FMpaIMMtkebuEahb1HhyiwQ== Subject: Re: [PHP-DEV] Proposal: add IntlDateTimePatternGenerator From: mel@dafert.at (Mel Dafert) --=_4a37b8b0-9d0e-4a83-a3a4-1f49bb1d8f24 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Now that I see their implementation again, I'm wondering if `IntlDateTimePa= tternGenerator` is the right name, or we should also use `IntlDatePatternGe= nerator`, which is more in line with `IntlDateFormatter`.=20 I was also wondering about that. I ended up going for `IntlDateTimePatternG= enerator`, because ICU has that same inconsistency (`icu::DateFormat` and `= icu::DateTimePatternGenerator`). I think the big argument here is discovera= bility - if someone is wondering about whether PHP exposes the feature from= ICU, it might be harder to find it if we name it differently (and vice ver= sa).=20 From: "M=C3=A1t=C3=A9 Kocsis" =20 To: "Mel Dafert" =20 Cc: "internals" =20 Sent: Sunday, March 28, 2021 7:45:46 PM=20 Subject: Re: [PHP-DEV] Proposal: add IntlDateTimePatternGenerator=20 Hi Mel,=20 Thank you very much for working on this! I was bitten by lack of this funct= ionality a few years ago, and I couldn't find any (good) alternative. Thus,= I'm looking forward to having `IntlDateTimePatternGenerator` in ext/intl.= =20 I think it could be mentioned for those who don't open the bug report that = HHVM implemented this class long ago: [ https://github.com/facebook/hhvm/co= mmit/bc84daf7816e4cd268da59d535dcadfc6cf01085 | https://github.com/facebook= /hhvm/commit/bc84daf7816e4cd268da59d535dcadfc6cf01085 ]=20 Now that I see their implementation again, I'm wondering if `IntlDateTimePa= tternGenerator` is the right name, or we should also use `IntlDatePatternGe= nerator`, which is more in line with ``IntlDateFormatter`.=20 Regards:=20 M=C3=A1t=C3=A9=20 Mel Dafert < [ mailto:mel@dafert.at | mel@dafert.at ] > ezt =C3=ADrta (id= =C5=91pont: 2021. m=C3=A1rc. 28., V, 16:54):=20 BQ_BEGIN Hello Internals,=20 I would like to propose an addition to the intl extension, IntlDateTimePatt= ernGenerator.=20 ICU exposes the DateTimePatternGenerator class that allows generating a for= matting pattern from a given "skeleton" for a given locale. (see [ https://= unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1DateTimePattern= Generator.html | https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/cl= assicu_1_1DateTimePatternGenerator.html ] )=20 This allows more flexibility than the current $format argument of IntlDateF= ormatter::format(), which takes either a few pre-defined constants or a har= d-coded format.=20 This functionality also has been requested in the past. (see [ https://bugs= .php.net/bug.php?id=3D70377 | https://bugs.php.net/bug.php?id=3D70377 ] )= =20 For example, if an application requires a format that will always use the l= ong version of a year, but the short version of a month (eg. "MM/dd/YYYY" f= or "en_US", or "dd.MM.YYYY" for "de_DE"), one is out of luck.=20 IntlDateFormatter::SHORT will use the short year for "de_DE" ("dd.MM.YY"), = and IntlDateFormatter::MEDIUM will use the long version of a month for "en_= US" ("MMM dd, YYYY").=20 With IntlDateTimePatternGenerator::getBestPattern(), a skeleton can be prov= ided to generate the appropriate pattern for a given locale.=20 In the use-case given above, the skeleton "YYYYMMdd" will generate the desi= red patterns for each locale, which can then be passed to IntlDateFormatter= ::format().=20 Proposed Signature:=20 ```=20 class IntlDateTimePatternGenerator=20 {=20 public function __construct(?string $locale =3D null) {}=20 public static function create(?string $locale =3D null): ?IntlDateTimePatte= rnGenerator {}=20 public function getBestPattern(string $skeleton): string|false {}=20 }=20 ```=20 Example use-case:=20 ```=20 $date =3D new \DateTime();=20 $skeleton =3D "YYYYMMdd";=20 $dtpg =3D new \IntlDateTimePatternGenerator(); // uses default locale if no= t specified=20 $format =3D $dtpg->getBestPattern($skeleton);=20 echo \IntlDateFormatter::formatObject($date, $format); // outputs "28.03.20= 20" for "de_DE" locale=20 ```=20 The proposed implementation can be found here: [ https://github.com/php/php= -src/pull/6771 | https://github.com/php/php-src/pull/6771 ]=20 I assume that this will require an RFC, in which case I request the karma t= o create one. My wiki account is deltragon.=20 Regards,=20 Mel Dafert=20 --=20 PHP Internals - PHP Runtime Development Mailing List=20 To unsubscribe, visit: [ https://www.php.net/unsub.php | https://www.php.ne= t/unsub.php ]=20 BQ_END --=_4a37b8b0-9d0e-4a83-a3a4-1f49bb1d8f24--