You-Dont-Need-Momentjs
You-Dont-Need-Momentjs copied to clipboard
IsBefore with an offset
How would I achieve something like this in native javascript :
moment(viewingDay).isBefore(moment(), 'day');
If this is possible then I can fully ditch moment
You can check out the source code of date-fns/isBefore
and see how they do it.
export default function isBefore (dirtyDate, dirtyDateToCompare, dirtyOptions) {
if (arguments.length < 2) {
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present')
}
var date = toDate(dirtyDate, dirtyOptions)
var dateToCompare = toDate(dirtyDateToCompare, dirtyOptions)
return date.getTime() < dateToCompare.getTime()
}