winkitee / datetime-streak

A package to find streaks from dates and times.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A package to find streaks from dates and times.

License:MIT License


Languages

Language:TypeScript 70.7%Language:JavaScript 29.3%