https://github.com/benvh/instants
Human friendly dates
https://github.com/benvh/instants
dates javascript library time
Last synced: 3 months ago
JSON representation
Human friendly dates
- Host: GitHub
- URL: https://github.com/benvh/instants
- Owner: benvh
- License: gpl-3.0
- Created: 2018-06-04T17:45:29.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-04T17:52:56.000Z (about 8 years ago)
- Last Synced: 2025-12-27T04:21:02.019Z (6 months ago)
- Topics: dates, javascript, library, time
- Language: TypeScript
- Homepage: https://benvh.tech/instants
- Size: 175 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Intants
Human friendly dates
## Usage
Use your favorite node package manager; e.g. yarn, to install
```sh
$ 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](https://benvh.tech/instants)
## Typescript
Typescript definition files can be found in the `types` folder.
## Example
```javascript
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);
```