What is the best practice when dealing with a limited range of supported DateTime values?

I am currently reviewing the globalization process for a project (.net mvc2 application), and for me globalization is a bit new. I noticed that DateTime.ToString () when formatting for some cultures can lead to a redundancy of ArgumentOutOfRangeException for values ​​too far in the past or future. In particular, the calendars used for "ar" and "ar-SA" ( UmAlQuraCalendar ) have very limited minimum and maximum supported dates. When using UmAlQuraCalendar, any date before April 1930 or after May 2029 will result in this. This is easy to observe:

DateTime.ParseExact("1900", "yyyy", CultureInfo.InvariantCulture).ToString("G", new CultureInfo("ar")); 

Forgive my ignorance on this subject, but I wonder what the best practice is here. I would like for me to be able to represent dates earlier than 1930 without having to add exception handling every time I print the date, but I would also like to respect the user's culture. Is it better here to switch to calendars for these cultures? It seems that from some search queries, optionally HijriCalendar is very similar to UmAlQuraCalendar, but with much more relaxed minimum and maximum supported dates. Is this a problem that many people face? I could not find a lot of advice on this particular problem. I hesitate to simply change the default calendar used in these cultures on a whim, without any advice.

+6
source share
1 answer

To achieve the best results in globalization as a whole, strictly adhere to the presentation of cultural invariant data in all areas of your application, except for the level of representation (human interaction); and add a consistent translation layer in the presentation layer for everything that needs to be presented to a person or has been entered by a person.

As for the calendar in particular: many global applications strictly adhere to the Gregorian calendar (although the formatting visible to humans, of course, is localized); some of them support several other calendars that have official status in some countries, but again, this is implemented at the presentation level with minimal impact on the application, and only when it becomes realistic to access these markets or even after production deployments in the area has already begun .

+1
source

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


All Articles