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
; const date1 = '2018-06-26';const date2 = '2018-06-14';const date3 = '2019-01-01';const isSameYear = ; // trueconst isSameYear2 = ; // falseconst isSameMonth = ; // trueconst isSameDay = ; // falseconst isSameHour = ; // false // Using the section prop, to subdivide the time period for comparison.const isSameHalfOfMonth = ; // false, different halves of the monthconst isSameThirdOfMonth = ; // true, same third of the month // Version 2.0.0+const isSameLocalDay = ;