calendars.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. define([ "./Record",
  2. "requirejs-text/text!../cldr/config/calendarDependencies.json",
  3. "../calendars/gregorianCalendar"],
  4. /**
  5. * Functions and data related to implementation of calendars.
  6. *
  7. * @private
  8. */
  9. function (Record, calendarDependenciesJson, gregorianCalendar) {
  10. var calendarMap = {
  11. "gregory" : gregorianCalendar
  12. };
  13. var dependencies = JSON.parse(calendarDependenciesJson);
  14. var calendars = {
  15. calendarMap : calendarMap,
  16. dependencies : dependencies,
  17. /**
  18. *
  19. * Converts the given date to an object representing the date/time as represented
  20. * in a particular calendar.
  21. *
  22. * @param {Date} date The date to convert
  23. * @param {String} calendar The BCP 47 tag representing the calendar type
  24. * @param {String} timeZone String representing the time zone (UTC or local)
  25. * @returns {Ojbect} An object representing the year,month,day,hour,minute,second in the given calendar.
  26. * @private
  27. */
  28. toLocalTime : function (date, calendar, timeZone) {
  29. if (dependencies[calendar] && dependencies[calendar].option) {
  30. return calendarMap[calendar].toLocalTime(date, timeZone, dependencies[calendar].option);
  31. }
  32. return calendarMap[calendar].toLocalTime(date, timeZone);
  33. },
  34. /**
  35. *
  36. * In the Hebrew calendar, determine which month name string to use based on the year. The Hebrew
  37. * calendar has a "leap month", so the set of month names used is variable.
  38. *
  39. * @param {Number} year The year number
  40. * @param {Number} month The year number
  41. * @returns {String} The key for looking up the month name in the CLDR resource file.
  42. * @private
  43. */
  44. hebrewMonthResource : function (year, month) {
  45. var mr;
  46. if (calendarMap.hebrew.isLeapYear(year)) {
  47. mr = ["1", "2", "3", "4", "5", "6", "7-yeartype-leap", "8", "9", "10", "11", "12", "13"];
  48. } else {
  49. mr = ["1", "2", "3", "4", "5", "7", "8", "9", "10", "11", "12", "13"];
  50. }
  51. return mr[month - 1];
  52. }
  53. };
  54. return calendars;
  55. });