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

parseDate sets the time forward by an hour for non DST date time #937

Open
c-shetty opened this issue Feb 8, 2023 · 2 comments
Open

parseDate sets the time forward by an hour for non DST date time #937

c-shetty opened this issue Feb 8, 2023 · 2 comments

Comments

@c-shetty
Copy link

c-shetty commented Feb 8, 2023

Hello @rxaviers. parseDate seems to have an issue in parsing a non-DST date time. The issue happens when the local machine's date is the same as the DST start date. Following are the steps I followed to reproduce,

  • Manually set the machine timezone to Eastern Time(UTC - 5) [I don't observe DST so had to do this manually]
  • Manually set the machine date to 12(Jan or Feb doesn't matter) [March 12th is when DST starts in 2023].
  • Run the following code,
var en = Globalize( "en" );
var date = "3/2/2023, 2:00 AM";
en.parseDate(date, { skeleton: "yMdhm" });

Expected result: Thu Mar 02 2023 02:00:00 GMT-0500 (Eastern Standard Time)
Actual result: Thu Mar 02 2023 03:00:00 GMT-0500 (Eastern Standard Time)

Similarly for 24hours format,

var en = Globalize( "en" );
var date = "3/2/2023, 2:00 PM";
en.parseDate(date, { skeleton: "yMdhm" });

Expected result: Thu Mar 02 2023 14:00:00 GMT-0500 (Eastern Standard Time)
Actual result: Thu Mar 02 2023 15:00:00 GMT-0500 (Eastern Standard Time)

@rxaviers
Copy link
Member

rxaviers commented Feb 8, 2023

Please, can you provide additional info? What do you get when formatting such dates? Can you also share the ISO string of the dates you're using (to format)? Thanks

@c-shetty
Copy link
Author

c-shetty commented Feb 8, 2023

@rxaviers

var iso = "2023-03-02T07:00:00.000Z";
var dateToFormat = new Date(iso); // Thu Mar 02 2023 02:00:00 GMT-0500 (Eastern Standard Time)
var formattedDate = Globalize.formatDate(dateToFormat, { skeleton: "yMdhm" });
var parsedDate = Globalize.parseDate(formattedDate, { skeleton: "yMdhm" });

console.log("Formatted date : " + formattedDate);
console.log("Parsed date : " + parsedDate);

Output when the machine's date is Feb 12:

Formatted date : 3/2/2023, 2:00 AM
Parsed date: Thu Mar 02 2023 03:00:00 GMT-0500 (Eastern Standard Time)

Output when the machine's date is other than 12 [I used Feb 11]:

Formatted date : 3/2/2023, 2:00 AM
Parsed date : Thu Mar 02 2023 02:00:00 GMT-0500 (Eastern Standard Time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants