Skip to content

Conversation

@antoinerousseau
Copy link

Fixes #1391.

@fturmel
Copy link
Member

fturmel commented Jan 9, 2024

Thoughts on my comment in this similar PR?

It might be less common, but I can see a valid use case (invoicing?) that would use day ordinals without months (ex: 5e du mois / 5e jour du mois). The date-fns v1 implementation was only applying this behavior if day ordinals were followed by MMM or MMMM, which seems like the safer approach but would require a revamp of the format function as far as I can tell.

@fturmel
Copy link
Member

fturmel commented Jan 9, 2024

Also, there used to be unit tests for this edge case in v1. It might be a good idea to bring this back because the locale snapshot tests sometimes don't surface these more subtle issues.

describe('Do MMM & Do MMMM', function () {
it('returns ordinal for day of month 1', function () {
var january1st = new Date(2017, 0 /* Jan */, 1)
var formatters = {
D: function () {
return 1
}
}
assert(buildFormatLocale().formatters.Do(january1st, formatters) === '1er')
assert(buildFormatLocale().formatters.MMM(january1st, formatters) === 'janv.')
assert(buildFormatLocale().formatters['Do MMM'](january1st, formatters) === '1er janv.')
assert(buildFormatLocale().formatters.MMMM(january1st, formatters) === 'janvier')
assert(buildFormatLocale().formatters['Do MMMM'](january1st, formatters) === '1er janvier')
})
it('returns cardinal for day of month other than 1', function () {
var january2nd = new Date(2017, 0 /* Jan */, 2)
var formatters = {
D: function () {
return 2
}
}
assert(buildFormatLocale().formatters.Do(january2nd, formatters) === '2e')
assert(buildFormatLocale().formatters.MMM(january2nd, formatters) === 'janv.')
assert(buildFormatLocale().formatters['Do MMM'](january2nd, formatters) === '2 janv.')
assert(buildFormatLocale().formatters.MMMM(january2nd, formatters) === 'janvier')
assert(buildFormatLocale().formatters['Do MMMM'](january2nd, formatters) === '2 janvier')
})
})
})

@antoinerousseau
Copy link
Author

antoinerousseau commented Jan 9, 2024

@fturmel indeed we might want to handle this edge case, but it's much less common so I think it's a good first fix anyway?

And those edge cases are better written using an intl library instead of this one.

The current version does not allow to handle this easily anyway...

Also, I added the test snapshots you suggested :)

@fturmel
Copy link
Member

fturmel commented Jan 9, 2024

Not my call to make, but the concern I want to raise (especially to the non-speaking core team) is the trade-off between breaking valid edge cases that are probably already out there in favor of fixing the more common use case.

I might poke around the format function a bit to see if I can find a somewhat sane approach to going back to this v1 behavior.

@Dallas62
Copy link

As mentioned in this PR, this change introduce a regression which is not expected #1391 (comment)
I'm not sure that introduce a regression is better than keep it as it is.

@antoinerousseau
Copy link
Author

@Dallas62 indeed, that's why @fturmel opened the even better #3662 :)

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.

Wrong translation for French.

3 participants