-
-
Save icesernia/eea0ea1291fc5b058354d9d797d955f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rtf = new Intl.RelativeTimeFormat("th", { | |
localeMatcher: "best fit", | |
numeric: "always", | |
style: "long", | |
}); | |
console.log(rtf.format(-1, "day")); // expected output: 1 วันที่ผ่านมา | |
console.log(rtf.format(-1, "month")); // expected output: 1 เดือนที่ผ่านมา | |
console.log(rtf.format(-1, "year")); // expected output: 1 ปีที่แล้ว | |
console.log(rtf.format(1, "day")); // expected output: ในอีก 1 วัน | |
console.log(rtf.format(0, "year")); // expected output: ในอีก 0 ปี | |
const rtf1 = new Intl.RelativeTimeFormat("th", { numeric: "auto" }); | |
console.log(rtf1.format(-1, "day")); // expected output: เมื่อวาน | |
console.log(rtf1.format(-1, "month")); // expected output: เดือนที่แล้ว | |
console.log(rtf1.format(-1, "year")); // expected output: ปีที่แล้ว | |
console.log(rtf1.format(1, "day")); // expected output: พรุ่งนี้ | |
console.log(rtf1.format(0, "year")); // expected output: ปีนี้ | |
const rtf2 = new Intl.RelativeTimeFormat("en", { numeric: "auto" }); | |
console.log(rtf2.format(-1, "day")); // expected output: yesterday | |
console.log(rtf2.format(-1, "month")); // expected output: last month | |
console.log(rtf2.format(-1, "year")); // expected output: last year | |
console.log(rtf2.format(1, "day")); // expected output: tomorrow | |
console.log(rtf2.format(0, "year")); // expected output: this year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment