-
Notifications
You must be signed in to change notification settings - Fork 730
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
support for n-th token? #118
Comments
No, there's nothing for that. Luxon relies on Intl.NumberFormat to handle numbers, and it would need to support for nd, rd, th, etc in arbitrary locales, which it does not. When (and if) that API gains that capability, I will be able to add to Luxon too. |
This function should do the trick (for English at least) function getNumberSuffix(num) {
const th = 'th'
const rd = 'rd'
const nd = 'nd'
const st = 'st'
if (num === 11 || num === 12 || num === 13) return th
let lastDigit = num.toString().slice(-1)
switch (lastDigit) {
case '1': return st
case '2': return nd
case '3': return rd
default: return th
}
} |
Or you can do this 😬 (still for English) function ordinal(n) {
var s = ["th", "st", "nd", "rd"];
var v = n%100;
return n + (s[(v-20)%10] || s[v] || s[0]);
} |
This is supported via Intl.PluralRules setting it to mode: ordinal ? |
Nifty. Yeah, I would take a PR that uses that to implement some new formatting/parsing tokens |
FYI I'll try to issue a PR about this in the coming weeks. So if someone else works on that, let me know :) |
Hmm actually |
True, but you have Intl available so all that needs to happen is to pass the result to that to change local afterwards, no? First work out the resulting rule from PluralRules, map to English st, nd, rd, th. Then plug into Intl. Or see if the Intl already contains the mapping for the one/two/many/other for each language? Feels like a large ommison of Intl otherwise... requiring all users to implement the same boiler plate mapping |
That's where the issue is? Luxon would have to contain that mapping code for "all" locales? (Intl does not have that mapping as far as I can see but would be happy to be proven wrong!). |
OK, I spent some more time here. @cjolif is correct. The PluralRules would let us figure out which of the strings to use in what situation, but not what the strings actually are. Maintaining those strings is ICU's job, not Luxon's. We're not going to add scores of these: const suffixes = new Map([
['one', 'st'],
['two', 'nd'],
['few', 'rd'],
['other', 'th'],
]); I believe |
Luxon does not support ordinal date formating (1st, 2nd, 3rd etc.) because it is not supported by the underlying `Intl.DateTimeFormat`. There is an open issue: moment/luxon#118
Luxon does not support ordinal date formating (1st, 2nd, 3rd etc.) because it is not supported by the underlying `Intl.DateTimeFormat`. There is an open issue: moment/luxon#118
Is there an equivalent for 1st, 2nd, 3rd etc. for luxon? I was looking through the documentation, but couldn't find anything regarding this topic.
compare to:
http://momentjs.com/docs/#/displaying/format/ e.g. DDDo, Do, Mo, wo etc.
The text was updated successfully, but these errors were encountered: