andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.53k stars 305 forks source link

Parsing a date using fromUTC not working as expected #651

Open raquelgs opened 5 years ago

raquelgs commented 5 years ago

When setting the locale to en-GB the date is parsed 4 hours before expected:

const stringDate = "05/22/2000";
const gb = Sugar.Date.create(stringDate, { fromUTC: true, locale: "en-GB" });
const us = Sugar.Date.create(stringDate, { fromUTC: true, locale: "en-US" });

console.log(gb.toISOString());
// Output: 2000-05-21T20:00:00.000Z 
console.log(us.toISOString());
// Output: 2000-05-22T00:00:00.000Z 

We expect both console.log to be the identical (2000-05-22T00:00:00.000Z).

Is this the expected behaviour? If that's the case, do you know why setting locale to en-GB is changing the parsed date?