Closed Techn1x closed 2 years ago
Might be a bit late but, in version 2.7.0 of momentjs, both min
and max
are deprecated here but I have found a workaround.
You can create a helper than takes an argument that is a time, and then inside the helper it compares a new Date()
variable to the argument passed into the helper, it checks if the argument is greater than the new variable created, and if it is it will return the new variable fromNow()
, otherwise it returns the argument fromNow()
.
Hope this helps.
Thanks @Straightline I'll probably do something similar to what you described. Thinking I'll extend the existing moment-from-now
helper and add new args min
and max
, so that it still has support for interval
.
Whenever I get around to it I'll make sure I post the code here, even though it's been a year since the issue was created, this has just been a fairly minor issue for our site.
So I've recently come up against an issue where my server and clients can be slightly out of sync, so the time that the server reports to the client for an action that has always happened in the past, can sometimes look to the client to be a few seconds in the future.
For example, my current code is
If the server gives the client a time that is a few seconds in the future, it shows up as 'in a few seconds' - whereas I would just like it to say 'a few seconds ago'. Essentially I want my
moment-from-now
to always be based in the past.This seems to have been solved in moment.js (after some discussion) by using moment().min() and moment().max() methods https://github.com/moment/moment/issues/537 https://github.com/moment/moment/pull/755 https://github.com/moment/moment/pull/800
Unfortunately it doesn't seem ember-moment implements min/max (in handlebars)? Or am I missing something? What would be the best way to achieve what I'm after?
I tried this, but it didn't seem to update the time at the supplied interval
Thanks