Closed catdad closed 11 years ago
oh interesting, yah this is definitely a bug. the morning default of 8am
should have been overwritten in the last example
I've been trying to look into fixing this bug, but getting stuck as the rAtHour
wont run for date("tomorrow at 9 in the morning")
wont find any matches.
@MatthewMueller any tips to where to look ?
Does it execute: https://github.com/MatthewMueller/date/blob/master/lib/parser.js#L307 ?
the function athour
does execute but the rAtHour
regex doesn't find any matches
the following prints null
var dateStr = "at 9 in morning"
var rAtHour = /^at\s?(\d{1,2})$/;
console.log(rAtHour.exec(dateStr));
Ah okay, well that wouldn't execute because it has the $
on the end.
The athour
function should receive the string at 9
though, which should match.
Oh my example had the wrong dateStr
Now that you mention that, this.str
progressively becomes the following;
test string is "tomorrow at 9 in the morning
at 9 in the morning
9 in the morning
in the morning
the morning
this explains why the rAtHour
regex doesn't run. Looking at the execution of the functions in order
tomorrow
string
number
string
string
morning
@MatthewMueller i've fixed this issue by doing this https://github.com/bulkan/date/commit/749941dc0b0cf1434d9022c8d8f1b69f81122558.
Probably, a better way would be to peek
back once from the number and see if the token
is at
Hey @MatthewMueller should I submit a pull request for the changes in https://github.com/bulkan/date/commit/749941dc0b0cf1434d9022c8d8f1b69f81122558 :question:
@bulkan yep, then i can review
Including morning after the time number overrides to 8am.
Examples:
date("tomorrow morning") // tomorrow morning at 8am
correct-ishdate("tomorrow morning at 9") // tomorrow morning at 9am
correctdate("tomorrow at 9 in the morning") // tomorrow morning at 8am
wrong