Sugar icon indicating copy to clipboard operation
Sugar copied to clipboard

Create date with Finnish locale is broken with 2.0.6 version

Open samiheikki opened this issue 5 years ago • 3 comments

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

samiheikki avatar Mar 01 '19 13:03 samiheikki

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...

andrewplummer avatar Mar 07 '19 00:03 andrewplummer

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

Haprog avatar Dec 19 '19 07:12 Haprog

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

sturdynut avatar Sep 25 '20 23:09 sturdynut