npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

time-remaining

v1.0.1

Published

This is the repository for time-remaining

Downloads

1

Readme

time-remaining

This is the repository for time-remaining

example

let date = new Date(86400000)
console.log(date.getTime()) // 86400000
console.log(date.toUTCString()) // "Fri, 02 Jan 1970 00:00:00 GMT"
let timezoneOffset = date.getTimezoneOffset() // -480 minutes
let newDate = toLocalDate(getEndHour(date), timezoneOffset)
console.log(newDate.getTime()) // 61199999
console.log(newDate) // Fri Jan 02 1970 00:59:59 GMT+0800
console.log(newDate.toUTCString()) // "Thu, 01 Jan 1970 16:59:59 GMT"

test

toMS,timeOptionsToMS,isTimeOptionsEmpty,toTimeOptions

test('toMS', () => {
    expect(toMS('millisecond', 1)).toBe(1)
    expect(toMS('second', 1)).toBe(1000)
    expect(toMS('minute', 1)).toBe(60000)
    expect(toMS('hour', 1)).toBe(3600000)
    expect(toMS('day', 1)).toBe(86400000)
})

test('timeOptionsToMS', () => {
    expect(
        timeOptionsToMS({
            millisecond: 1,
            second: 1,
            minute: 1,
            hour: 1,
            day: 1,
        })
    ).toBe(90061001)
})

test('isTimeOptionsEmpty', () => {
    expect(isTimeOptionsEmpty({})).toBe(true)

    expect(
        isTimeOptionsEmpty({
            millisecond: 1,
        })
    ).toBe(false)
})

test('toTimeOptions', () => {
    expect(toTimeOptions(90061001)).toStrictEqual({
        millisecond: 1,
        second: 1,
        minute: 1,
        hour: 1,
        day: 1,
    })

    expect(toTimeOptions(0)).toStrictEqual({
        millisecond: 0,
        second: 0,
        minute: 0,
        hour: 0,
        day: 0,
    })
})

getEndSecond,getEndMinute,getEndHour,getEndDay,getEndWeek,getEndMonth

describe.each([
    new Date(86400000)
])('get end of the time ', (date) => {
    test('getEndSecond', () => {
        const end = getEndSecond(date)
        expect(end.getTime()).toBe(86400999)
    })

    test('getEndMinute', () => {
        const end = getEndMinute(date)
        expect(end.getTime()).toBe(86459999)
    })

    test('getEndHour', () => {
        const end = getEndHour(date)
        expect(end.getTime()).toBe(89999999)
    })

    test('getEndDay', () => {
        const end = getEndDay(date)
        expect(end.getTime()).toBe(172799999)
    })

    test('getEndWeek', () => {
        const end = getEndWeek(date)
        expect(end.getTime()).toBe(345599999)
    })

    test('getEndMonth', () => {
        const end = getEndMonth(date)
        expect(end.getTime()).toBe(2678399999)
    })
})

getRemainingMS,getRemainingSecond,getRemainingMinute,getRemainingHour,getRemainingDay

describe.each([
    new Date(86400000)
])('get the remaining time', (date) => {
    test('getRemainingMS', () => {
        expect(getRemainingMS(date)).toBe(999)
    })

    test('getRemainingSecond', () => {
        expect(getRemainingSecond(date)).toBe(59999)
    })

    test('getRemainingMinute', () => {
        expect(getRemainingMinute(date)).toBe(3599999)
    })

    test('getRemainingHour', () => {
        expect(getRemainingHour(date)).toBe(86399999)
    })

    test('getRemainingDay', () => {
        expect(getRemainingDay(date)).toBe(259199999)
    })
})

toLocalDate

describe.each([
    new Date(86400000)
])('get the local date', (date) => {
    test('getEndSecond', () => {
        const newDate = toLocalDate(getEndSecond(date), -480)
        expect(newDate.getTime()).toBe(57600999)
    })

    test('getEndMinute', () => {
        const newDate = toLocalDate(getEndMinute(date), -480)
        expect(newDate.getTime()).toBe(57659999)
    })

    test('getEndHour', () => {
        const newDate = toLocalDate(getEndHour(date), -480)
        expect(newDate.getTime()).toBe(61199999)
    })

    test('getEndDay', () => {
        const newDate = toLocalDate(getEndDay(date), -480)
        expect(newDate.getTime()).toBe(143999999)
    })

    test('getEndWeek', () => {
        const newDate = toLocalDate(getEndWeek(date), -480)
        expect(newDate.getTime()).toBe(316799999)
    })

    test('getEndMonth', () => {
        const newDate = toLocalDate(getEndMonth(date), -480)
        expect(newDate.getTime()).toBe(2649599999)
    })
})

toLocalMS

describe.each([
    new Date(86400000)
])('get the local time', (date) => {
    test('getRemainingMS', () => {
        const ms = toLocalMS(getRemainingMS(date), -480)
        expect(ms).toEqual(999)
    })

    test('getRemainingSecond', () => {
        const ms = toLocalMS(getRemainingSecond(date), -480)
        expect(ms).toEqual(59999)
    })

    test('getRemainingMinute', () => {
        const ms = toLocalMS(getRemainingMinute(date), -480)
        expect(ms).toEqual(3599999)
    })

    test('getRemainingHour', () => {
        const ms = toLocalMS(getRemainingHour(date), -480)
        expect(ms).toEqual(57599999)
    })

    test('getRemainingDay', () => {
        const ms = toLocalMS(getRemainingDay(date), -480)
        expect(ms).toEqual(230399999)
    })
})