moment().diff returns negative value

Created on 4 Apr 2012  ·  1Comment  ·  Source: moment/moment

//Wed, 04 Apr 2012 21:09:16 GMT to = moment.utc().add('m', 60).toDate(); seconds = moment.diff(to, 'seconds');
I'm trying to get the seconds from the current time in UTC and another date that is set in UTC.

I'm using moment.diff- the above code returns a negative value of -3600 instead of 3600.

Is this the correct way to do this? Shouldn't the negative only be if the date has passed?

Bug

Most helpful comment

That should be clarified in the docs.

If the moment is earlier than the one you are diffing, it should be negative. If it is after the one you are diffing, it will be positive.

Think of it this way...

var a = moment(),
    b = moment().add('hours', 1);
a.diff(b); // a - b
b.diff(a); // b - a

>All comments

That should be clarified in the docs.

If the moment is earlier than the one you are diffing, it should be negative. If it is after the one you are diffing, it will be positive.

Think of it this way...

var a = moment(),
    b = moment().add('hours', 1);
a.diff(b); // a - b
b.diff(a); // b - a
Was this page helpful?
5 / 5 - 1 ratings

Related issues

ghost picture ghost  ·  3Comments

paulyoung picture paulyoung  ·  3Comments

chitgoks picture chitgoks  ·  3Comments

alvarotrigo picture alvarotrigo  ·  3Comments

benhathaway picture benhathaway  ·  3Comments