Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsBefore with an offset #61

Open
abyrne85 opened this issue Nov 23, 2018 · 1 comment
Open

IsBefore with an offset #61

abyrne85 opened this issue Nov 23, 2018 · 1 comment

Comments

@abyrne85
Copy link

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

@stevemao
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants