New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

same-date

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

same-date

Minimal function that tells you whether dates are within the same year, month, day, or hour. Allows subdividing (e.g. 1/2 year).

latest
Source
npmnpm
Version
2.0.2
Version published
Maintainers
1
Created
Source

same-date

Minimal function that tells you whether dates are within the same year, month, day, or hour. Allows subdividing (e.g. 1/2 year).

Version 2.0.0 makes the options into an object and adds support for using local vs. UTC comparison

Why?

I love moment.js, but for some things (such as date comparison) it's regrettably slow. Until the time comes that it's quick to compare dates in momentjs, this library will come in handy. It's useful for averaging data out over a given time period (i.e. if it's in the same period, average it).

Install

npm install same-date

Usage

import sameDate from 'same-date';

const date1 = new Date('2018-06-26');
const date2 = new Date('2018-06-14');
const date3 = new Date('2019-01-01');
const isSameYear = sameDate(date1, date2, 'year'); // true
const isSameYear2 = sameDate(date1, date3, 'year'); // false
const isSameMonth = sameDate(date1, date2, 'month'); // true
const isSameDay = sameDate(date1, date2, 'day'); // false
const isSameHour = sameDate(date1, date2, 'hour'); // false

// Using the section prop, to subdivide the time period for comparison.
const isSameHalfOfMonth = sameDate(date1, date2, 'month', 2); // false, different halves of the month
const isSameThirdOfMonth = sameDate(date1, date2, 'month', 3); // true, same third of the month

// Version 2.0.0+
const isSameLocalDay = sameDate({date: date1, compareDate: date2, unit: 'day', sections: 1, local: true});

Keywords

same date

FAQs

Package last updated on 06 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts