datetime-streak
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

datetime-streak

Generic badge Generic badge

A package to find streak from dates and times.

import { getStreak } from "datetime-streak";

// today: 2021-04-08
const dates = [
    new Date(2021, 3, 6, 13, 40, 20), // 2021-04-06
    "2021-04-07T06:40:20.000Z",       // 2021-04-07
    1617888567772,                    // 2021-04-08
    new Date(2021, 3, 8, 12, 00, 20), // 2021-04-08
]; // it also accepts unsorted dates.

const streak = getStreak(dates, "03:00:00");

Returns:

// streak
{
  currentDailyStreak: 3,
  currentWeeklyStreak: 1,
  longestDailyStreak: 3,
  longestWeeklyStreak: 1,
  activityDates: { '2021-04-08': 2, '2021-04-07': 1, '2021-04-06': 1 }
}

Installation

// with npm:
npm install datetime-streak

// or with yarn:
yarn add datetime-streak

Package Sidebar

Install

npm i datetime-streak

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

12.2 kB

Total Files

27

Last publish

Collaborators

  • winkitee