Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113835 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52371 invoked from network); 28 Mar 2021 17:49:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2021 17:49:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 064911804D8 for ; Sun, 28 Mar 2021 10:45:59 -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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 28 Mar 2021 10:45:58 -0700 (PDT) Received: by mail-lj1-f171.google.com with SMTP id u10so13370642lju.7 for ; Sun, 28 Mar 2021 10:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6WAxZnqAziJz6eRH/1j/fev/m1iXdDP4O6LR0ORPDAU=; b=XHtgekjBOIA73yXI/o08D5LgSHs0eSiaA0lIaF22EE5HGg20uBoDAI2Aakwsj2x3Yz ciF3MoDlk1mtSEWdjeAnn+NWfRxFvN2r+1+nOIhb8CvUY/8oLCCyxCTApVFYmnsOhVsP 4phbCdaXoDGMpGFBeIirfAEdy+C9i9wojs3pa1lViTO+LccvGQw5aqiCCxQQCKayxmPl V4CwyImLdb3Gnw1tSoGxzz9e2g4BQALa//Mg5SBWOlUAqnlXkXmfr1v+RKZKabd9DX0k y7mzG8I8FXz6olYUgwGqVJudJ7PrZTTElVjWR5LfebV/yAzZrhQxnoI+0IWKScvL4lOD wsww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6WAxZnqAziJz6eRH/1j/fev/m1iXdDP4O6LR0ORPDAU=; b=WMlwv4dxffTfBjAReyfL40BCbPcnT78ekguZBpD2S9d4mZUk4w89h563V1KGUfsUFG 43PJXjbs4SW9bephWoBuHunTVLCzEypYgqeBnv8fMCHsMU582qZN/cn8ZNNx8C9OOZjP u4ZdEU1pVqfGKYS1Q3WyuxeGu2+3Prh1gl28mp8OL/57DFu5fn+vyhcsvt8Oi4txPOn5 EWF3I+cpS+Qjueu3qZH597JoQffrV4l8C1t8YJE/ItbfuYAxMJimaMfNqro/n/AVCn6y xAA8mMehDFGF0eQ9TdhQ8phvtO3EvjF6c/pWTFjSKxZuBHnYhHi08x9DRbYXw2VhV6er b2lA== X-Gm-Message-State: AOAM532f3DGYgrnRcxknBD2PlH+cLQcIpPkarzAvHrqNpX5HhKrxJfoP 5hxmuCSi6TYX/WIkv38lehtxPKAp7SRfne9brgSp9MWmXZg= X-Google-Smtp-Source: ABdhPJwz6ZJbFxGceudMxADtgu8jYJXFAyWWlZ/VGJLISNpIpoD4QphWL6+C0wmYan6QLzq4qjDIhvybNcy1y/me4Is= X-Received: by 2002:a05:651c:1206:: with SMTP id i6mr15859610lja.426.1616953556972; Sun, 28 Mar 2021 10:45:56 -0700 (PDT) MIME-Version: 1.0 References: <1722754661.329421.1616943259775.JavaMail.zimbra@dafert.at> In-Reply-To: <1722754661.329421.1616943259775.JavaMail.zimbra@dafert.at> Date: Sun, 28 Mar 2021 19:45:46 +0200 Message-ID: To: Mel Dafert Cc: internals Content-Type: multipart/alternative; boundary="00000000000061b7ed05be9c561e" Subject: Re: [PHP-DEV] Proposal: add IntlDateTimePatternGenerator From: kocsismate90@gmail.com (=?UTF-8?B?TcOhdMOpIEtvY3Npcw==?=) --00000000000061b7ed05be9c561e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Mel, Thank you very much for working on this! I was bitten by lack of this functionality a few years ago, and I couldn't find any (good) alternative. Thus, I'm looking forward to having `IntlDateTimePatternGenerator` in ext/intl. 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/commit/bc84daf7816e4cd268da59d535dcadfc6cf= 01085 Now that I see their implementation again, I'm wondering if `IntlDateTimePatternGenerator` is the right name, or we should also use `IntlDatePatternGenerator`, which is more in line with ``IntlDateFormatter`= . Regards: M=C3=A1t=C3=A9 Mel Dafert ezt =C3=ADrta (id=C5=91pont: 2021. m=C3=A1rc. 28= ., V, 16:54): > Hello Internals, > > I would like to propose an addition to the intl extension, > IntlDateTimePatternGenerator. > ICU exposes the DateTimePatternGenerator class that allows generating a > formatting pattern from a given "skeleton" for a given locale. (see > https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1DateT= imePatternGenerator.html > ) > This allows more flexibility than the current $format argument of > IntlDateFormatter::format(), which takes either a few pre-defined constan= ts > or a hard-coded format. > This functionality also has been requested in the past. (see > https://bugs.php.net/bug.php?id=3D70377) > > For example, if an application requires a format that will always use the > long version of a year, but the short version of a month (eg. "MM/dd/YYYY= " > for "en_US", or "dd.MM.YYYY" for "de_DE"), one is out of luck. > 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"). > > With IntlDateTimePatternGenerator::getBestPattern(), a skeleton can be > provided to generate the appropriate pattern for a given locale. > In the use-case given above, the skeleton "YYYYMMdd" will generate the > desired patterns for each locale, which can then be passed to > IntlDateFormatter::format(). > > Proposed Signature: > ``` > class IntlDateTimePatternGenerator > { > public function __construct(?string $locale =3D null) {} > > public static function create(?string $locale =3D null): > ?IntlDateTimePatternGenerator {} > > public function getBestPattern(string $skeleton): string|false {} > } > ``` > > Example use-case: > ``` > $date =3D new \DateTime(); > $skeleton =3D "YYYYMMdd"; > $dtpg =3D new \IntlDateTimePatternGenerator(); // uses default locale if = not > specified > $format =3D $dtpg->getBestPattern($skeleton); > > echo \IntlDateFormatter::formatObject($date, $format); // outputs > "28.03.2020" for "de_DE" locale > > ``` > > The proposed implementation can be found here: > https://github.com/php/php-src/pull/6771 > I assume that this will require an RFC, in which case I request the karma > to create one. My wiki account is deltragon. > > Regards, > Mel Dafert > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000061b7ed05be9c561e--