A formatting function for Temporal types.
Several Temporal types don't support the toLocaleString
method (i.e., Temporal.ZonedDateTime
, Temporal.PlainYearMonth
, and Temporal.PlainMonthDay
), so this package provides a formatTemporal
function that formats a Temporal type using the Intl.DateTimeFormat
API.
import { formatTemporal } from "format-temporal";
const plainYearMonth = Temporal.PlainYearMonth.from("2023-05");
const formatter = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
});
const result = formatTemporal(plainYearMonth, formatter);
console.log(result); // "May 2023"
Apache-2.0