MomentJs isAfter bug

On the app I’m managing and building at Warwick WMG I’ve come across a bit of a problem with momentjs and its isAfter method.

It never seems to correctly evaluate two times together and always returns `false` no matter what I pass through it.

So after lots of creative problem solving and searching I came across this jsfiddle article which gave me an alternative which is working.

Below is my solution.


// Not quite the solution, but it works so I can move on!
// CHANGEME: a date to test against, change it to something you want
var dateToTest = moment('2015-02-04 08:00:00').valueOf();
// now
var now = moment().valueOf();
// use a "greater than" eval, rather than isAfter
var x = dateToTest > now;
console.log('isAfterTest', now, '>', dateToTest, x);

view raw

gistfile1.js

hosted with ❤ by GitHub

 

 

By Dan Course

Senior Instructional Designer. Partnerships, people, products, delivery, agile tech and online edu. Naturally curious, innovative and willing to challenge the status quo.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: