On Mon, 12 May 2008, Brian Hirt wrote:

it includes the year (which i do not want). Does anyone have any advice on how to do this other than manually defining and maintaining 200 different format strings outside of DateTime? If it is not possible to print a "day month" string, is this something that might be added to the locale objects? It seems like this would be a common thing that's wanted.

This is definitely something that should be part of the DT::Locale api (if it exists).

It looks like this data does exist in the CLDR XML data, which is key, because the DT::Locale modules are just generated from this data.

If you look at the CLDR data, there's a bit of XML like this:

  <dateTimeFormats>
          <dateTimeFormatLength>
                  <dateTimeFormat>
                          <pattern>{1} {0}</pattern>
                  </dateTimeFormat>
          </dateTimeFormatLength>
          <availableFormats>
                  <dateFormatItem id="HHmm">HH:mm</dateFormatItem>
                  <dateFormatItem id="HHmmss">HH:mm:ss</dateFormatItem>
                  <dateFormatItem id="MMMMd">MMMM d</dateFormatItem>
                  <dateFormatItem id="MMMMdd" draft="unconfirmed">dd 
MMMM</dateFormatItem>
                  <dateFormatItem id="MMMd" 
draft="unconfirmed">d-MMM</dateFormatItem>
                  <dateFormatItem id="MMMdd" draft="unconfirmed">dd 
MMM</dateFormatItem>
                  <dateFormatItem id="MMd" 
draft="unconfirmed">d/MM</dateFormatItem>
                  <dateFormatItem id="Md">M/d</dateFormatItem>
                  <dateFormatItem id="hhmm" draft="unconfirmed">hh:mm 
a</dateFormatItem>
                  <dateFormatItem id="hhmmss" draft="unconfirmed">hh:mm:ss 
a</dateFormatItem>
                  <dateFormatItem id="mmss">mm:ss</dateFormatItem>
                  <dateFormatItem id="yyMM">MM/yy</dateFormatItem>
                  <dateFormatItem id="yyQ">Q yy</dateFormatItem>
                  <dateFormatItem id="yyQQQQ">QQQQ yy</dateFormatItem>
                  <dateFormatItem id="yyyyM" 
draft="unconfirmed">M/yyyy</dateFormatItem>
                  <dateFormatItem id="yyyyMMM">MMM yyyy</dateFormatItem>
          </availableFormats>
  </dateTimeFormats>

I'm pretty sure this is the type of thing you're looking for.

This is definitely a case of patches welcome.

It probably wouldn't be _too_ hard to add support for this.

The starting point is the tools/generate_from_cldr script, which is what generates the various locatel .pm files. It's not the most beautiful code though ;)

If you make the generator include this info I would certainly be willing to add an appropriate API for retrieving it, probably something like:

  $locale->format_for('MMMMd')

since there's so many formats making a mtehod for each seems like a mess.


-dave

/*==========================
VegGuide.Org
Your guide to all that's veg
==========================*/

Reply via email to