-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add calendar DateType option #53895
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
$form->submit('2024-03-31 2024w13'); | ||
|
||
$this->assertEquals($output, $form->getData()); | ||
$this->assertEquals('2024-03-31 2024w13', $form->getViewData()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use asserSame ?
Same for the other tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the change ready on local, but I'm not a big fan of it as other tests in changed files use assertEquals
. Could somebody else give us an opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opinion: never rely on assertEquals
, same as never rely on ==
instead of ===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change it to assertSame
across the whole file 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are random comments :)
@@ -49,7 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void | |||
{ | |||
$dateFormat = \is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT; | |||
$timeFormat = \IntlDateFormatter::NONE; | |||
$calendar = \IntlDateFormatter::GREGORIAN; | |||
$calendar = null !== $options['calendar'] ? $options['calendar'] : \IntlDateFormatter::GREGORIAN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$calendar = null !== $options['calendar'] ? $options['calendar'] : \IntlDateFormatter::GREGORIAN; | |
$calendar = $options['calendar'] ?? \IntlDateFormatter::GREGORIAN; |
$pattern, | ||
); | ||
|
||
$this->assertEquals('2024-03-31 2024w13', $transformer->transform($dateTime)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertSame everywhere please
null, | ||
$calendar, | ||
$pattern, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we prefer long lines, maybe using named args could help? our put this on one line otherwise
|
||
$pattern = "y-MM-dd y'w'w"; | ||
|
||
$transformer = new DateTimeToLocalizedStringTransformer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneliners FTW
$calendar->setFirstDayOfWeek(\IntlCalendar::DOW_MONDAY); | ||
$calendar->setMinimalDaysInFirstWeek(4); | ||
|
||
$transformer = new DateTimeToLocalizedStringTransformer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneliner
@jan-pintr are you interested in finishing this PR? |
closing in favour of #57960, thank you for starting the work @jan-pintr |
…ype` (alexandre-daubois) This PR was merged into the 7.2 branch. Discussion ---------- [Form] Add support for the `calendar` option in `DateType` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #53894 | License | MIT Supersedes #53895 which seems abandoned for 6 months. I genuinely think this feature worth it especially when dealing with calendars with different first day of week. Commits ------- fca95c5 [Form] Add support for the `calendar` option in `DateType`
Recently I required to render DateType in format with week of year [1] (week 13 of year 2024:
2024-03-31 2024w13
) with independentIntlCalendar
specification than provided from currently setLocale
.For example when project (default) locale is
en_US
(en
). But you need to output in "European's format" it is not possible with current implementation. You would get2024-03-31 2024w14
, because first day of week configuration is taken from currently set locale.This pull request adds
calendar
option toDateType
.[1] https://unicode.org/reports/tr35/tr35-dates.html#Date_Patterns_Week_Of_Year