Localization trap in Yahoo’s YUI Calendar

June 19th, 2008
life No comments Leave a comment

Quick note to self and others having just wasted several hours trying to get Yahoo’s YUI calendar to work with dates in the format “2008-06-19″.

Working from this example I was only setting the “DATE_FIELD_DELIMITER”. It refused to work, but I struggled on confident that, for once, the americans really had implemented something which wasn’t culturally imperialistic.

Finally I’ve worked out that the “DATE_RANGE_DELIMITER” is already “-” and setting the “DATE_FIELD_DELIMITER” will not override that setting. It will continue parse your date as a range.

eg: So to use dates in yyyy-m-d format change the “DATE_RANGE_DELIMITER” to something else…

var call = new YAHOO.widget.Calendar("calendar");
call.cfg.setProperty("DATE_RANGE_DELIMITER", "+");
call.cfg.setProperty("DATE_FIELD_DELIMITER", "-");
call.cfg.setProperty("MDY_YEAR_POSITION", 1);
call.cfg.setProperty("MDY_MONTH_POSITION", 2);
call.cfg.setProperty("MDY_DAY_POSITION", 3);
call.select("2008-6-21");
call.render();

If you expect it to open at the selected day then don’t run away, there’s more…

The “pagedate” property only wants the month and the year; it can’t handle being fed the date you’ve just used, which is rather irritating. It not only wants you to trim the day off but also tell it the order of month/day strings (as opposed to month/day/year strings). It all starts to add up to lots of code…


call.cfg.setProperty("MY_YEAR_POSITION", 1);
call.cfg.setProperty("MY_MONTH_POSITION", 2);
call.cfg.setProperty("pagedate","2008-06");

  1. No comments yet.
  1. No trackbacks yet.