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.
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]);
}
Most helpful comment
This function should do the trick (for English at least)