Why doesn't GetDateFormat take a CALID?

by Michael S. Kaplan, published on 2005/05/12 03:21 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2005/05/12/416761.aspx


Meikel Weber posted (in the suggestion box):

Hi,

Your article today reminds me of an old question. Why is there no "GetDateFormat" API that takes a CALID as parameter?

Thank you for this really cool blog!!!

Well, thanks for the kind words. :-)

Some questions are good. In my opinion, this question is excellent. Now rather than letting Meikel and I share a private joke, I will explain....

In the NLS API set, there is an EnumDateFormats function. However, this only allows you to look at the date formats for the currently selected calendar, so an EnumDateFormatsEx function was added. This function will return the formats that apply to not only the default calendar but to all posible alternate calendars.

And then to use the date formats, there is a GetDateFormat function, which like EnumDateFormats is very much centered on the currently selected calendar. Now there is some minor concession to the notion of alternatives, with a DATE_USE_ALT_CALENDAR flag. But there are many limitations to this flag, as the Platform SDK topic describes:

If this flag is set, the function uses the default format for that alternate calendar, rather than using any user overrides. The user overrides will be used only in the event that there is no default format for the specified alternate calendar.

An then it goes on in remarks to give more advice on ways to do lots of work to figure things out:

To obtain the default short and long date format without performing any actual formatting, use the GetLocaleInfo function with the LOCALE_SSHORTDATE or LOCALE_SLONGDATE parameter. To get the date format for an alternate calendar, use GetLocaleInfo with the LOCALE_IOPTIONALCALENDAR parameter. To get the date format for a particular calendar, use GetCalendarInfo. Also, to return all of the date formats for a particular calendar, you can use EnumCalendarInfo or EnumDateFormatsEx.

If all of this sounds like apologetic posturing to try to avoid having to explain that there is no GetDateFormatEx function that takes a CALID parameter, then you have proven the truth in the concept behing Ronan Keating's new song (follow up to "You Say It Best When You Say Nothing At All"), tentatively entitled "NLS Says It Best When It Says Everything But". Congratulations!

Obviously both GetLocaleInfo/LOCALE_IOPTIONALCALENDAR and GetDateFormat/DATE_USE_ALT_CALENDAR are pretty incomplete as workarounds, since the latter has many limitations related to overrides and both assume that there is at most one alternate calendar (which is not always true). And the rest of the suggestions will work, but they do have a serious "do it yourself, some assembly required" factor.

In a future post, maybe I could write one up that would do this sort of thing. :-)

Incidentally, this fact has been noticed by lots of people both inside and outside of Microsoft, and assisting with the limitation is under consideration for future versions of Windows (to be triaged along with other issues in locale APIs).

Again, excellent question!

 

This post brought to you by "ΤΉ" (U+0539, ARMENIAN CAPITAL LETTER TO)


# Bill on 13 May 2005 9:58 PM:

I was wondering how to make GetDateFormat work with other calendars. Any chance of this problem getting fixed?

# Michael S. Kaplan on 13 May 2005 11:00 PM:

Hi Bill!

Well, like I said, many people have noticed this lack before, both inside and outside of Microsoft. It is definitely on the list of things to consider in the future. At this point, there is no way to say when exactly that will be, though. But hang in there....

# Qflash on 15 May 2005 2:39 AM:

RePost:
http://www.yeyan.cn/SoftwareEngineering/GetDateFormatCALID.aspx

referenced by

2006/10/15 Not everything you might want out of a GetDateFormatEx, but think of it as a fixer-upper

go to newer or older post, or back to index or month or day