Bug: forwardDate fails if the specified time is passed the reference time
Abstract
If the current time is 1:57 AM, passing "1am" with forwardDate: true results in date referencing 1am on the current date.
Instead, since 1:00 AM has already passed by 57 minutes, the result should be 1am the following day.
Realistically, forwardDate: true should never result in a date that is older than the reference date.
Example
Reference Date: May 26th at 01:57 AM
Input: "1am"
Timezone: CDT
const now = new Date(); // 2022-05-26T06:57:55.240Z
chrono.parseDate("1am", now, { forwardDate: true }); // 2022-05-26T06:00:00.000Z
Expected: 2022-05-27T06:00:00.000Z (May 27 @ 1am)
Actual: 2022-05-26T06:00:00.000Z (May 26 @ 1am)
Addendum
Interestingly enough, now that it is 2:00AM, Chrono still insists on using the reference day, instead of the following day.
const now = new Date(); // 2022-05-26T07:14:28.103Z
chrono.parseDate('1am', now, { forwardDate: true }); // 2022-05-26T06:00:00.000Z
I've opened up a PR for this. However, it may be best to pull that PR down locally to build and test it. I'm not 100% confident, since some unrelated tests were failing for me whenever I first cloned the repo.
For some weird reason, my local machine doesn't particularly like this repo. Possibly because my dependency versions might be slightly different (I did notice that the package-lock.json was in the .gitignore for some reason), but I'm not entirely sure.
Thanks for the PR!.
Regarding the error. There was a typescript error/warning that I just fixed today. Could you try again?
For the package-lock.json, I didn't include it because I thought (at the time) it was the best practice to allow automatic patches from dependencies. I guess I was wrong. Will include the put the package-lock.json in the repo soon.
Similarly, presuming a current time of 12:00pm, "today at 3" should be 3pm:
parse(
"today at 3",
{
instant: new Date("2023-12-07T12:00:00.000Z"),
timezone: "GMT"
},
{
forwardDate: true
}
)
The result is:
[
{
"reference": {
"instant": "2023-12-07T12:00:00.000Z",
"timezoneOffset": 0
},
"refDate": "2023-12-07T12:00:00.000Z",
"index": 0,
"text": "today at 3",
"start": {
"_tags": {},
"reference": {
"instant": "2023-12-07T12:00:00.000Z",
"timezoneOffset": 0
},
"knownValues": {
"day": 7,
"month": 12,
"year": 2023,
"hour": 3,
"minute": 0
},
"impliedValues": {
"second": 0,
"millisecond": 0,
"meridiem": 0
}
},
"end": null
}
]
I would expect the result to match the current day at 3pm, rather the result is for 3am.
- Expected: "2023-12-07T15:00:00.000Z" + Received: "2023-12-07T03:00:00.000Z"