Hi UncleCheese
Thanks for your work on the CalendarModule. The dmy Dates work just fine.
However, I think you'll encounter problems when this module will be widely used, because there are far more date-formatting conventions/styles than just dmy and mdy.
That's why I suggested a template approach instead of the if(dmy) else (mdy). I have thought about this and I would suggest something like the following:
- Create a translatable String for all the different Date-outputs (eg. one day, same month and year, different months etc.)
- These Strings must consist of pre-defined placeholders which will then be replaced by a simple str_replace
Here's how this could look in code:
// example for the getDateString method, same year but different month
// first we get the localized template. Per default we use a american mdy template
// the advantage of this approach is, that every language/localization can have a custom date template
$template = _t(
'EVENTCALENDAR.diffMonthSameYear',
'%{sDayNum}%{sDaySuffix} %{sMonShort} - %{eDayNum}%{eDaySuffix} %{eMonShort}, %{eYearFull}'
);
// array of placeholders. This array should contain all possible variations of
// day, weekday, month, year output
// This won't change it could be a static member of the class
$placeHolders = array(
'%{sWeekDayShort}',
'%{sWeekDayFull}',
'%{sDayNum}',
'%{sDaySuffix}',
'%{sMonNum}',
'%{sMonShort}',
'%{sMonFull}',
'%{sYearShort}',
'%{sYearFull}',
'%{eWeekDayShort}',
'%{eWeekDayFull}',
'%{eDayNum}',
'%{eDaySuffix}',
'%{eMonNum}',
'%{eMonShort}',
'%{eMonFull}',
'%{eYearShort}',
'%{eYearFull}'
);
// populate the replacement array
$replacement = array(
strftime('%a', $start), // sWeekDayShort
strftime('%A', $start), // sWeekDayFull
date ('d', $start), // sDayNum
date ('S', $start), // sDaySuffix
date ('m', $start), // sMonNum
strftime('%b', $start), // sMonShort
strftime('%B', $start), // sMonFull
date ('y', $start), // sYearShort
date ('Y', $start), // sYearFull
// now the same for the end date
strftime('%a', $end), // eWeekDayShort
strftime('%A', $end), // eWeekDayFull
date ('d', $end), // eDayNum
date ('S', $end), // eDaySuffix
date ('m', $end), // eMonNum
strftime('%b', $end), // eMonShort
strftime('%B', $end), // eMonFull
date ('y', $end), // eYearShort
date ('Y', $end), // eYearFull
);
// now all that's left to do is to replace the placeholders in the template
$formattedDate = str_replace($placeHolders, $replacement, $template);
I think this would be a really flexible and extensible approach for the localization problem.
What remains an issue is the localization of the datePicker widget. Maybe you could bundle the localizations that are provided by the widget author: http://jqueryjs.googlecode.com/svn/trunk/plugins/methods/ and include them according to the locale.
Another possibility would be to generate the required javascript automatically. If you look at these localization files they are really simple and could be generated with only using the strftime function.
Another thing that bugs me are the requirements.. yeah, still. I'd really move them to the template files :)
Sorry for length. If you wish, I can implement the date template approach and provide a patch. Most likely you know better where adjustments have to be made though.
Best - Roman
Edit: Ugh. Code formatting turns out really ugly even when using spaces instead of tabs. A developer forum should at least have some usable code parser/formatting. Anyway.. here's a pastebin link: http://pastebin.com/m2a451393