firebase_rs_sdk/util/
formatters.rs1pub fn ordinal(value: i64) -> String {
2 let suffix = match value.rem_euclid(100) {
3 11..=13 => "th",
4 _ => match value.rem_euclid(10) {
5 1 => "st",
6 2 => "nd",
7 3 => "rd",
8 _ => "th",
9 },
10 };
11
12 format!("{value}{suffix}")
13}
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18
19 #[test]
20 fn ordinal_suffixes_match() {
21 assert_eq!(ordinal(1), "1st");
22 assert_eq!(ordinal(2), "2nd");
23 assert_eq!(ordinal(3), "3rd");
24 assert_eq!(ordinal(4), "4th");
25 assert_eq!(ordinal(11), "11th");
26 }
27}