andrewplummer / Sugar

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

Create date with Finnish locale is broken with 2.0.6 version #648

Open samiheikki opened 5 years ago

samiheikki commented 5 years ago
Sugar.Date.setLocale('fi');
console.log(Sugar.Date.create("15.8.1980")) // Reults in "Invalid Date"

Live demo: https://jsfiddle.net/samiheikki/08k6pozh/5/

This commit seems to break it: https://github.com/andrewplummer/Sugar/commit/d920840a4775d43f320180823fd0b73346178901

andrewplummer commented 5 years ago

Yikes... ok thank you! As a workaround you can mess with the locale file and try moving certain formats from timeParse into parse and/or simply removing the timeMarker prop...

Haprog commented 4 years ago

@andrewplummer Here's another example of the problem. This is a really bad regression. It was working correctly with Sugar v2.0.4 but not anymore in v2.0.5 or v2.0.6. Formatting with Finnish locale still seems to work correctly but parsing of Finnish dates got broken so that it reads the dates as mm.dd.yyyy instead of the correct dd.mm.yyyy.

Sugar v2.0.4:

Sugar.Date.format(new Date(2019, 11, 1), '{short}', 'fi'); // = "1.12.2019" (correct)
Sugar.Date.create('1.12.2019', 'fi'); // = date of December 1st 2019 (correct)

Sugar v2.0.6:

Sugar.Date.format(new Date(2019, 11, 1), '{short}', 'fi'); // = "1.12.2019" (correct)
Sugar.Date.create('1.12.2019', 'fi'); // = date of January 12th 2019 (WRONG, should be December 1st 2019)
sturdynut commented 4 years ago

@andrewplummer

I took a stab at fixing this issue. I very well may not have solved it correctly, however, the test I added confirmed that it does fix the issues mentioned here.