Open shichao-an opened 8 years ago
any update on this?
Hello,
The issue seems the same whatever time unit is used, i.e.:
> ['now', 'in 30 seconds', 'in 60 seconds', 'in 99 seconds', 'in 100 seconds'].map(d => console.log(date(d)))
2018-03-16T14:44:24.751Z
2018-03-16T14:44:54.751Z
2018-03-16T14:45:24.756Z
2018-03-16T14:46:03.757Z
2018-03-17T00:00:00.757Z
The maintainer has probably not so much time to fix this, a merge request is probably welcome. @matthewmueller I'll look into it if I have some time.
This issue seems hard to fix without major modifications.
From my current understanding:
ago
or in
words basically change the way the tokenizer should (and cannot) extract tokens.Currently the tokenizer extracts 100
as if it was 1 hour and 00 minutes which results in a replacement of 100
by the token 01:00
, this later token is recognized as an hourMinute
token.
From my point of view, this should at least result in an error instead of a bad result.
100 days ago
is recognized by the library as 1 hour 00 minutes days ago
which seems to be an incorrect way of detailing a past event.
Another way to deal with this would be to systematically interpret plain numbers as periods of time and not as points in time but that would break things like today at 705 pm
(I would rather use today at 7:05 pm
).
Hello
As a workaround, you can split the number of days in multiples series of 'in n days' where n is <100.
ex: instead of doing:
date('in 200 days at 7:00pm)
you can do:
date('in 50 days in 50 days in 50 days in 50 days at 7:00pm')
or:
date('in 99 days in 99 days in 2 days at 7:00pm')
I know it's ugly but it work :)
@matthewmueller Maybe add a note about this to the documentation? Like your numbers must be <100!!!. This is a very unexpected thing.
"100 days ago" or (>= 100 days ago) results in 1:00 a.m. today. "99 days" or (<= 99 days ago) is working correctly.