Forum OpenACS Q&A: Response to Globalization - date formatting

Collapse
Posted by Tilmann Singer on
There are lots of places where formats are hardcoded in to_char() calls, so as initially discussed in this thread. I grepped through the toolkit for such format strings to find the most commonly used. Below is a list of the results with an occurence greater than 5. The only thing that can be said by looking at the results is that currently the toolkit uses a wild mixture of format strings ...

It would be a step towards internationalization if we had some centrally defined pl/sql functions that do that formatting instead of using to_char(), so I'd like to suggest to introduce the following ones:

acs_dt__time (just the time, e.g. "6:00 PM")
acs_dt__date (just a date, e.g. "12/31/2002")
acs_dt__date_long (date in longer format, like "December 31, 2002")
acs_dt__datetime - both date and time
acs_dt__datetime_long - both date and time in a longer format

Is that sufficient?

I think acs-datetime is the right place to add this stuff, but then this package would have to be made part of the always required packages.

Also what would be the best approach to allow for changing locales per request? So that it can be set up in a way that on the same server acs_dt__date(some_date) produces "31.12.2002" for a german user and "12/31/2002" for an english speaking user?

The only solution I can currently think of is to add a second parameter that passes the request's locale down to the pl/sql level. That would make a .tcl page with a query look like this:

set locale [ad_some_yet_to_write_locale_function]
db_1row getdate {
        select acs_dt__date(some_date, :locale) from bla
}

Looks a bit tedious to me. Any better solutions?

List of grep results follows.

{YYYY-MM-DD HH24:MI:SS} 86
yyyy-mm-dd 55
YYYY 46
HH24:MI 42
{Month DD, YYYY} 38
{Mon. DD, YYYY} 35
{MM/DD/YYYY HH24:MI} 19
HH:MIpm 18
{MM/DD/YY HH:MI AM} 18
{Mon DD, YYYY} 16
YYYY-MM-DD 15
MM/DD/YYYY 13
HH24 13
J 12
Q 12
{YYYY MM DD HH24 MI SS} 11
MM-DD-YYYY 11
YYYYMM 11
{Mon DD} 9
{HH24:MI:SS Mon DD, YYYY} 7
{MM-DD-YYYY HH12:MI:AM} 6
{HH24:MI, Mon DD, YYYY} 6
mm/dd/yyyy 6
{Mon fmDDfm, YYYY HH24:MI:SS} 6
{MM/DD HH24} 6
{Month DD, YYYY HH:Mi am} 6
hh24:mi:ss 6
{yyyy-mm-dd hh24:mi:ss} 6
{Month DD, YYYY HH:MI:SS} 6
{Day Month DD, YYYY} 6
YYYYMMDD 6
MMDDYY 6
{Mon DD, YYYY HH:MI:SS PM} 6
9999.9 6
{YYYY-MM-DD HH24:MI} 6
fmMM/DDfm/YYYY 6
{MM/DD/YY hh12:Mi am} 6