2.0.2 • Published 3 years ago

time-left-ago v2.0.2

Weekly downloads
222
License
MIT
Repository
github
Last release
3 years ago

time-left-ago

Provide time left and time ago

Install

yarn add time-left-ago

Example

timeLeft returns the specified time that left until the provided ttl in seconds, minutes, hours or days.

import { timeLeft } from 'time-left-ago'

const ttl = 40/60
const timeString = timeLeft(new Date(), ttl)
// => 40 seconds left

timeAgo returns the specified date that passed since the provided timestamp in time, day or date.

import { timeAgo } from 'time-left-ago'
import moment from 'moment'

const today = moment() // Sunday
const dayBeforeYesterday = today.subtract(2, 'days')
const dayString = timeAgo(dayBeforeYesterday)
// => Friday

timeAgoFormatted returns the specified date bucketed by minutes, hours or days.

import { timeAgoFormatted } from 'time-left-ago'

const twoDaysAgo = moment(Date.now()).subtract(2, 'days').toString()
const formatted = timeAgoFormatted(twoDaysAgo) // => '2 DAYS'

const twoHoursAgo = moment(Date.now()).subtract(2, 'hours').toString()
const formatted = timeAgoFormatted(twoHoursAgo) // => '2 HOURS'

License

MIT

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago