Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Intl] AddDateIntervalFormatter#39912

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
YaFou wants to merge1 commit intosymfony:5.4fromYaFou:date-interval-formatter

Conversation

@YaFou
Copy link
Contributor

@YaFouYaFou commentedJan 20, 2021
edited
Loading

QA
Branch?5.x
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#29929
LicenseMIT
Doc PRTODO
$formatter =newDateIntervalFormatter();$formatter->formatInterval(new \DateInterval('P1DT5H2M'));// one day, 5 hours and 2 minutes

You can set a precision. The precision cuts the formatted content to a given number of elements:

$formatter =newDateIntervalFormatter();$formatter->formatInterval(new \DateInterval('P1DT20H2M'),2);// one day and 20 hours

Deltachaos reacted with thumbs up emojiOskarStark reacted with eyes emoji
@carsonbotcarsonbot changed the title[Translation] [WIP] Add DateIntervalFormatter[Translator] [WIP] Add DateIntervalFormatterJan 20, 2021
@YaFouYaFouforce-pushed thedate-interval-formatter branch 2 times, most recently from0169445 to5189d2dCompareJanuary 20, 2021 20:54
@ro0NL
Copy link
Contributor

there's an interesting ICU concept: listPattern
https://github.com/unicode-org/icu/blob/6092942e23785d85de5b40ea2f47768f7fa9345b/icu4c/source/data/locales/en.txt#L2007

relative/duration time formats
https://github.com/unicode-org/icu/blob/6092942e23785d85de5b40ea2f47768f7fa9345b/icu4c/source/data/locales/en.txt#L1441-L1456
https://github.com/unicode-org/icu/blob/6092942e23785d85de5b40ea2f47768f7fa9345b/icu4c/source/data/unit/en.txt#L286

ideally we'd implement this at the ICU message format level 😁 but that's far fetched.

overall, having a generic localized interval formatter in the Intl component seems more useful.

kaznovac reacted with thumbs up emoji

@fancyweb
Copy link
Contributor

fancyweb commentedJan 21, 2021
edited
Loading

overall, having a generic localized interval formatter in the Intl component seems more useful.

I agree and we could use it in the Validator component too for#33401

@YaFouYaFouforce-pushed thedate-interval-formatter branch from2888345 to7f6cbbaCompareJanuary 21, 2021 10:04
@YaFouYaFouforce-pushed thedate-interval-formatter branch 2 times, most recently fromb43f917 to0ed15bdCompareJanuary 21, 2021 10:08
@nicolas-grekasnicolas-grekas added this to the5.x milestoneJan 21, 2021
@YaFouYaFou changed the title[Translator] [WIP] Add DateIntervalFormatter[Intl] [WIP] Add DateIntervalFormatterJun 26, 2021
@YaFouYaFouforce-pushed thedate-interval-formatter branch 5 times, most recently from1c09134 to894cc36CompareJune 26, 2021 09:01
@YaFou
Copy link
ContributorAuthor

Ready for review

@YaFouYaFou changed the title[Intl] [WIP] Add DateIntervalFormatter[Intl] Add DateIntervalFormatterJun 26, 2021
@YaFouYaFou requested a review fromOskarStarkJune 26, 2021 09:03
@YaFouYaFouforce-pushed thedate-interval-formatter branch from894cc36 to86a078aCompareJune 26, 2021 09:05
useTwig\Extension\AbstractExtension;
useTwig\TwigFilter;

class IntlExtensionextends AbstractExtension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about doing this inhttps://github.com/twigphp/intl-extra/blob/2.x/IntlExtension.php instead?
Currently it may conflict withhttps://github.com/twigphp/twig-extra-bundle/blob/2.x/Resources/config/intl.php.

YaFou reacted with thumbs up emoji
Copy link
Member

@nicolas-grekasnicolas-grekasOct 18, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think@HeahDude's idea is a good one. Can you please remove that code from this PR and move it to twig instead?

@sstok
Copy link
Contributor

FYIhttps://carbon.nesbot.com/docs/#api-interval provides a fully localized version of DateInterval withforHumans().

@OskarStarkOskarStark changed the title[Intl] Add DateIntervalFormatter[Intl] AddDateIntervalFormatterAug 4, 2021
@OskarStark
Copy link
Contributor

Open to finish this PR@YaFou ?

@YaFou
Copy link
ContributorAuthor

Open to finish this PR@YaFou ?

For me, it is finished. I saw comments which suggest to add ICU but I don't think we have to add something to big to Symfony core.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm mixed here: I get the value, but what about i18n? Is the language designed to be an implementation detail or should the interface allow declaring it?

In the end, my question ends up as: shouldn't we delegate this to a 3rd party lib, eg Carbon?

useTwig\Extension\AbstractExtension;
useTwig\TwigFilter;

class IntlExtensionextends AbstractExtension
Copy link
Member

@nicolas-grekasnicolas-grekasOct 18, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think@HeahDude's idea is a good one. Can you please remove that code from this PR and move it to twig instead?

->tag('container.service_subscriber', ['id' =>'translator'])
->tag('kernel.cache_warmer')

->set('translation.formatter.date_interval', DateIntervalFormatter::class)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't get the need for this service

returnstaticfunction (ContainerConfigurator$container) {
$container->services()
->set('intl.date_interval_formatter', DateIntervalFormatter::class)
->alias(DateIntervalFormatterInterface::class,'intl.date_interval_formatter')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

alias should be unindented by one

'kernel.reset',
]);

if (class_exists(DateIntervalFormatterInterface::class)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

interface_exists, since it's not a class but an interface

5.4
---

* Add`DateIntervalFormatter` to humanize a`DateInterval` or a difference between two`DateTimeInterface` objects

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

missing space at start of line

/**
* @param \DateInterval|string $interval
*/
publicfunctionformatInterval($interval,int$precision =0):string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

what is $precision supposed to mean? reading the interface should provide a clue

@fabpot
Copy link
Member

Having something like this in core without i18n is a no-go for me. As soon as we will merge it, people will start asking for it and they will be right.
Let's close for now.

@fabpotfabpot closed thisOct 30, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

@OskarStarkOskarStarkAwaiting requested review from OskarStark

+1 more reviewer

@HeahDudeHeahDudeHeahDude left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

[Translation] Add human readable DateInterval

9 participants

@YaFou@ro0NL@fancyweb@sstok@OskarStark@fabpot@nicolas-grekas@HeahDude@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp