Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone parsing reference not working as expected with forwardDate: true specified #553

Open
sarahmaas opened this issue May 13, 2024 · 1 comment
Labels
to-clarify For issues that need more clarification and review

Comments

@sarahmaas
Copy link

sarahmaas commented May 13, 2024

Apologies for all of the setup here for the date, but this is what I'm working with:

// Node for commented results is v18.11.0
var chronoNode = require("chrono-node"); // v2.7.0
var moment = require("moment-timezone"); // v0.5.43
var baseDate = '2020-02-16 10:00:00';
var timeZoneId = 'America/New_York';
var momentDate = moment(baseDate).tz(timeZoneId, true);
var jsDate = momentDate.toDate(); 
// Tue Feb 18 2020 07:00:00 GMT-0800 (Pacific Standard Time)
var timezoneAbbr = moment(momentDate).tz(timeZoneId).zoneAbbr();
// EST
const referenceDate = {
	instant: jsDate,
	timezone: timezoneAbbr
};

function testParser(text, referenceDate) {
    let result;
    result = chronoNode.parseDate(text, referenceDate);
    console.log(result);

    result = chronoNode.parseDate(text, referenceDate, { forwardDate: true });
    console.log(result);

    result = chronoNode.parse(text, referenceDate);
    console.log(result);

    result = chronoNode.parse(text, referenceDate, { forwardDate: true });
    console.log(result);
}

testParser('every week on Sunday at noon', referenceDate); // after both timezones
/* gives dates:
Sun Feb 16 2020 09:00:00 GMT-0800 (Pacific Standard Time)
Sun Feb 16 2020 09:00:00 GMT-0800 (Pacific Standard Time)
This is working as expected, since it is two hours before noon in the referenced timezone.
*/

testParser('every week on Sunday at 8 AM', referenceDate); // before both timezones
/* gives dates:
Sun Feb 16 2020 05:00:00 GMT-0800 (Pacific Standard Time)
Sun Feb 23 2020 05:00:00 GMT-0800 (Pacific Standard Time)
Also working as expected
*/

testParser('every week on Sunday at 10 AM', referenceDate); // exact time it is currently
/* gives dates without, then with forwardDate:
Sun Feb 16 2020 07:00:00 GMT-0800 (Pacific Standard Time)
Sun Feb 16 2020 07:00:00 GMT-0800 (Pacific Standard Time)
Also working as expected
*/

testParser('every week on Sunday at noon starting Feb 16', referenceDate); // today, in two hours
/* gives dates without, then with forwardDate:
Sun Feb 16 2020 09:00:00 GMT-0800 (Pacific Standard Time)
Sun Feb 16 2020 09:00:00 GMT-0800 (Pacific Standard Time)
Also working as expected
*/

testParser('every 8 weeks on Sunday at noon starting Feb 16', referenceDate); // today, in two hours
/* gives dates without, then with forwardDate:
Sun Feb 16 2020 09:00:00 GMT-0800 (Pacific Standard Time)
Sun Apr 12 2020 13:00:00 GMT-0700 (Pacific Daylight Time) 
potentially expected date because it's dropping 'every', but not expected time
*/

This is adding 5 hours to what should be a 3 hour time difference with a daylight savings change of 1 hour in that time frame. It seems to be related to parse adding the implied value of timezoneOffset: -480.

@wanasit
Copy link
Owner

wanasit commented Aug 10, 2024

Sorry, I don't understand the setup and question.

First, Chrono doesn't support "every" or "every week" out-of-box. Is this some additional part that you date?

Second, from what I tested, the input 'every 8 weeks [on Sunday at noon] starting [Feb 16]' should output two separate results, which one are you referring to that has the problem?

If you believe the problem is related to the timezone, could you provide a short example around that daylight-saving window change?

@wanasit wanasit added the to-clarify For issues that need more clarification and review label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-clarify For issues that need more clarification and review
Projects
None yet
Development

No branches or pull requests

2 participants