Error "DateTime" in Arabic culture "ar-sa"

I have the following scenario: my site is designed to work with different cultures (mainly in Arabic and English), when a user selects the "ar-sa" culture (from the options of an Internet explorer), all date selection timers are converted to Hijri format. On one of my pages I used the RadTimePicker teletext control, when I launch this page from the visual studio, an error does not appear, but when we expanded this page on the site, the following error appears:

Valid values ​​are from 1318 to 1450 inclusive. Parameter Name: Year

I tried to deploy a page on my colleague's computer (in local IIS), an error appears. Then I tried to deploy it to my computer using IIS this time without errors.

please can someone give me a hint where to start looking for an error

Thanks in advance

+6
source share
5 answers

Any time objects created in .NET using CultureInfo from "ar-sa" will use a UmAlQuraCalendar object, which indicates that valid dates must have their year between 1318 and 1450. Check the .NET documentation for this object and you will see. For my project, I had to download a date without culture, and then check its range against the current range of the culture calendar and the maximum range of the year, and if outside this range, turn the value into a value inside this range before sorting out the time of the date that was given the proper cultural information object. Note that .NET time objects are ALWAYS ALWAYS in gregorian. To see a date as a date in another calendar, you should always look at it through the Calendar object that matches the culture you use.

+1
source

http://www.telerik.com/community/forums/winforms/calendar-and-datetimepicker/valid-values-are-between-1318-and-1450-inclusive-parameter-name-year.aspx covers similar usage.

As for why it runs on one machine and not another, I would suggest that somewhere along the line one of the implicit cultures (CurrentCulture and CurrentUICulture) is used, and this may or may not contradict your explicit use of ar-SA in depending on what it is.

0
source

What server do you host? The date and time format depends on the settings on the computer control panel.

If your site is hosted on an American server, you need to change the datetime context accordingly.

0
source

PUT Culture property as culture = "English (USA)"

<telerik:raddatepicker id="dt_DOB" runat="server" culture="English (United States)"> </telerik:raddatepicker> 

How to use any culture.

0
source

in the code behind, set the culture calendar to always Georgian. See below example with Telerik DateTimePicker on mypage.aspx

mypage.aspx:

 <telerik:RadDateTimePicker ID="CtrlStartPeriod" runat="server"> <DateInput DateFormat="G" DisplayDateFormat="G" runat="server"></DateInput> </telerik:RadDateTimePicker> 

mypage.aspx.cs:

 protected override void OnInit(EventArgs e) { base.OnInit(e); CtrlStartPeriod.DateInput.Culture.DateTimeFormat.Calendar = new GregorianCalendar(); 
0
source

Source: https://habr.com/ru/post/901298/


All Articles