Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is expected datetime string for ar-sa culture?

I have a method

DateToString(DateTime datetime, string format, CultureInfo cultrueInfo)
{
    return datetime.ToString(format, cultureInfo);
}

Parameters:

datetime: {10/1/2016 12:00:00 AM}
format: "ddd, dd MMM"
cultureInfo: {ar-SA}

But it returns me "السبت, 30 ذو الحجة". October 1st is Saturday. Why it seems return me September 30, Saturday? Anything wrong at my side?

like image 898
spspli Avatar asked Oct 04 '16 00:10

spspli


1 Answers

ar-SA culture uses UmAlQuraCalendar a calendar.

new CultureInfo("ar-SA").Calendar.Dump(); // System.Globalization.UmAlQuraCalendar

Since you used that culture in your ToString method, it will generated a string representation based on that calendar. You can't expect to generate "September" since your culture does not use GregorianCalendar.

enter image description here

In UmAlQuraCalendar, your DateTiem will be represented as 30-12-1437.

var dt = new DateTime(2016, 10, 1);  // Gregorian

var umAlQura = new UmAlQuraCalendar();

umAlQura.GetYear(dt);       // 1437
umAlQura.GetMonth(dt);      // 12
umAlQura.GetDayOfMonth(dt); // 30

https://www.staff.science.uu.nl/~gent0113/islam/ummalqura_converter.htm

That's why:

  • ddd format specifier generates السبت ((Yawm) as-Sabt aka Saturday) since it is the abbreviated day name.
  • dd format specifier generates 30 as expected.
  • MMM format specifier generates ذو الحجة (Dhu al-Hijjah) since it is the abbreviated month name.

As you can see, abbreviated day and month name switched in result. This is probably a Right to left issue.

like image 79
Soner Gönül Avatar answered Oct 01 '22 06:10

Soner Gönül