1

I have the following snippet of Code for Convert Gregorian Date to Hijri Date.

public static string GregoriantoHijri(DateTime gregorianDate)
{
    CultureInfo arCI = new CultureInfo("ar-SA");
    var hijriCalendar = new HijriCalendar();
    hijriCalendar.HijriAdjustment = App_Code.StoreRetrieveSettingsAssist.getHA();
    arCI.DateTimeFormat.Calendar = hijriCalendar;  //CODE FAILS HERE
    string hijriDate = gregorianDate.ToString("dd-MM-yyyy", arCI);

    return hijriDate;
}

This code runs perfectly for my Windows Mobile App which is also posted on Store. However the same code is giving me issues in Xamarin.Android

The Error:

System.ArgumentOutOfRangeException:
Not a valid calendar for the given culture.
Parameter name: value

I don't understand why codes using same .NET base class have issues on different platforms. Can you suggest a workaround cause this doesn't seem to work.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Rahul Jha
  • 1,131
  • 1
  • 10
  • 25
  • If I remember correctly than the counting on android is different than in .NET. January is 0 not 1. So the question is: What is the provided date for the gregorianDate parameter when the exception occures? – tequila slammer May 07 '16 at 19:47
  • @tequilaslammer I am using whatever date is today for Gregorian. Later I plan to add features to convert any date – Rahul Jha May 07 '16 at 19:49

1 Answers1

1

You might want to consider NodaTime. It is supposedly more robust than the native .NET datetime handling, and is supposed to support Hijri.

Jason
  • 86,222
  • 15
  • 131
  • 146