YUI recommends YUI3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

This documentation is no longer maintained.

YUI Library Examples: Calendar Control: Localization - Taiwan (Year Offset)

Calendar Control: Localization - Taiwan (Year Offset)

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.

Setting up the Calendar

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.

Copyright © 2013 Yahoo! Inc. All rights reserved.

Privacy Policy - Copyright Policy - Job Openings