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

[Validator] Format datetime values in comparison constraints withdateFormat option#39857

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

Conversation

@YaFou
Copy link
Contributor

@YaFouYaFou commentedJan 16, 2021
edited
Loading

QA
Branch?5.x
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#36784
LicenseMIT
Doc PRTODO

I have introduced a new option for comparison constraints calleddateFormat. This option gives the ability to use a different format for datetime values in the following placeholders:{{ value }} and{{ compared_value }}.

Before:

/** * @Assert\GreaterThanOrEqual(value="2020-01-01") */

will output:This value should be greater than Jan 1, 2020, 12:00 AM.

After:

/** * @Assert\GreaterThanOrEqual(value="2020-01-01", dateFormat="Y-m-d") */

will output:This value should be greater than 2020-01-01.

OskarStark, stloyd, maxhelias, JohJohan, and featuriz reacted with thumbs up emoji
@YaFouYaFouforce-pushed themessage-format-comparison-validator branch fromf019cc3 to64f3fc5CompareJanuary 16, 2021 13:57
@YaFouYaFouforce-pushed themessage-format-comparison-validator branch from64f3fc5 to9395d1dCompareJanuary 17, 2021 13:54
@YaFouYaFou changed the title[Validator] Format datetime values in comparison constraints with "valuesFormat" option[Validator] Format datetime values in comparison constraints with "dateFormat" optionJan 17, 2021
@YaFouYaFouforce-pushed themessage-format-comparison-validator branch 3 times, most recently from56fe8dd to3873d69CompareJanuary 17, 2021 14:12
@jderussejderusse added this to the5.x milestoneJan 18, 2021
@fancyweb
Copy link
Contributor

fancyweb commentedApr 7, 2021
edited
Loading

I have three concerns with the proposed solution:

  1. The date format will behave differently if\IntlDateFormatter is available or not. I mean you have to know about the internal code to choose the right format.
  2. There is no way to easily configure a date format for all constraints.
  3. I would like to have a way to add more custom configurable formats (eg: for[Validator] Support \DateInterval in comparison constraints #33401) and we are not going to pile arguments everywhere.

I tried to resolve this issue at least 3 times but never came out with something good enough to me. I think the difficulty is that the formatting logic is internal toConstraintValidator, it's nowhere in contracts. Having a real formatting system in the component could do the job. It could make sense at the violation builder level, but we cannot change thesetParameter() method. Maybe we can addsetParameterToFormat(string $key, mixed $value, int $flags) and then have a system that format the value to a string? It would be easy to hook in to add "custom" formatters. We would still need to find a way to easily allow override of the formats in the constraints.

@ro0NL
Copy link
Contributor

ro0NL commentedApr 26, 2021
edited
Loading

Having a real formatting system in the component could do the job.

https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Translation/Formatter/MessageFormatterInterface.php 😅

i'd be generally curious if we can move formatting to the translation level using ICU formats.

eg. to avoid duplicating the message, perhaps a special translation key solely for date values.

JohJohan and sstok reacted with thumbs up emoji

@JohJohan
Copy link
Contributor

Having a real formatting system in the component could do the job.

https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Translation/Formatter/MessageFormatterInterface.php 😅

i'd be generally curious if we can move formatting to the translation level using ICU formats.

eg. to avoid duplicating the message, perhaps a special translation key solely for date values.

That could be a solution the default value should be full date format as that is how it is now

@YaFouYaFouforce-pushed themessage-format-comparison-validator branch from3873d69 to62a7952CompareJune 26, 2021 08:27
@YaFouYaFouforce-pushed themessage-format-comparison-validator branch from62a7952 to478b8ecCompareJune 26, 2021 08:28
@YaFou
Copy link
ContributorAuthor

The date format will behave differently if \IntlDateFormatter is available or not. I mean you have to know about the internal code to choose the right format.

I'm facing the issue where the tests do not provide the intl extension and tests break... I don't know what is the right way to fix it.

@OskarStarkOskarStark changed the title[Validator] Format datetime values in comparison constraints with "dateFormat" option[Validator] Format datetime values in comparison constraints withdateFormat optionAug 4, 2021
@fabpotfabpot removed this from the5.4 milestoneNov 16, 2021
@fabpotfabpot added this to the6.1 milestoneNov 16, 2021
@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@louismariegaborit
Copy link
Contributor

I'm very interesting about this feature. What is missing for the PR will be merged ?

@fabpot
Copy link
Member

Closing for the reasons explained by@fancyweb

@fabpotfabpot closed thisJul 23, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@OskarStarkOskarStarkAwaiting requested review from OskarStark

3 more reviewers

@ro0NLro0NLro0NL left review comments

@JohJohanJohJohanJohJohan left review comments

@maxheliasmaxheliasmaxhelias approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

[Validator] Support date format option to format invalid message

10 participants

@YaFou@fancyweb@ro0NL@JohJohan@louismariegaborit@fabpot@OskarStark@maxhelias@jderusse@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp