Sugar icon indicating copy to clipboard operation
Sugar copied to clipboard

date create fails on {dd}.{mm}.{yy} with locale

Open thomasf1 opened this issue 7 years ago • 3 comments

It seems the popular german date format of {dd}.{mm}.{yy} causing inconsistent results. Validated with Chrome on the Sugar.js date demo homepage in the console.

Replicate by typing this into the console Sugar.Date.create('29.04.16') -> current date Sugar.Date.create('29.04.16', 'de') -> current date (wrong) Sugar.Date.create('29.04.2016', 'de') -> right date Sugar.Date.create('29.04.16', 'de') -> same code as before, right date now

screen shot 2017-06-08 at 15 08 50

thomasf1 avatar Jun 08 '17 13:06 thomasf1

Greetings!

Try to use {dd}.{MM}.{yyyy}. "MM" instead of "mm". "mm" is for minutes.

P.S. At the top you need to set local: Sugar.Date.setLocale("de").addFormat("{dd}.{MM}.{yyyy}");

Costegillio avatar Jun 21 '17 18:06 Costegillio

@thomasf1 I've confirmed the results you're getting. Also the first date is also wrong... it's not quite the current date, but a few hours ahead. There also appears to be some kind of state being kept. This shouldn't happen, maybe there's something deeper here, but I'll definitely look into it, thanks!

@Costegillio I think @thomasf1's comment is about out-of-the-box date parsing, so he's probably not using addFormat... this seems to be some kind of bug instead.

andrewplummer avatar Jun 22 '17 03:06 andrewplummer

This has taken ages, but I put in a fix. In the end Finnish date parsing allows periods as time marker separators and the standalone time format was interfering with date parsing. I've added code to make the dots in times exclusive to the Finnish locale.

andrewplummer avatar Aug 11 '18 14:08 andrewplummer