Enterprise: Locale: parseDate issue for Arabic?

Created on 10 Feb 2021  路  11Comments  路  Source: infor-design/enterprise

Describe the bug
I think this is a bug, but not really sure. When parsing a date string when Arabic locale / language is used, the return value is an array, not a Date. For example, trying to parse the value of a datepicker (e.g. a date string) into a proper Date.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://design.infor.com/code/ids-enterprise/latest/demo/components/datepicker/example-index?theme=uplift&variant=light&locale=ar-SA
  2. Select any value from the first Datepicker
  3. Open console
  4. Execute Soho.Locale.parseDate($("#date-field-normal").val()) (parse value of datepicker into a proper Date object)

Expected behavior
A Date object is returned.

Actual result
Returns an array, like [1442, 5, 28, 0, 0, 0, 0]

Version

  • ids-enterprise: 4.37.0

Additional context
Similar issue is seen for a datetime string as well.

Compare this to other Locales, for example English, by following the same steps but change the Locale in the URL. A proper Date object is returned for other Locales.

[2] type

All 11 comments

Actually no this is not a bug. The arabic dates do not work as date objects because the months are different so it will adjust them incorrectly so an array must be used. We have to handle this internally by treating dates in arabic as arrays and others as dateobjects.

Not exactly sure of the month but as an example but to illustrate 1442, 1, 31 could be valid in arabic but if you put it on a date object it changes it to the next month. So it must be represented as an array not a date.

new Date(1442, 1, 31) 
Thu Mar 03 1442 00:00:00 GMT-0456 (Eastern Standard Time)
````

Could use this tho...

if (Locale.isIslamic()) {
// its an array
} else {
// its a date
}
```

Oh, I see! Do you have any suggestions on how to "transfer" it into a Date, or is it not even possible?

Perhaps the API reference could be updated with this info?

/**
 * Take a date string written in the current locale and parse it into a Date Object.
  */
parseDate(dateString: string, dateFormat?: string): Date;

We assume it returns a Date, and thus our subsequent Date operations fail, for example date.getTimeZoneOffset()

Its possible but you will get an gregorian date we have two functions...

Locale.gregorianToUmalqura(new Date(new Date(2017, 4, 31)))
Locale.umalquraToGregorian(1431, 11, 25) -> think you want this and you can plug the array positions on here

We also have toGregorian and fromGregorian on formatDate

  expect(Locale.formatDate(Locale.parseDate('1439/10/06', Locale.calendar().dateFormat.short, false), { pattern: 'yyyyMMdd', toGregorian: true })).toEqual('20180620');

Thank you, I'll try this out. I better read up on Hijri calendar :)

But it seems we can't get the time from the array, right? I'm trying out the datetime example here:
https://design.infor.com/code/ids-enterprise/latest/demo/components/datepicker/example-timeformat?theme=uplift&variant=light&locale=ar-SA

But the four last array entries are always 0

No problem the functions are there. But its tricky because they cant be stored as dates.... https://www.islamicfinder.org/islamic-calendar/ is interesting

the array does have the time as far as i know... in that example where are you seeing the problem?

Locale.gregorianToUmalqura(new Date(new Date(2017, 4, 31, 10, 10, 10, 10)))
(7)聽[1438, 8, 5, 10, 10, 10, 10]

Seeing it here
https://design.infor.com/code/ids-enterprise/latest/demo/components/datepicker/example-timeformat?theme=uplift&variant=light&locale=ar-SA

Select any value in last datepicker. Then in dev console
Soho.Locale.parseDate($("#dp4").val())

Hmm actually maybe that last point is a bug.. Also:

new Date()
Wed Feb 10 2021 11:38:19 GMT-0500 (Eastern Standard Time)

But..

Locale.gregorianToUmalqura(new Date(2017, 4, 31))
(7)聽[1438, 8, 5, 0, 0, 0, 0]

So i think somewhere its not including the time part if its unset...

Maybe close this and make an issue for that?

Oh, might work after all. I forgot to specify the dateformat in second argument. With this I'm getting the h and m
Soho.Locale.parseDate($("#dp4").val(), Soho.Locale.calendar().dateFormat.datetime)

Thanks for the help, we'll try to workaround this with the Locale utils available. I'll close this one

Was this page helpful?
0 / 5 - 0 ratings