0.2.0 • Published 5 months ago
format-temporal v0.2.0
format-temporal
A formatting function for Temporal types.
Motivation
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.
Usage
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"
License
Apache-2.0