question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting to Arabic Language giving wrong Days in Calendar

See original GitHub issue

I am using Example # 2 from Sample, in English language it is giving me correct Days of the Calendar like 1st Jan 2021 is Friday, but if I am changing device Language to Arabic, it is giving me wrong Dates like: 1st Jan 2021 on Saturday. I am using daysOfWeekFromLocale() from Ext for week days and changing my Preferred start of week as Sunday also,

fun daysOfWeekFromLocale(): Array<DayOfWeek> {
    val firstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek
    var daysOfWeek = DayOfWeek.values()
    // Order `daysOfWeek` array so that firstDayOfWeek is at index 0.
    // Only necessary if firstDayOfWeek != DayOfWeek.MONDAY which has ordinal 0.
    if (firstDayOfWeek != DayOfWeek.SUNDAY) {
        val rhs = daysOfWeek.sliceArray(firstDayOfWeek.ordinal..daysOfWeek.indices.last)
        val lhs = daysOfWeek.sliceArray(0 until firstDayOfWeek.ordinal)
        daysOfWeek = rhs + lhs
    }
    return daysOfWeek
}

For reference you can see screenshots from English Language and also from Arabic. Both are from Sample Code Example # 2.

ENGLISH ONE (1st Jan 2021 is Friday) Screen Shot 2021-01-16 at 2 51 42 PM

ARABIC ONE (1st Jan 2021 on Saturday) Screen Shot 2021-01-16 at 2 52 24 PM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
usmankhan1990commented, Jan 16, 2021

Really thank you @kizitonwose . This solution works like a charm. I also did same.

1reaction
kizitonwosecommented, Jan 16, 2021

To ensure that the calendar always starts from Sunday, you need to do two things:

When setting up the headers, do NOT use this:

~val daysOfWeek = daysOfWeekFromLocale()~

Use this instead:

val daysOfWeek = arrayOf(
    DayOfWeek.SUNDAY,
    DayOfWeek.MONDAY,
    DayOfWeek.TUESDAY,
    DayOfWeek.WEDNESDAY,
    DayOfWeek.THURSDAY,
    DayOfWeek.FRIDAY,
    DayOfWeek.SATURDAY
)

Then setup the calendarView like this: calendarView.setup(startMonth, endMonth, DayOfWeek.SUNDAY)

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - ToLongDateString() showing wrong date in Arabic
When you work with ar-AE culture - Arabic language, United Arab Emirates you represent given DateTime as a string according to this culture....
Read more >
Error in converting Hijri Date to Gregorian Date
The conversion documentation shows that the input for Hijri dates should be in the format of "dd/mm/yyyy". Is 30/02/1434 a valid date?
Read more >
Excel Dates Displayed in Different Languages
Excel Dates Displayed in Different Languages using the TEXT Function to easily convert the language for day and month.
Read more >
Change your language setting - Google Calendar Help
Open Google Calendar. Settings. In the "Language" section, choose the language you want to use from the drop-down menu. Changes are automatically saved....
Read more >
Change language in date (year, month, day)
Hi,. I solved this issue by going to "Date Settings" in Windows and changing the regional format to English. Restart Power BI and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found