You-Dont-Need-Momentjs icon indicating copy to clipboard operation
You-Dont-Need-Momentjs copied to clipboard

IsBefore with an offset

Open abyrne85 opened this issue 5 years ago • 1 comments

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

abyrne85 avatar Nov 23 '18 12:11 abyrne85

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()
}

stevemao avatar Nov 23 '18 12:11 stevemao