Skip to content

Conversation

@thibdrev
Copy link

clarifications on the formatDate() function

clarifications on the formatDate() function
@thibdrev thibdrev requested a review from a team as a code owner October 20, 2021 09:07
@Crash-- Crash-- requested review from LucsT and doubleface October 24, 2021 16:53
@Crash--
Copy link
Contributor

Crash-- commented Feb 1, 2022

*/
function formatDate(date) {
return format(new Date(date), 'yyyy-MM-dd')
return format(new Date(date), 'YYYY-MM-DD')
Copy link
Collaborator

Choose a reason for hiding this comment

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

What problem does this solve ?

Copy link
Contributor

Choose a reason for hiding this comment

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

from: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md

D and DD that represent the day of a year (1, 2, ..., 365, 366) are often confused with d and dd that represent the day of a month (1, 2, ..., 31).
YY and YYYY that represent the local week-numbering year (44, 01, 00, 17) are often confused with yy and yyyy that represent the calendar year.

// ❌ Wrong!
format(new Date(), 'YYYY-MM-DD')
//=> 2018-10-283

// ✅ Correct
format(new Date(), 'yyyy-MM-dd')
//=> 2018-10-10

So I don't think we should change the format.

We can still cherry-pick the documentation fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants