Handling Non-Gregorian Calendars

I’m trying to create a header for a column of dates that correctly shows the format of the date in the locale in which the computer is working, e.g.'s d/m/y, m/d/y, y/m/d etc

The following gets part of the way there:

[code]//first get the appropriate translated abbreviations for d/m/y in this language
Dim ss() As String = Split(lingo.Y_M_D, “/”)

//use the current local shortdate to determine the order and translation of the d/m/y string
Dim d As New DateTime(2000, 12, 30)

Dim s As String = d.ToString(Nil, datetime.FormatStyles.Short, dateTime.FormatStyles.none)
//s will be a d/m/y string in the local format - not dependent on the language of the app.

If s.IndexOf(“2000”) <> -1 Then
s = ReplaceAll(s, “2000”, Trim(ss(0)))
Elseif s.IndexOf(“00”) <> -1 Then
s = ReplaceAll(s, “00”, Trim(ss(0)))

If s.IndexOf(“12”) <> -1 Then
s = ReplaceAll(s, “12”, Trim(ss(1)))
End If

If s.IndexOf(“30”) <> -1 Then
s = ReplaceAll(s, “30”, Trim(ss(2)))
End If

Return s[/code]

But it doesn’t work for non-Gregorian calendars e.g. Arabic for which the date created by the new DateTime would be different. For example, 2000/12/30 in Saudi comes out as 04/10/1421 AH, whilst in Afghanistan it becomes 10/10/1379 AP - there are probably others too.

Whilst only a small part of the potential market - is there a way to get this right?

Just out of curiosity, why aren’t you using DateTime.FromString and passing in Locale.Current instead of doing all this work?

I am using that for the dates in the column - but that doesn’t give me text in the form of d/m/y to tell the customer what order the dates are in. This is to generate the column header.

Ah. So FWIW, you can’t guarantee that the date delimiter will be a / either. If the user’s locale is one we don’t support, s will be in SQL format: 2000-12-30.

Exactly - that’s why I don’t use the date delimiter to help - just identify the corresponding number for the y, m or d and do a replaceAll - that keeps whatever delimiters have been generated by Xojo or OS. But this doesn’t work if the value of the year, month or date doesn’t match.