andrewplummer / Sugar

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

Date parsing 'tomorrow' with Korean locale misinterpreted #614

Open ghost opened 7 years ago

ghost commented 7 years ago

Tested on Tuesday September 5th, 2017:

Sugar.Date.create('내일', 'ko'); // tomorrow //--> Sun Sep 10 2017 Sugar.Date.create('오늘', ko') // today //--> Tue Sep 05 2017 Sugar.Date.create('내일', 'ko'); // tomorrow (yet again) //--> Wed Sep 06 2017

I was wondering why creating date of "tomorrow" for the first time shows wrong result, and seems like the following part of locale causing the problem.

...
'weekdays': '일:요일|,월:요일|,화:요일|,수:요일|,목:요일|,금:요일|,토:요일|',
'numerals': '영|제로,일|한,이,삼,사,오,육,칠,팔,구,십',
...
'modifiers': [ ...
  { 'name': 'day', 'src': '내일', 'value': 1 }, //tomorrow
  ...
  { 'name': 'shift', 'src': '다음|내', 'value': 1 } //next
 ]

so, by combination of 내+일 could be tomorrow(내일) or next sunday(내+일). So Sugar.js returns result of '내일' as tomorrow or next sunday.

But in Korea '내일' never means next sunday, so changing

'weekdays': '일:요일|,월:요일|,화:요일|,수:요일|,목:요일|,금:요일|,토:요일|',

to

'weekdays': '일요일|,월요일|,화요일|,수요일|,목요일|,금요일|,토요일|',

would temporarily fix the problem (by removing the case of '내일=next sunday') However, in this way, creating date by single character of weekdays becomes impossible:

Sugar.Date.create('월', 'ko'); // tomorrow //--> Invalid Date Sugar.Date.create('월요일', 'ko'); // tomorrow //--> Mon Sep 04 2017

Any suggestion to fix this this issue? Thank you, have a nice day :)

andrewplummer commented 6 years ago

This one is a bit tricky... I think essentially there needs to be a way to split it up so that weekdays only occur with 다음 and never . The current format makes this rather difficult so I think it will have to be modified.... I'll have a look at this and get back to you... Thanks for reporting!

andrewplummer commented 6 years ago

I had another look at this and as I mentioned before handling this properly will require a change in the current locale format. Fortunately I have something in mind. I put a hack in for now to fix this until the next major release when that can happen.

Rev: 4c72a71c