dateintervalformat_test.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // Copyright 2017 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.module('goog.i18n.DateIntervalFormatTest');
  15. goog.setTestOnly('goog.i18n.DateIntervalFormatTest');
  16. var DateIntervalFormat = goog.require('goog.i18n.DateIntervalFormat');
  17. var DateRange = goog.require('goog.date.DateRange');
  18. var DateTime = goog.require('goog.date.DateTime');
  19. var DateTimeFormat = goog.require('goog.i18n.DateTimeFormat');
  20. var DateTimeSymbols_ar = goog.require('goog.i18n.DateTimeSymbols_ar');
  21. var DateTimeSymbols_en = goog.require('goog.i18n.DateTimeSymbols_en');
  22. var DateTimeSymbols_fr_CA = goog.require('goog.i18n.DateTimeSymbols_fr_CA');
  23. var DateTimeSymbols_gl = goog.require('goog.i18n.DateTimeSymbols_gl');
  24. var DateTimeSymbols_hi = goog.require('goog.i18n.DateTimeSymbols_hi');
  25. var DateTimeSymbols_zh = goog.require('goog.i18n.DateTimeSymbols_zh');
  26. var GoogDate = goog.require('goog.date.Date');
  27. var Interval = goog.require('goog.date.Interval');
  28. var TimeZone = goog.require('goog.i18n.TimeZone');
  29. var dateIntervalPatterns = goog.require('goog.i18n.dateIntervalPatterns');
  30. var dateIntervalSymbols = goog.require('goog.i18n.dateIntervalSymbols');
  31. var object = goog.require('goog.object');
  32. var testSuite = goog.require('goog.testing.testSuite');
  33. /** @const {!Object<string, !Object>} */
  34. var localeSymbols = {
  35. 'ar': {
  36. DateIntervalSymbols: dateIntervalSymbols.DateIntervalSymbols_ar,
  37. DateTimeSymbols: DateTimeSymbols_ar
  38. },
  39. 'en': {
  40. DateIntervalSymbols: dateIntervalSymbols.DateIntervalSymbols_en,
  41. DateTimeSymbols: DateTimeSymbols_en
  42. },
  43. 'fr_CA': {
  44. DateIntervalSymbols: dateIntervalSymbols.DateIntervalSymbols_fr_CA,
  45. DateTimeSymbols: DateTimeSymbols_fr_CA
  46. },
  47. 'gl': {
  48. DateIntervalSymbols: dateIntervalSymbols.DateIntervalSymbols_gl,
  49. DateTimeSymbols: DateTimeSymbols_gl
  50. },
  51. 'hi': {
  52. DateIntervalSymbols: dateIntervalSymbols.DateIntervalSymbols_hi,
  53. DateTimeSymbols: DateTimeSymbols_hi
  54. },
  55. 'zh': {
  56. DateIntervalSymbols: dateIntervalSymbols.DateIntervalSymbols_zh,
  57. DateTimeSymbols: DateTimeSymbols_zh
  58. }
  59. };
  60. /**
  61. * @param {string} locale
  62. * @param {!Array<number>} firstDate
  63. * @param {!Array<number>} secondDate
  64. * @param {number|!dateIntervalSymbols.DateIntervalPatternMap} pattern
  65. * @param {string} expected
  66. * @constructor
  67. */
  68. var Data = function(locale, firstDate, secondDate, pattern, expected) {
  69. this.locale = locale;
  70. this.firstDate = firstDate;
  71. this.secondDate = secondDate;
  72. this.pattern = pattern;
  73. this.expected = expected;
  74. };
  75. /**
  76. * @return {string} Error description.
  77. */
  78. Data.prototype.getErrorDescription = function() {
  79. return 'Error for locale:' + this.locale + ' firstDate:\'' + this.firstDate +
  80. '\' secondDate:\'' + this.secondDate + '\'';
  81. };
  82. // clang-format off
  83. var formatTestData = [
  84. new Data('en', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_en.YEAR_FULL, '2007'),
  85. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_en.YEAR_FULL, '2007'),
  86. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.YEAR_FULL, '2007'),
  87. new Data('en', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.YEAR_FULL, '2007'),
  88. new Data('en', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.YEAR_FULL, '2007'),
  89. new Data('en', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.YEAR_FULL, '2007 – 2008'),
  90. new Data('en', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_en.MONTH_DAY_FULL, 'January 10'),
  91. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_en.MONTH_DAY_FULL, 'January 10'),
  92. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.MONTH_DAY_FULL, 'January 10'),
  93. new Data('en', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.MONTH_DAY_FULL, 'November 10 – 20'),
  94. new Data('en', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.MONTH_DAY_FULL, 'October 10 – November 10'),
  95. new Data('en', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.MONTH_DAY_FULL, 'October 10, 2007 – October 10, 2008'),
  96. new Data('en', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_en.DAY_ABBR, '10'),
  97. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_en.DAY_ABBR, '10'),
  98. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.DAY_ABBR, '10'),
  99. new Data('en', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.DAY_ABBR, '10 – 20'),
  100. new Data('en', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.DAY_ABBR, '10/10 – 11/10'),
  101. new Data('en', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.DAY_ABBR, '10/10/2007 – 10/10/2008'),
  102. new Data('en', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_en.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, 'Wed, Jan 10, 2007'),
  103. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_en.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, 'Wed, Jan 10, 2007'),
  104. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, 'Wed, Jan 10, 2007'),
  105. new Data('en', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, 'Sat, Nov 10 – Tue, Nov 20, 2007'),
  106. new Data('en', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, 'Wed, Oct 10 – Sat, Nov 10, 2007'),
  107. new Data('en', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_en.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, 'Wed, Oct 10, 2007 – Fri, Oct 10, 2008'),
  108. new Data('en', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], DateTimeFormat.Format.SHORT_TIME, '10:10 AM'),
  109. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], DateTimeFormat.Format.SHORT_TIME, '10:00 – 10:20 AM'),
  110. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], DateTimeFormat.Format.SHORT_TIME, '10:00 AM – 2:10 PM'),
  111. new Data('en', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], DateTimeFormat.Format.SHORT_TIME, '11/10/2007, 10:10 AM – 11/20/2007, 10:10 AM'),
  112. new Data('en', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], DateTimeFormat.Format.SHORT_TIME, '10/10/2007, 10:10 AM – 11/10/2007, 10:10 AM'),
  113. new Data('en', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], DateTimeFormat.Format.SHORT_TIME, '10/10/2007, 10:10 AM – 10/10/2008, 10:10 AM'),
  114. new Data('en', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], DateTimeFormat.Format.SHORT_DATETIME, '1/10/07, 10:10 AM'),
  115. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], DateTimeFormat.Format.SHORT_DATETIME, '1/10/07, 10:00 – 10:20 AM'),
  116. new Data('en', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], DateTimeFormat.Format.SHORT_DATETIME, '1/10/07, 10:00 AM – 2:10 PM'),
  117. new Data('en', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], DateTimeFormat.Format.SHORT_DATETIME, '11/10/07, 10:10 AM – 11/20/07, 10:10 AM'),
  118. new Data('en', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], DateTimeFormat.Format.SHORT_DATETIME, '10/10/07, 10:10 AM – 11/10/07, 10:10 AM'),
  119. new Data('en', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], DateTimeFormat.Format.SHORT_DATETIME, '10/10/07, 10:10 AM – 10/10/08, 10:10 AM'),
  120. new Data('ar', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_ar.MONTH_DAY_ABBR, '١٠ يناير'),
  121. new Data('ar', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_ar.MONTH_DAY_ABBR, '١٠ يناير'),
  122. new Data('ar', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_ar.MONTH_DAY_ABBR, '١٠ يناير'),
  123. new Data('ar', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_ar.MONTH_DAY_ABBR, '١٠–٢٠ نوفمبر'),
  124. new Data('ar', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_ar.MONTH_DAY_ABBR, '١٠ أكتوبر – ١٠ نوفمبر'),
  125. new Data('ar', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_ar.MONTH_DAY_ABBR, '١٠ أكتوبر، ٢٠٠٧ – ١٠ أكتوبر، ٢٠٠٨'),
  126. new Data('fr_CA', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_fr_CA.MONTH_DAY_MEDIUM, '10 janvier'),
  127. new Data('fr_CA', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_fr_CA.MONTH_DAY_MEDIUM, '10 janvier'),
  128. new Data('fr_CA', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_fr_CA.MONTH_DAY_MEDIUM, '10 janvier'),
  129. new Data('fr_CA', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_fr_CA.MONTH_DAY_MEDIUM, '10–20 novembre'),
  130. new Data('fr_CA', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_fr_CA.MONTH_DAY_MEDIUM, '10 octobre – 10 novembre'),
  131. new Data('fr_CA', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_fr_CA.MONTH_DAY_MEDIUM, '10 octobre 2007 – 10 octobre 2008'),
  132. new Data('gl', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_gl.YEAR_MONTH_FULL, 'Xaneiro de 2007'),
  133. new Data('gl', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_gl.YEAR_MONTH_FULL, 'Xaneiro de 2007'),
  134. new Data('gl', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_gl.YEAR_MONTH_FULL, 'Xaneiro de 2007'),
  135. new Data('gl', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_gl.YEAR_MONTH_FULL, 'Novembro de 2007'),
  136. new Data('gl', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_gl.YEAR_MONTH_FULL, 'outubro–novembro de 2007'),
  137. new Data('gl', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_gl.YEAR_MONTH_FULL, 'outubro de 2007 – outubro de 2008'),
  138. new Data('hi', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_hi.MONTH_DAY_MEDIUM, '10 जनवरी'),
  139. new Data('hi', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_hi.MONTH_DAY_MEDIUM, '10 जनवरी'),
  140. new Data('hi', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_hi.MONTH_DAY_MEDIUM, '10 जनवरी'),
  141. new Data('hi', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_hi.MONTH_DAY_MEDIUM, '10 नवंबर–20'),
  142. new Data('hi', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_hi.MONTH_DAY_MEDIUM, '10 अक्तूबर – 10 नवंबर'),
  143. new Data('hi', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_hi.MONTH_DAY_MEDIUM, '10 अक्तूबर 2007 – 10 अक्तूबर 2008'),
  144. new Data('zh', [2007, 0, 10, 10, 10, 10], [2007, 0, 10, 10, 10, 20], dateIntervalPatterns.DateIntervalPatterns_zh.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, '2007年1月10日周三'),
  145. new Data('zh', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 10, 20, 10], dateIntervalPatterns.DateIntervalPatterns_zh.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, '2007年1月10日周三'),
  146. new Data('zh', [2007, 0, 10, 10, 0, 10], [2007, 0, 10, 14, 10, 10], dateIntervalPatterns.DateIntervalPatterns_zh.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, '2007年1月10日周三'),
  147. new Data('zh', [2007, 10, 10, 10, 10, 10], [2007, 10, 20, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_zh.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, '2007年11月10日周六至20日周二'),
  148. new Data('zh', [2007, 9, 10, 10, 10, 10], [2007, 10, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_zh.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, '2007年10月10日周三至11月10日周六'),
  149. new Data('zh', [2007, 9, 10, 10, 10, 10], [2008, 9, 10, 10, 10, 10], dateIntervalPatterns.DateIntervalPatterns_zh.WEEKDAY_MONTH_DAY_YEAR_MEDIUM, '2007年10月10日周三至2008年10月10日周五')
  150. ];
  151. // clang-format on
  152. testSuite({
  153. testFormat: function() {
  154. for (var i = 0; i < formatTestData.length; i++) {
  155. var data = formatTestData[i];
  156. var symbols = localeSymbols[data.locale];
  157. var dt1 = new Date(Date.UTC.apply(null, data.firstDate));
  158. var dt2 = new Date(Date.UTC.apply(null, data.secondDate));
  159. var fmt = new DateIntervalFormat(
  160. data.pattern, symbols.DateIntervalSymbols, symbols.DateTimeSymbols);
  161. var tz = TimeZone.createTimeZone(0);
  162. assertEquals(
  163. data.getErrorDescription(), data.expected, fmt.format(dt1, dt2, tz));
  164. }
  165. },
  166. testRangeFormat: function() {
  167. var dt1 = new GoogDate(2007, 1, 10);
  168. var dt2 = new GoogDate(2007, 6, 3);
  169. var dtRng = new DateRange(dt1, dt2);
  170. var fmt = new DateIntervalFormat(DateTimeFormat.Format.LONG_DATE);
  171. assertEquals('February 10 – July 3, 2007', fmt.formatRange(dtRng));
  172. },
  173. testDateAndIntervalFormat: function() {
  174. var dt = new GoogDate(2007, 1, 10);
  175. var itv = new Interval(0, 4, 23);
  176. var fmt = new DateIntervalFormat(DateTimeFormat.Format.LONG_DATE);
  177. assertEquals('February 10 – July 3, 2007', fmt.format(dt, itv));
  178. },
  179. testNewYearFormat: function() {
  180. var dt1 = new Date(Date.UTC(2007, 0, 1, 3, 0, 23));
  181. var dt2 = new Date(Date.UTC(2007, 0, 1, 3, 40, 23));
  182. var fmt = new DateIntervalFormat(DateTimeFormat.Format.FULL_DATETIME);
  183. var tz = TimeZone.createTimeZone(210);
  184. assertEquals(
  185. 'Sunday, December 31, 2006 at 11:30:23 PM UTC-3:30 – ' +
  186. 'Monday, January 1, 2007 at 12:10:23 AM UTC-3:30',
  187. fmt.format(dt1, dt2, tz));
  188. },
  189. testTimeZone: function() {
  190. var dt1 = new Date(Date.UTC(2007, 0, 10, 6, 0, 23));
  191. var dt2 = new Date(Date.UTC(2007, 0, 10, 6, 20, 23));
  192. var fmt = new DateIntervalFormat(DateTimeFormat.Format.LONG_TIME);
  193. var tz = TimeZone.createTimeZone(240);
  194. assertEquals(
  195. '2:00:23 AM UTC-4 – 2:20:23 AM UTC-4', fmt.format(dt1, dt2, tz));
  196. },
  197. testFormatSecondDateWithFirstPattern: function() {
  198. // Set the new fallback pattern.
  199. var symbols = object.clone(dateIntervalSymbols.getDateIntervalSymbols());
  200. symbols.FALLBACK = '{1} – {0}';
  201. // Format the dates.
  202. var dt1 = new GoogDate(2007, 1, 10);
  203. var dt2 = new GoogDate(2007, 6, 3);
  204. var fmt = new DateIntervalFormat(DateTimeFormat.Format.LONG_DATE, symbols);
  205. assertEquals('July 3 – February 10, 2007', fmt.format(dt1, dt2));
  206. },
  207. testGetLargestDifferentCalendarField: function() {
  208. // Era
  209. var dt1 = new DateTime(-1, 1, 10);
  210. var dt2 = new DateTime(2007, 6, 3);
  211. var calField =
  212. DateIntervalFormat.getLargestDifferentCalendarField_(dt1, dt2);
  213. assertEquals('G', calField);
  214. // Month
  215. dt1 = new DateTime(2007, 1, 10);
  216. dt2 = new DateTime(2007, 6, 3);
  217. calField = DateIntervalFormat.getLargestDifferentCalendarField_(dt1, dt2);
  218. assertEquals('M', calField);
  219. // AmPm
  220. dt1 = new DateTime(2007, 1, 10, 10);
  221. dt2 = new DateTime(2007, 1, 10, 14);
  222. calField = DateIntervalFormat.getLargestDifferentCalendarField_(dt1, dt2);
  223. assertEquals('a', calField);
  224. // AmPm + Timezone
  225. dt1 = new Date(Date.UTC(2007, 1, 10, 8, 25));
  226. dt2 = new Date(Date.UTC(2007, 1, 10, 8, 35));
  227. var tz = new TimeZone.createTimeZone(-210);
  228. calField =
  229. DateIntervalFormat.getLargestDifferentCalendarField_(dt1, dt2, tz);
  230. assertEquals('a', calField);
  231. // Seconds
  232. dt1 = new DateTime(2007, 1, 10, 10, 0, 1);
  233. dt2 = new DateTime(2007, 1, 10, 10, 0, 10);
  234. calField = DateIntervalFormat.getLargestDifferentCalendarField_(dt1, dt2);
  235. assertEquals('s', calField);
  236. },
  237. testDivideIntervalPattern: function() {
  238. var pttn = DateIntervalFormat.divideIntervalPattern_('MMM d – d, y');
  239. assertObjectEquals({firstPart: 'MMM d – ', secondPart: 'd, y'}, pttn);
  240. pttn = DateIntervalFormat.divideIntervalPattern_('MMM d, y');
  241. assertNull(pttn);
  242. },
  243. testIsCalendarFieldLargerOrEqualThan: function() {
  244. assertTrue(DateIntervalFormat.isCalendarFieldLargerOrEqualThan_('G', 's'));
  245. assertTrue(DateIntervalFormat.isCalendarFieldLargerOrEqualThan_('a', 'm'));
  246. assertFalse(DateIntervalFormat.isCalendarFieldLargerOrEqualThan_('a', 'y'));
  247. assertFalse(DateIntervalFormat.isCalendarFieldLargerOrEqualThan_('a', '-'));
  248. }
  249. });