Moment: fromNow and toNow

Created on 16 Nov 2015  路  1Comment  路  Source: moment/moment

If I understand this right then one of these fromNow and toNow functions should be used for dates in the past and the other for dates in the future? Could there be a new function like relative or something that determines which to use based on if the date provided is in the past or future? Would simplify the application logic.

Most helpful comment

No, the two functions just express opposite relationships:fromNow tells you the _date relative to now_ whereas toNow tells you how to express _now relative to the date_. IOW, what you're calling relative is just fromNow:

> moment("2016-05-25").fromNow()
'in 6 months'
> moment("2015-10-14").fromNow()
'a month ago'

I suspect toNow is rarely used...

>All comments

No, the two functions just express opposite relationships:fromNow tells you the _date relative to now_ whereas toNow tells you how to express _now relative to the date_. IOW, what you're calling relative is just fromNow:

> moment("2016-05-25").fromNow()
'in 6 months'
> moment("2015-10-14").fromNow()
'a month ago'

I suspect toNow is rarely used...

Was this page helpful?
0 / 5 - 0 ratings