Along with the locale customization parameters covered in the Japanese and German calendar examples, Calendar also supports the ability to set a year offset (from the Gregorian year), which can be used to support locales such as Taiwan (zh-TW), for which the year is 1911 years behind the Gregorian year. This example demonstrates how the year offset field can be used to create a Calendar for the zh-TW locale.
As with the other localization examples, we set up the various label, position and delimiter fields for the Taiwan (zh-TW) localized calendar:
However for the Taiwan localized calendar, we also specify a year offset for the Calendar as shown on line 4 above. The year offset is applied whenever the Calendar renders a year as a string, or accepts a year as string input.
For example, when setting selector dates, or the page date using strings, we use the offset date (the Gregorian year-1911). The months and dates are the same as the Gregorian calendar:
It's important to note that whenever you're working with JavaScript Date objects, the year will/should always be set to the Gregorian year (and not offset by the year_offset amount), since the JavaScript Date object's month and date rollovers and leap year calculations will only work correctly when operating with the year set to the equivalent Gregorian year.
For this reason, any JavaScript Date objects returned by Calendar's methods, will always reflect the Gregorian year, even when a year offset is set, and any Date objects passed into Calendar methods, should reflect the Gregorian year.
You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings