An alternative to libraries such as moment.js, day.js, and date-fns, Tempo is a new package designed to simplify working with dates in JavaScript and TypeScript.
Tempo is best thought of as a collection of utilities for working with Date objects โ an important distinction from other libraries that provide custom date primitives.
To start using Tempo, simply run the following command:
npm install @formkit/tempo
Then import only the necessary functions, which is great for tree shaking:
import { format, parse, addDay } from "@formkit/tempo";
const readable = format(new Date(), "full"); // Friday, February 23, 2024
parse(readable, "full"); // Date: 2024-02-22T17:00:00.000Z
// Add 1 day
addDay("2013-03-15"); // Date: 2013-03-15T17:00:00.000Z
// Add 5 days
addDay("2013-03-15", 5); // Date: 2013-03-19T17:00:00.000Z
// Subtract 3 days
addDay("2013-03-15", -3); // Date: 2013-03-11T17:00:00.000Z
To learn more about this library, visit their documentation at tempo.formkit.com. You can also find the source code on Github.