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-divider

v1.1.2

Published

Sequentially divides a period of time into multiple segments of specified duration, the last segment may be of less than the specified duration. Time periods do not contain end times, [startTime, endTime)

Downloads

368

Readme

Time-Divider

Build Status Coverage Status

Sequentially divides a period of time into multiple segments of specified duration, the last segment may be of less than the specified duration. Time periods do not contain end times, [startTime, endTime)

npm install time-divider --save

Eglish | 中文简体

Usage

const { TimeDivider, UNITS } = require('time-divider');

const startTime = 1577462400000; // Sat Dec 28 2019 00:00:00 GMT+0800
const endTime = 1626580800000; // Sun Jul 18 2021 12:00:00 GMT+0800

const chunks = new TimeDivider(startTime, endTime).divide(2, UNITS.MONTH);

console.log(chunks);

console.log(
  chunks.map((chunk) => {
    const { start, end } = chunk;
    return new Date(start).toString() + ' - ' + new Date(end).toString();
  }),
);

Output:

[
  { start: 1577462400000, end: 1582819199999 },
  { start: 1582819200000, end: 1588003199999 },
  { start: 1588003200000, end: 1593273599999 },
  { start: 1593273600000, end: 1598543999999 },
  { start: 1598544000000, end: 1603814399999 },
  { start: 1603814400000, end: 1609084799999 },
  { start: 1609084800000, end: 1614441599999 },
  { start: 1614441600000, end: 1619539199999 },
  { start: 1619539200000, end: 1624809599999 },
  { start: 1624809600000, end: 1626580799999 }
]
[
  'Sat Dec 28 2019 00:00:00 GMT+0800 (中国标准时间) - Thu Feb 27 2020 23:59:59 GMT+0800 (中国标准时间)',
  'Fri Feb 28 2020 00:00:00 GMT+0800 (中国标准时间) - Mon Apr 27 2020 23:59:59 GMT+0800 (中国标准时间)',
  'Tue Apr 28 2020 00:00:00 GMT+0800 (中国标准时间) - Sat Jun 27 2020 23:59:59 GMT+0800 (中国标准时间)',
  'Sun Jun 28 2020 00:00:00 GMT+0800 (中国标准时间) - Thu Aug 27 2020 23:59:59 GMT+0800 (中国标准时间)',
  'Fri Aug 28 2020 00:00:00 GMT+0800 (中国标准时间) - Tue Oct 27 2020 23:59:59 GMT+0800 (中国标准时间)',
  'Wed Oct 28 2020 00:00:00 GMT+0800 (中国标准时间) - Sun Dec 27 2020 23:59:59 GMT+0800 (中国标准时间)',
  'Mon Dec 28 2020 00:00:00 GMT+0800 (中国标准时间) - Sat Feb 27 2021 23:59:59 GMT+0800 (中国标准时间)',
  'Sun Feb 28 2021 00:00:00 GMT+0800 (中国标准时间) - Tue Apr 27 2021 23:59:59 GMT+0800 (中国标准时间)',
  'Wed Apr 28 2021 00:00:00 GMT+0800 (中国标准时间) - Sun Jun 27 2021 23:59:59 GMT+0800 (中国标准时间)',
  'Mon Jun 28 2021 00:00:00 GMT+0800 (中国标准时间) - Sun Jul 18 2021 11:59:59 GMT+0800 (中国标准时间)'
]

UNITS

enum Units {
  Millisecond,
  Second,
  Minute,
  Hour,
  Day,
  Week,
  Month,
  Year,
}

License

MIT © Cody Tseng