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 is an hour off with DST date #689

Closed
dwbruhn opened this issue Feb 15, 2017 · 1 comment
Closed

parseDate is an hour off with DST date #689

dwbruhn opened this issue Feb 15, 2017 · 1 comment

Comments

@dwbruhn
Copy link

dwbruhn commented Feb 15, 2017

Hi @rxaviers, parseDate appears to have a bug in parsing a DST date.

My environment:

  • OS X El Capitan
  • Node 4.7.0
  • America/Los_Angeles

Here's a Node script that demonstrates the problem. Note that the summer date is 5:32am PDT, but after globalize parse it's 4:32am PDT:

var Globalize = require("globalize");

Globalize.load(
    require("cldr-data/main/en/ca-gregorian"),
    require("cldr-data/main/en/dateFields"),
    require("cldr-data/main/en/timeZoneNames"),
    require("cldr-data/main/en/numbers"),
    require("cldr-data/supplemental/likelySubtags"),
    require("cldr-data/supplemental/timeData"),
    require("cldr-data/supplemental/weekData")
);

Globalize.locale("en");

var winterDateISO = "2015-01-26T01:02:03.000Z";
var winterDate = new Date(winterDateISO); // Sun Jan 25 2015 17:02:03 GMT-0800 (PST)

var summerDateISO = "2015-06-01T12:32:46.000Z";
var summerDate = new Date(summerDateISO); // Mon Jun 01 2015 05:32:46 GMT-0700 (PDT)

var options = { datetime: "full" };

var winterDateFormatted = Globalize.formatDate(winterDate, options);
console.log("Winter Formatted:", winterDateFormatted); // "Sunday, January 25, 2015 at 5:02:03 PM GMT-08:00"
var winterDateParsed = Globalize.parseDate(winterDateFormatted, options);
console.log("Winter Parsed:", winterDateParsed); // Sun Jan 25 2015 17:02:03 GMT-0800 (PST)
console.log("Dates Match:", winterDate.getTime() === winterDateParsed.getTime()); // true

console.log();

var summerDateFormatted = Globalize.formatDate(summerDate, options);
console.log("Summer Formatted:", summerDateFormatted); // "Monday, June 1, 2015 at 5:32:46 AM GMT-07:00"
var summerDateParsed = Globalize.parseDate(summerDateFormatted, options);
console.log("Summer Parsed:", summerDateParsed); // Mon Jun 01 2015 04:32:46 GMT-0700 (PDT) (!!! One hour earlier)
console.log("Dates Match:", summerDate.getTime() === summerDateParsed.getTime()); // false

Output:

Winter Formatted: Sunday, January 25, 2015 at 5:02:03 PM GMT-08:00
Winter Parsed: Sun Jan 25 2015 17:02:03 GMT-0800 (PST)
Dates Match: true

Summer Formatted: Monday, June 1, 2015 at 5:32:46 AM GMT-07:00
Summer Parsed: Mon Jun 01 2015 04:32:46 GMT-0700 (PDT)
Dates Match: false

I have a hunch that if this were summer right now, it would be the winterDate failing. 😄

@rxaviers rxaviers added the bug label Feb 15, 2017
@rxaviers
Copy link
Member

Thanks, bug confirmed. Root cause: this needs to be calculated in here, i.e., after all date sets are complete.

rxaviers added a commit to rxaviers/globalize that referenced this issue Feb 21, 2017
- Handle special case when target date and today date are in different
  DST rules;

Fixes globalizejs#689
rxaviers added a commit to rxaviers/globalize that referenced this issue Feb 23, 2017
- Handle special case when target date and today date are in different
  DST rules;

Fixes globalizejs#689
mwistrand pushed a commit to mwistrand/i18n that referenced this issue Mar 14, 2017
Implements a workaround for a Globalize.js bug
(globalizejs/globalize#689) that incorrectly
parses date strings when the resulting date follows a different rule
from today's date (e.g., the parsed date is in standard time while
today's date is in daylight savings time).
mwistrand pushed a commit to dojo/i18n that referenced this issue Mar 15, 2017
* Implement a workaround for a Globalize.js bug
(globalizejs/globalize#689) that incorrectly
parses date strings when the resulting date follows a different rule
from today's date (e.g., the parsed date is in standard time while
today's date is in daylight savings time).

* Temporarily pin Globalize.js version to prevent the `fixParsedDate`
method from breaking on the next release of Globalize.js.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants