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

[Serializer] Better example for date denormalization#19356

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
OskarStark merged 1 commit intosymfony:5.4frommisaert:patch-1
Dec 30, 2023
Merged

[Serializer] Better example for date denormalization#19356

OskarStark merged 1 commit intosymfony:5.4frommisaert:patch-1
Dec 30, 2023

Conversation

misaert
Copy link
Contributor

@misaertmisaert commentedDec 29, 2023
edited by OskarStark
Loading

Hi,

When we use theDateTimeNormalizer to denormalize a date without time, using the same formatY-m-d does not seem a good example because the objectDateTimeImmutable has the time from the moment of denormalization.

Example:

$dateTimeFormat ='Y-m-d';// From `$context[self::FORMAT_KEY]`$result = DateTimeImmutable::createFromFormat($dateTimeFormat,'2024-01-31');var_dump($result);

Output:

object(DateTimeImmutable)symfony#1 (3) {  ["date"]=>  string(26) "2024-01-31 17:14:23.000000"  ["timezone_type"]=>  int(3)  ["timezone"]=>  string(16) "Europe/Amsterdam"}

It seems better to differentiate the normalization and the denormalization like:

#[Context(    normalizationContext: [DateTimeNormalizer::FORMAT_KEY =>'Y-m-d'],    denormalizationContext: [DateTimeNormalizer::FORMAT_KEY =>'!Y-m-d'],)]

The format!Y-m-d prevents to have a time and weird behavior.

$dateTimeFormat ='!Y-m-d';// From `$context[self::FORMAT_KEY]`$result = DateTimeImmutable::createFromFormat($dateTimeFormat,'2024-01-31');var_dump($result);

Output:

object(DateTimeImmutable)symfony#1 (3) {  ["date"]=>  string(26) "2024-01-31 00:00:00.000000"  ["timezone_type"]=>  int(3)  ["timezone"]=>  string(16) "Europe/Amsterdam"}

WDYT?

Mickaël

@OskarStark
Copy link
Contributor

Thank you Mickaël.

misaert reacted with thumbs up emoji

@OskarStarkOskarStark merged commit57e50c3 intosymfony:5.4Dec 30, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OskarStarkOskarStarkOskarStark approved these changes

@xabbuhxabbuhxabbuh approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
5.4
Development

Successfully merging this pull request may close these issues.

4 participants
@misaert@OskarStark@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp