Skip to content

benvh/instants

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intants

Human friendly dates

Usage

Use your favorite node package manager; e.g. yarn, to install

$ yarn add instants --dev

Or simply download instants.min.js and include into your web project yourself. The library exposes itself as the Instants property on window.

Api docs

https://benvh.tech/instants

Typescript

Typescript definition files can be found in the types folder.

Example

import { Instant, Timezone } from 'instants';

// instants are like date objects
const now = new Instant();

// instants can be jumper forward/backward in time
const tomorrow = now.days(1).later();
const yesterday = now.days(1).earlier();
const nextWeek = now.weeks(1).later();

// jumping can be chained
const fiveHoursThreeMinutesAndTwentySecondsAgo = now.hours(5).minutes(3).seconds(20).earlier();

// or whatever
const someMomentInTime = now.years(20).earlier().hours(5).minutes(10).later().days(10).earlier();

// Timezones manipulate the time that is diplayed by an Instant.
// By default the local timezone is applied.
const localTimezone = Timezone.local();

// Modify the timezone property where needed
yesterday.timezone = Timezone.CEST;

// Or use a Timezone to create Instants with that Timezone applied.
const nowUTC = Timezone.UTC.applyTo(now);
const nowPST = Timezone.PST.applyTo(now);
const nowPDT = Timezone.PDT.applyTo(now);

// You can also create your own "timezones". They're simply offsets...
yesterday.timezone = new Timezone(-4.75);