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

[HttpKernel]  Resolve DateTime value using the Clock#48098

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

Merged
nicolas-grekas merged 1 commit intosymfony:6.3fromGromNaN:clock-valud-resolver
Dec 22, 2022

Conversation

@GromNaN
Copy link
Member

@GromNaNGromNaN commentedNov 3, 2022
edited
Loading

QA
Branch?6.3
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PRTODO

In order to mock the current time in functional test cases by injecting aSymfony\Component\Clock\MockClock asclock service. This is necessary when aDateTimeInterface argument is not nullable and we expect the current date time by default.

Example when 2 routes are configured on the same controller with an optional parameter.

class TvGridController{    #[Route('/', name:'prime_now')]    #[Route('/{date}', name:'prime_date']publicfunctionprime(\DateTimeInterface$date)    {returnnewResponse('Grid for date:'.$date->format('Y-m-d'));    }}

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.2" but it seems your PR description refers to branch "6.3".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbotcarsonbot changed the title[HttpKernel] Resolve DateTime value using the Clock[HttpKernel]  Resolve DateTime value using the ClockNov 3, 2022
@GromNaNGromNaN modified the milestones:6.2,6.3Nov 3, 2022
@GromNaN
Copy link
MemberAuthor

Fromphp doc:

Ifformat does not contain the character! then portions of the generated date/time which are not specified in format will be set to the current system time.

It looks like we cannot change the reference date when usingDateTime::createFromFormat. This means we cannot use the clock whenformat is specified.

@GromNaNGromNaNforce-pushed theclock-valud-resolver branch 2 times, most recently fromdcf32eb toc3bc63cCompareDecember 4, 2022 22:40
Copy link
MemberAuthor

@GromNaNGromNaN left a comment

Choose a reason for hiding this comment

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

Rebased. Ready for a last review.

@GromNaN
Copy link
MemberAuthor

I tried to use the newClockAwareTrait from#48362, but I think we should not havesymfony/clock as a required dependency to use this class.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedDec 22, 2022
edited
Loading

Now that#48642 is merged, what about leveragingClock::get()->now()?
Making clock a required dep might be legit. Because this static class is just a wrapper around PSR-20, it doesn't create any strong coupling to the clock implementations in the package so it might be fine.

@GromNaN
Copy link
MemberAuthor

GromNaN commentedDec 22, 2022
edited
Loading

Dependency injection is simpler here since this is already a service, and this is easy to test. I don't see the benefit of the global object: that adds a required dependency tosymfony/clock and the tests would required a call tomockTime.

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.

LGTM thanks (small rebase needed)

@GromNaNGromNaNforce-pushed theclock-valud-resolver branch 2 times, most recently from9319d95 toacf7674CompareDecember 22, 2022 11:43
@nicolas-grekas
Copy link
Member

(tests fail)

@GromNaN
Copy link
MemberAuthor

Yes sorry, that's fixed.

@nicolas-grekas
Copy link
Member

Thank you@GromNaN.

@nicolas-grekasnicolas-grekas merged commitdfcb811 intosymfony:6.3Dec 22, 2022
@GromNaNGromNaN deleted the clock-valud-resolver branchDecember 22, 2022 16:11
fabpot added a commit that referenced this pull requestJan 11, 2023
…olver (nicolas-grekas)This PR was merged into the 6.3 branch.Discussion----------[HttpKernel] Use TZ from clock service in DateTimeValueResolver| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -Fixing#48098 + making tests green by using legit TZ names.Commits-------1acf90e [HttpKernel] Use TZ from clock service in DateTimeValueResolver
@fabpotfabpot mentioned this pull requestMay 1, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@stofstofstof left review comments

Assignees

No one assigned

Projects

None yet

Milestone

6.3

Development

Successfully merging this pull request may close these issues.

4 participants

@GromNaN@carsonbot@nicolas-grekas@stof

[8]ページ先頭

©2009-2025 Movatter.jp