1.0.0 • Published 1 year ago

@coalaura/instant.js v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Instant.js

A small package to format dates and durations.

Installation

npm i @coalaura/instant.js

Usage (durations)

import instant from "@coalaura/instant.js";

// Either use seconds
console.log(instant.ago(12345678)); // 4 months ago
console.log(instant.ago(-1234)); // since 20 minutes

// Or specify your duration type
console.log(instant.ago(3, "days")); // 3 days ago
console.log(instant.ago(-14, "minutes")) // since 14 minutes

Usage (dates)

import instant from "@coalaura/instant.js";

// Format a timestamp in your timezone
const myDate = instant.unix(1670610204);

console.log(myDate.format("d.m.Y - h:i:s a P"));
// 09.12.2022 - 07:23:24 pm +01:00

// Or force it to be UTC
console.log(myDate.utc().format("d.m.Y - h:i:s a P"));
// 09.12.2022 - 06:23:24 pm +00:00
Format CharacterDescriptionExample returned values
Day------
dDay of the month, 2 digits with leading zeros01 to 31
DA textual representation of a day, three lettersMon through Sun
jDay of the month without leading zeros1 to 31
l (lowercase "L")A full textual representation of the day of the weekSunday through Saturday
NISO 8601 numeric representation of the day of the week1 (for Monday) through 7 (for Sunday)
SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd or th. Works well with j
wNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
Month------
FA full textual representation of a month, such as January or MarchJanuary through December
mNumeric representation of a month, with leading zeros01 through 12
MA short textual representation of a month, three lettersJan through Dec
nNumeric representation of a month, without leading zeros1 through 12
tNumber of days in the given month28 through 31
Year------
LWhether it's a leap year1 if it is a leap year, 0 otherwise.
YA full numeric representation of a year, at least 4 digits, with - for years BCE.-0055, 0787, 1999, 2003, 10191
yA two digit representation of a yearExamples: 99 or 03
Time------
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds with leading zeros00 through 59
uMilliseconds654
Timezone------
eTimezone identifierUTC, GMT, Atlantic/Azores
ODifference to Greenwich time (GMT) without colon between hours and minutes+0200
PDifference to Greenwich time (GMT) with colon between hours and minutes+02:00
Full Date/Time------
cISO 8601 date2004-02-12T15:19:21+00:00
rRFC 2822/ RFC 5322 formatted dateThu, 21 Dec 2000 16:01:07 +0200
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT)1662731715