Home

Awesome

<center> <img src='logo/tempe.png' height='120' align="center" alt='Tempe Logo' />

Featherlight (2kB) helper for Javascript date formatting

min min

</center>

Sometimes all you need is just a simple date formatting without all of those super powers.

Name is a play from tempus, Latin word meaning time and tempe an Indonesian traditional food.

📦 Install

$ yarn add tempe

 or

$ npm install tempe --save

💻 Usage

Use the default export, pass existing date object or you can initialize it like normal Javascript Date object.

import tempe from 'tempe';

// use tempe as Date initializer
tempe(2020, 0, 13).format('dd, DD MMM YYYY'); // "Monday, 13 Jan 2020"

// pass existing Date object to tempe
tempe(new Date(2020, 0, 13)).format('dd, DD MMM YYYY'); // "Monday, 13 Jan 2020"

// time formatting
tempe(2020, 2, 25, 23, 59).format('DD MMMM YYYY hh:mm:ss'); // "25 March 2020 23:59:00"
tempe(2020, 2, 25, 23, 59).format('H at DD/MM/YYYY'); // "11 PM at 25/03/2020"

🌐 i18n

Tempe supports internationalization by specifying the locale while formatting

import tempe from 'tempe';

tempe(2020, 5, 13).format('DD MMM YYYY', 'ja'); // "13日 6月 2020年"
tempe(2020, 5, 13).format('DD MMM YYYY', 'vi'); // "13 Tháng 6 2020"
tempe(2020, 5, 13).format('DD MMM YYYY', 'id'); // "13 Juni 2020"

Calendar Types

Meanwhile, some locale have their own default calendar type. For example, if you're using a Thailand locale it will generate a Buddhist calendar that show a different year than standard gregorian calendar.

tempe(2020, 5, 13).format('DD MMM YYYY', 'th'); // 13 มิถุนายน พ.ศ. 2563

You can change it by providing the calendar type in the third optional parameter of format() function.

// change calendar type to gregorian
tempe(2020, 5, 13).format('DD MMM YYYY', 'th', 'gregory' ); // 13 มิถุนายน พ.ศ. 2020

// change calendar type to islamic
tempe(2020, 5, 13).format('DD MMM YYYY', 'id', 'islamic' ); // 22 Syawal 1441 H

Possible values for this parameter includes:

This is an optional parameter. By leaving this parameter empty, the date will be generated using the default type of provided locale.

📝 List of all available formats

FormatOutputDescription
YY18Two-digit year
YYYY2018Four-digit year
M1-12The month, beginning at 1
MM01-12The month, 2-digits
MMMJan-DecThe abbreviated month name
MMMMJanuary-DecemberThe full month name
D1-31The day of the month
DD01-31The day of the month, 2-digits
ddSun-SatThe short name of the day of the week
dddSunday-SaturdayThe name of the day of the week
H0-23 AM/PMThe hour with AM/PM
HH0-23 AM/PMThe hour with AM/PM
h01-12The hour, 12-hour clock
hh01-12The hour, 12-hour clock
m0-59The minute
mm00-59The minute, 2-digits
s0-59The second
ss00-59The second, 2-digits

This project was bootstrapped with TSDX.