globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 603 forks source link

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

Open c-shetty opened 1 year ago

c-shetty commented 1 year ago

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,

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 commented 1 year ago

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 commented 1 year ago

@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)