e5c9afef7dcdd21302ac6cd6befe03cc6be47121.svn-base 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. if (!dojo._hasResource["tests.date"]) { // _hasResource checks added by build.
  2. // Do not use _hasResource directly in
  3. // your code.
  4. dojo._hasResource["tests.date"] = true;
  5. dojo.provide("tests.date");
  6. dojo.require("dojo.date");
  7. tests.register("tests.date.util", [
  8. /***********************************************************
  9. * Informational Functions
  10. **********************************************************/
  11. function test_date_getDaysInMonth(t) {
  12. // months other than February
  13. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 0, 1)));
  14. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 2, 1)));
  15. t.is(30, dojo.date.getDaysInMonth(new Date(2006, 3, 1)));
  16. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 4, 1)));
  17. t.is(30, dojo.date.getDaysInMonth(new Date(2006, 5, 1)));
  18. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 6, 1)));
  19. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 7, 1)));
  20. t.is(30, dojo.date.getDaysInMonth(new Date(2006, 8, 1)));
  21. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 9, 1)));
  22. t.is(30, dojo.date.getDaysInMonth(new Date(2006, 10, 1)));
  23. t.is(31, dojo.date.getDaysInMonth(new Date(2006, 11, 1)));
  24. // Februarys
  25. t.is(28, dojo.date.getDaysInMonth(new Date(2006, 1, 1)));
  26. t.is(29, dojo.date.getDaysInMonth(new Date(2004, 1, 1)));
  27. t.is(29, dojo.date.getDaysInMonth(new Date(2000, 1, 1)));
  28. t.is(28, dojo.date.getDaysInMonth(new Date(1900, 1, 1)));
  29. t.is(28, dojo.date.getDaysInMonth(new Date(1800, 1, 1)));
  30. t.is(28, dojo.date.getDaysInMonth(new Date(1700, 1, 1)));
  31. t.is(29, dojo.date.getDaysInMonth(new Date(1600, 1, 1)));
  32. },
  33. function test_date_isLeapYear(t) {
  34. t.f(dojo.date.isLeapYear(new Date(2006, 0, 1)));
  35. t.t(dojo.date.isLeapYear(new Date(2004, 0, 1)));
  36. t.t(dojo.date.isLeapYear(new Date(2000, 0, 1)));
  37. t.f(dojo.date.isLeapYear(new Date(1900, 0, 1)));
  38. t.f(dojo.date.isLeapYear(new Date(1800, 0, 1)));
  39. t.f(dojo.date.isLeapYear(new Date(1700, 0, 1)));
  40. t.t(dojo.date.isLeapYear(new Date(1600, 0, 1)));
  41. },
  42. // The getTimezone function pulls from either the date's
  43. // toString or
  44. // toLocaleString method -- it's really just a
  45. // string-processing
  46. // function (assuming the Date obj passed in supporting both
  47. // toString
  48. // and toLocaleString) and as such can be tested for
  49. // multiple browsers
  50. // by manually settting up fake Date objects with the actual
  51. // strings
  52. // produced by various browser/OS combinations.
  53. // FIXME: the function and tests are not localized.
  54. function test_date_getTimezoneName(t) {
  55. // Create a fake Date object with toString and
  56. // toLocaleString
  57. // results manually set to simulate tests for multiple
  58. // browsers
  59. function fakeDate(str, strLocale) {
  60. this.str = str || '';
  61. this.strLocale = strLocale || '';
  62. this.toString = function() {
  63. return this.str;
  64. };
  65. this.toLocaleString = function() {
  66. return this.strLocale;
  67. };
  68. }
  69. var dt = new fakeDate();
  70. // FF 1.5 Ubuntu Linux (Breezy)
  71. dt.str = 'Sun Sep 17 2006 22:25:51 GMT-0500 (CDT)';
  72. dt.strLocale = 'Sun 17 Sep 2006 10:25:51 PM CDT';
  73. t.is('CDT', dojo.date.getTimezoneName(dt));
  74. // Safari 2.0 Mac OS X 10.4
  75. dt.str = 'Sun Sep 17 2006 22:55:01 GMT-0500';
  76. dt.strLocale = 'September 17, 2006 10:55:01 PM CDT';
  77. t.is('CDT', dojo.date.getTimezoneName(dt));
  78. // FF 1.5 Mac OS X 10.4
  79. dt.str = 'Sun Sep 17 2006 22:57:18 GMT-0500 (CDT)';
  80. dt.strLocale = 'Sun Sep 17 22:57:18 2006';
  81. t.is('CDT', dojo.date.getTimezoneName(dt));
  82. // Opera 9 Mac OS X 10.4 -- no TZ data expect empty
  83. // string return
  84. dt.str = 'Sun, 17 Sep 2006 22:58:06 GMT-0500';
  85. dt.strLocale = 'Sunday September 17, 22:58:06 GMT-0500 2006';
  86. t.is('', dojo.date.getTimezoneName(dt));
  87. // IE 6 Windows XP
  88. dt.str = 'Mon Sep 18 11:21:07 CDT 2006';
  89. dt.strLocale = 'Monday, September 18, 2006 11:21:07 AM';
  90. t.is('CDT', dojo.date.getTimezoneName(dt));
  91. // Opera 9 Ubuntu Linux (Breezy) -- no TZ data expect
  92. // empty string return
  93. dt.str = 'Mon, 18 Sep 2006 13:30:32 GMT-0500';
  94. dt.strLocale = 'Monday September 18, 13:30:32 GMT-0500 2006';
  95. t.is('', dojo.date.getTimezoneName(dt));
  96. // IE 5.5 Windows 2000
  97. dt.str = 'Mon Sep 18 13:49:22 CDT 2006';
  98. dt.strLocale = 'Monday, September 18, 2006 1:49:22 PM';
  99. t.is('CDT', dojo.date.getTimezoneName(dt));
  100. }]);
  101. tests.register("tests.date.math", [function test_date_compare(t) {
  102. var d1 = allGetServerTime();
  103. d1.setHours(0);
  104. var d2 = allGetServerTime();
  105. d2.setFullYear(2005);
  106. d2.setHours(12);
  107. t.is(0, dojo.date.compare(d1, d1));
  108. t.is(1, dojo.date.compare(d1, d2, "date"));
  109. t.is(-1, dojo.date.compare(d2, d1, "date"));
  110. t.is(-1, dojo.date.compare(d1, d2, "time"));
  111. t.is(1, dojo.date.compare(d1, d2, "datetime"));
  112. }, function test_date_add(t) {
  113. var interv = ''; // Interval (e.g., year, month)
  114. var dtA = null; // Date to increment
  115. var dtB = null; // Expected result date
  116. interv = "year";
  117. dtA = new Date(2005, 11, 27);
  118. dtB = new Date(2006, 11, 27);
  119. t.is(dtB, dojo.date.add(dtA, interv, 1));
  120. dtA = new Date(2005, 11, 27);
  121. dtB = new Date(2004, 11, 27);
  122. t.is(dtB, dojo.date.add(dtA, interv, -1));
  123. dtA = new Date(2000, 1, 29);
  124. dtB = new Date(2001, 1, 28);
  125. t.is(dtB, dojo.date.add(dtA, interv, 1));
  126. dtA = new Date(2000, 1, 29);
  127. dtB = new Date(2005, 1, 28);
  128. t.is(dtB, dojo.date.add(dtA, interv, 5));
  129. dtA = new Date(1900, 11, 31);
  130. dtB = new Date(1930, 11, 31);
  131. t.is(dtB, dojo.date.add(dtA, interv, 30));
  132. dtA = new Date(1995, 11, 31);
  133. dtB = new Date(2030, 11, 31);
  134. t.is(dtB, dojo.date.add(dtA, interv, 35));
  135. interv = "quarter";
  136. dtA = new Date(2000, 0, 1);
  137. dtB = new Date(2000, 3, 1);
  138. t.is(dtB, dojo.date.add(dtA, interv, 1));
  139. dtA = new Date(2000, 1, 29);
  140. dtB = new Date(2000, 7, 29);
  141. t.is(dtB, dojo.date.add(dtA, interv, 2));
  142. dtA = new Date(2000, 1, 29);
  143. dtB = new Date(2001, 1, 28);
  144. t.is(dtB, dojo.date.add(dtA, interv, 4));
  145. interv = "month";
  146. dtA = new Date(2000, 0, 1);
  147. dtB = new Date(2000, 1, 1);
  148. t.is(dtB, dojo.date.add(dtA, interv, 1));
  149. dtA = new Date(2000, 0, 31);
  150. dtB = new Date(2000, 1, 29);
  151. t.is(dtB, dojo.date.add(dtA, interv, 1));
  152. dtA = new Date(2000, 1, 29);
  153. dtB = new Date(2001, 1, 28);
  154. t.is(dtB, dojo.date.add(dtA, interv, 12));
  155. interv = "week";
  156. dtA = new Date(2000, 0, 1);
  157. dtB = new Date(2000, 0, 8);
  158. t.is(dtB, dojo.date.add(dtA, interv, 1));
  159. var interv = "day";
  160. dtA = new Date(2000, 0, 1);
  161. dtB = new Date(2000, 0, 2);
  162. t.is(dtB, dojo.date.add(dtA, interv, 1));
  163. dtA = new Date(2001, 0, 1);
  164. dtB = new Date(2002, 0, 1);
  165. t.is(dtB, dojo.date.add(dtA, interv, 365));
  166. dtA = new Date(2000, 0, 1);
  167. dtB = new Date(2001, 0, 1);
  168. t.is(dtB, dojo.date.add(dtA, interv, 366));
  169. dtA = new Date(2000, 1, 28);
  170. dtB = new Date(2000, 1, 29);
  171. t.is(dtB, dojo.date.add(dtA, interv, 1));
  172. dtA = new Date(2001, 1, 28);
  173. dtB = new Date(2001, 2, 1);
  174. t.is(dtB, dojo.date.add(dtA, interv, 1));
  175. dtA = new Date(2000, 2, 1);
  176. dtB = new Date(2000, 1, 29);
  177. t.is(dtB, dojo.date.add(dtA, interv, -1));
  178. dtA = new Date(2001, 2, 1);
  179. dtB = new Date(2001, 1, 28);
  180. t.is(dtB, dojo.date.add(dtA, interv, -1));
  181. dtA = new Date(2000, 0, 1);
  182. dtB = new Date(1999, 11, 31);
  183. t.is(dtB, dojo.date.add(dtA, interv, -1));
  184. interv = "weekday";
  185. // Sat, Jan 1
  186. dtA = new Date(2000, 0, 1);
  187. // Should be Mon, Jan 3
  188. dtB = new Date(2000, 0, 3);
  189. t.is(dtB, dojo.date.add(dtA, interv, 1));
  190. // Sun, Jan 2
  191. dtA = new Date(2000, 0, 2);
  192. // Should be Mon, Jan 3
  193. dtB = new Date(2000, 0, 3);
  194. t.is(dtB, dojo.date.add(dtA, interv, 1));
  195. // Sun, Jan 2
  196. dtA = new Date(2000, 0, 2);
  197. // Should be Fri, Jan 7
  198. dtB = new Date(2000, 0, 7);
  199. t.is(dtB, dojo.date.add(dtA, interv, 5));
  200. // Sun, Jan 2
  201. dtA = new Date(2000, 0, 2);
  202. // Should be Mon, Jan 10
  203. dtB = new Date(2000, 0, 10);
  204. t.is(dtB, dojo.date.add(dtA, interv, 6));
  205. // Mon, Jan 3
  206. dtA = new Date(2000, 0, 3);
  207. // Should be Mon, Jan 17
  208. dtB = new Date(2000, 0, 17);
  209. t.is(dtB, dojo.date.add(dtA, interv, 10));
  210. // Sat, Jan 8
  211. dtA = new Date(2000, 0, 8);
  212. // Should be Mon, Jan 3
  213. dtB = new Date(2000, 0, 3);
  214. t.is(dtB, dojo.date.add(dtA, interv, -5));
  215. // Sun, Jan 9
  216. dtA = new Date(2000, 0, 9);
  217. // Should be Wed, Jan 5
  218. dtB = new Date(2000, 0, 5);
  219. t.is(dtB, dojo.date.add(dtA, interv, -3));
  220. // Sun, Jan 23
  221. dtA = new Date(2000, 0, 23);
  222. // Should be Fri, Jan 7
  223. dtB = new Date(2000, 0, 7);
  224. t.is(dtB, dojo.date.add(dtA, interv, -11));
  225. interv = "hour";
  226. dtA = new Date(2000, 0, 1, 11);
  227. dtB = new Date(2000, 0, 1, 12);
  228. t.is(dtB, dojo.date.add(dtA, interv, 1));
  229. dtA = new Date(2001, 9, 28, 0);
  230. dtB = new Date(2001, 9, 28, 1);
  231. t.is(dtB, dojo.date.add(dtA, interv, 1));
  232. dtA = new Date(2001, 9, 28, 23);
  233. dtB = new Date(2001, 9, 29, 0);
  234. t.is(dtB, dojo.date.add(dtA, interv, 1));
  235. dtA = new Date(2001, 11, 31, 23);
  236. dtB = new Date(2002, 0, 1, 0);
  237. t.is(dtB, dojo.date.add(dtA, interv, 1));
  238. interv = "minute";
  239. dtA = new Date(2000, 11, 31, 23, 59);
  240. dtB = new Date(2001, 0, 1, 0, 0);
  241. t.is(dtB, dojo.date.add(dtA, interv, 1));
  242. dtA = new Date(2000, 11, 27, 12, 02);
  243. dtB = new Date(2000, 11, 27, 13, 02);
  244. t.is(dtB, dojo.date.add(dtA, interv, 60));
  245. interv = "second";
  246. dtA = new Date(2000, 11, 31, 23, 59, 59);
  247. dtB = new Date(2001, 0, 1, 0, 0, 0);
  248. t.is(dtB, dojo.date.add(dtA, interv, 1));
  249. dtA = new Date(2000, 11, 27, 8, 10, 59);
  250. dtB = new Date(2000, 11, 27, 8, 11, 59);
  251. t.is(dtB, dojo.date.add(dtA, interv, 60));
  252. // Test environment JS Date doesn't support millisec?
  253. // interv = "millisecond";
  254. //
  255. // dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
  256. // dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
  257. // t.is(dtB, dojo.date.add(dtA, interv, 1));
  258. //
  259. // dtA = new Date(2000, 11, 27, 8, 10, 53, 2);
  260. // dtB = new Date(2000, 11, 27, 8, 10, 54, 2);
  261. // t.is(dtB, dojo.date.add(dtA, interv, 1000));
  262. }, function test_date_diff(t) {
  263. var dtA = null; // First date to compare
  264. var dtB = null; // Second date to compare
  265. var interv = ''; // Interval to compare on (e.g., year,
  266. // month)
  267. interv = "year";
  268. dtA = new Date(2005, 11, 27);
  269. dtB = new Date(2006, 11, 27);
  270. t.is(1, dojo.date.difference(dtA, dtB, interv));
  271. dtA = new Date(2000, 11, 31);
  272. dtB = new Date(2001, 0, 1);
  273. t.is(1, dojo.date.difference(dtA, dtB, interv));
  274. interv = "quarter";
  275. dtA = new Date(2000, 1, 29);
  276. dtB = new Date(2001, 2, 1);
  277. t.is(4, dojo.date.difference(dtA, dtB, interv));
  278. dtA = new Date(2000, 11, 1);
  279. dtB = new Date(2001, 0, 1);
  280. t.is(1, dojo.date.difference(dtA, dtB, interv));
  281. interv = "month";
  282. dtA = new Date(2000, 1, 29);
  283. dtB = new Date(2001, 2, 1);
  284. t.is(13, dojo.date.difference(dtA, dtB, interv));
  285. dtA = new Date(2000, 11, 1);
  286. dtB = new Date(2001, 0, 1);
  287. t.is(1, dojo.date.difference(dtA, dtB, interv));
  288. interv = "week";
  289. dtA = new Date(2000, 1, 1);
  290. dtB = new Date(2000, 1, 8);
  291. t.is(1, dojo.date.difference(dtA, dtB, interv));
  292. dtA = new Date(2000, 1, 28);
  293. dtB = new Date(2000, 2, 6);
  294. t.is(1, dojo.date.difference(dtA, dtB, interv));
  295. dtA = new Date(2000, 2, 6);
  296. dtB = new Date(2000, 1, 28);
  297. t.is(-1, dojo.date.difference(dtA, dtB, interv));
  298. interv = "day";
  299. dtA = new Date(2000, 1, 29);
  300. dtB = new Date(2000, 2, 1);
  301. t.is(1, dojo.date.difference(dtA, dtB, interv));
  302. dtA = new Date(2000, 11, 31);
  303. dtB = new Date(2001, 0, 1);
  304. t.is(1, dojo.date.difference(dtA, dtB, interv));
  305. // DST leap -- check for rounding err
  306. // This is dependent on US calendar, but
  307. // shouldn't break in other locales
  308. dtA = new Date(2005, 3, 3);
  309. dtB = new Date(2005, 3, 4);
  310. t.is(1, dojo.date.difference(dtA, dtB, interv));
  311. interv = "weekday";
  312. dtA = new Date(2006, 7, 3);
  313. dtB = new Date(2006, 7, 11);
  314. t.is(6, dojo.date.difference(dtA, dtB, interv));
  315. // Positive diffs
  316. dtA = new Date(2006, 7, 4);
  317. dtB = new Date(2006, 7, 11);
  318. t.is(5, dojo.date.difference(dtA, dtB, interv));
  319. dtA = new Date(2006, 7, 5);
  320. dtB = new Date(2006, 7, 11);
  321. t.is(5, dojo.date.difference(dtA, dtB, interv));
  322. dtA = new Date(2006, 7, 6);
  323. dtB = new Date(2006, 7, 11);
  324. t.is(5, dojo.date.difference(dtA, dtB, interv));
  325. dtA = new Date(2006, 7, 7);
  326. dtB = new Date(2006, 7, 11);
  327. t.is(4, dojo.date.difference(dtA, dtB, interv));
  328. dtA = new Date(2006, 7, 7);
  329. dtB = new Date(2006, 7, 13);
  330. t.is(4, dojo.date.difference(dtA, dtB, interv));
  331. dtA = new Date(2006, 7, 7);
  332. dtB = new Date(2006, 7, 14);
  333. t.is(5, dojo.date.difference(dtA, dtB, interv));
  334. dtA = new Date(2006, 7, 7);
  335. dtB = new Date(2006, 7, 15);
  336. t.is(6, dojo.date.difference(dtA, dtB, interv));
  337. dtA = new Date(2006, 7, 7);
  338. dtB = new Date(2006, 7, 28);
  339. t.is(15, dojo.date.difference(dtA, dtB, interv));
  340. dtA = new Date(2006, 2, 2);
  341. dtB = new Date(2006, 2, 28);
  342. t.is(18, dojo.date.difference(dtA, dtB, interv));
  343. // Negative diffs
  344. dtA = new Date(2006, 7, 11);
  345. dtB = new Date(2006, 7, 4);
  346. t.is(-5, dojo.date.difference(dtA, dtB, interv));
  347. dtA = new Date(2006, 7, 11);
  348. dtB = new Date(2006, 7, 5);
  349. t.is(-4, dojo.date.difference(dtA, dtB, interv));
  350. dtA = new Date(2006, 7, 11);
  351. dtB = new Date(2006, 7, 6);
  352. t.is(-4, dojo.date.difference(dtA, dtB, interv));
  353. dtA = new Date(2006, 7, 11);
  354. dtB = new Date(2006, 7, 7);
  355. t.is(-4, dojo.date.difference(dtA, dtB, interv));
  356. dtA = new Date(2006, 7, 13);
  357. dtB = new Date(2006, 7, 7);
  358. t.is(-5, dojo.date.difference(dtA, dtB, interv));
  359. dtA = new Date(2006, 7, 14);
  360. dtB = new Date(2006, 7, 7);
  361. t.is(-5, dojo.date.difference(dtA, dtB, interv));
  362. dtA = new Date(2006, 7, 15);
  363. dtB = new Date(2006, 7, 7);
  364. t.is(-6, dojo.date.difference(dtA, dtB, interv));
  365. dtA = new Date(2006, 7, 28);
  366. dtB = new Date(2006, 7, 7);
  367. t.is(-15, dojo.date.difference(dtA, dtB, interv));
  368. dtA = new Date(2006, 2, 28);
  369. dtB = new Date(2006, 2, 2);
  370. t.is(-18, dojo.date.difference(dtA, dtB, interv));
  371. // Two days on the same weekend -- no weekday diff
  372. dtA = new Date(2006, 7, 5);
  373. dtB = new Date(2006, 7, 6);
  374. t.is(0, dojo.date.difference(dtA, dtB, interv));
  375. interv = "hour";
  376. dtA = new Date(2000, 11, 31, 23);
  377. dtB = new Date(2001, 0, 1, 0);
  378. t.is(1, dojo.date.difference(dtA, dtB, interv));
  379. dtA = new Date(2000, 11, 31, 12);
  380. dtB = new Date(2001, 0, 1, 0);
  381. t.is(12, dojo.date.difference(dtA, dtB, interv));
  382. interv = "minute";
  383. dtA = new Date(2000, 11, 31, 23, 59);
  384. dtB = new Date(2001, 0, 1, 0, 0);
  385. t.is(1, dojo.date.difference(dtA, dtB, interv));
  386. dtA = new Date(2000, 1, 28, 23, 59);
  387. dtB = new Date(2000, 1, 29, 0, 0);
  388. t.is(1, dojo.date.difference(dtA, dtB, interv));
  389. interv = "second";
  390. dtA = new Date(2000, 11, 31, 23, 59, 59);
  391. dtB = new Date(2001, 0, 1, 0, 0, 0);
  392. t.is(1, dojo.date.difference(dtA, dtB, interv));
  393. interv = "millisecond";
  394. dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
  395. dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
  396. t.is(1, dojo.date.difference(dtA, dtB, interv));
  397. dtA = new Date(2000, 11, 31, 23, 59, 59, 0);
  398. dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
  399. t.is(1000, dojo.date.difference(dtA, dtB, interv));
  400. }, function test_date_add_diff_year(t) {
  401. var interv = ''; // Interval (e.g., year, month)
  402. var dtA = null; // Date to increment
  403. var dtB = null; // Expected result date
  404. interv = "year";
  405. dtA = new Date(2005, 11, 27);
  406. dtB = dojo.date.add(dtA, interv, 1);
  407. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  408. dtA = new Date(2005, 11, 27);
  409. dtB = dojo.date.add(dtA, interv, -1);
  410. t.is(dojo.date.difference(dtA, dtB, interv), -1);
  411. dtA = new Date(2000, 1, 29);
  412. dtB = dojo.date.add(dtA, interv, 1);
  413. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  414. dtA = new Date(2000, 1, 29);
  415. dtB = dojo.date.add(dtA, interv, 5);
  416. t.is(dojo.date.difference(dtA, dtB, interv), 5);
  417. dtA = new Date(1900, 11, 31);
  418. dtB = dojo.date.add(dtA, interv, 30);
  419. t.is(dojo.date.difference(dtA, dtB, interv), 30);
  420. dtA = new Date(1995, 11, 31);
  421. dtB = dojo.date.add(dtA, interv, 35);
  422. t.is(dojo.date.difference(dtA, dtB, interv), 35);
  423. }, function test_date_add_diff_quarter(t) {
  424. var interv = ''; // Interval (e.g., year, month)
  425. var dtA = null; // Date to increment
  426. var dtB = null; // Expected result date
  427. interv = "quarter";
  428. dtA = new Date(2000, 0, 1);
  429. dtB = dojo.date.add(dtA, interv, 1);
  430. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  431. dtA = new Date(2000, 1, 29);
  432. dtB = dojo.date.add(dtA, interv, 2);
  433. t.is(dojo.date.difference(dtA, dtB, interv), 2);
  434. dtA = new Date(2000, 1, 29);
  435. dtB = dojo.date.add(dtA, interv, 4);
  436. t.is(dojo.date.difference(dtA, dtB, interv), 4);
  437. }, function test_date_add_diff_month(t) {
  438. var interv = ''; // Interval (e.g., year, month)
  439. var dtA = null; // Date to increment
  440. var dtB = null; // Expected result date
  441. interv = "month";
  442. dtA = new Date(2000, 0, 1);
  443. dtB = dojo.date.add(dtA, interv, 1);
  444. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  445. dtA = new Date(2000, 0, 31);
  446. dtB = dojo.date.add(dtA, interv, 1);
  447. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  448. dtA = new Date(2000, 1, 29);
  449. dtB = dojo.date.add(dtA, interv, 12);
  450. t.is(dojo.date.difference(dtA, dtB, interv), 12);
  451. }, function test_date_add_diff_week(t) {
  452. var interv = ''; // Interval (e.g., year, month)
  453. var dtA = null; // Date to increment
  454. var dtB = null; // Expected result date
  455. interv = "week";
  456. dtA = new Date(2000, 0, 1);
  457. dtB = dojo.date.add(dtA, interv, 1);
  458. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  459. }, function test_date_add_diff_day(t) {
  460. var interv = ''; // Interval (e.g., year, month)
  461. var dtA = null; // Date to increment
  462. var dtB = null; // Expected result date
  463. var interv = "day";
  464. dtA = new Date(2000, 0, 1);
  465. dtB = dojo.date.add(dtA, interv, 1);
  466. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  467. dtA = new Date(2001, 0, 1);
  468. dtB = dojo.date.add(dtA, interv, 365);
  469. t.is(dojo.date.difference(dtA, dtB, interv), 365);
  470. dtA = new Date(2000, 0, 1);
  471. dtB = dojo.date.add(dtA, interv, 366);
  472. t.is(dojo.date.difference(dtA, dtB, interv), 366);
  473. dtA = new Date(2000, 1, 28);
  474. dtB = dojo.date.add(dtA, interv, 1);
  475. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  476. dtA = new Date(2001, 1, 28);
  477. dtB = dojo.date.add(dtA, interv, 1);
  478. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  479. dtA = new Date(2000, 2, 1);
  480. dtB = dojo.date.add(dtA, interv, -1);
  481. t.is(dojo.date.difference(dtA, dtB, interv), -1);
  482. dtA = new Date(2001, 2, 1);
  483. dtB = dojo.date.add(dtA, interv, -1);
  484. t.is(dojo.date.difference(dtA, dtB, interv), -1);
  485. dtA = new Date(2000, 0, 1);
  486. dtB = dojo.date.add(dtA, interv, -1);
  487. t.is(dojo.date.difference(dtA, dtB, interv), -1);
  488. }, function test_date_add_diff_weekday(t) {
  489. var interv = ''; // Interval (e.g., year, month)
  490. var dtA = null; // Date to increment
  491. var dtB = null; // Expected result date
  492. interv = "weekday";
  493. // Sat, Jan 1
  494. dtA = new Date(2000, 0, 1);
  495. // Should be Mon, Jan 3
  496. dtB = dojo.date.add(dtA, interv, 1);
  497. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  498. // Sun, Jan 2
  499. dtA = new Date(2000, 0, 2);
  500. // Should be Mon, Jan 3
  501. dtB = dojo.date.add(dtA, interv, 1);
  502. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  503. // Sun, Jan 2
  504. dtA = new Date(2000, 0, 2);
  505. // Should be Fri, Jan 7
  506. dtB = dojo.date.add(dtA, interv, 5);
  507. t.is(dojo.date.difference(dtA, dtB, interv), 5);
  508. // Sun, Jan 2
  509. dtA = new Date(2000, 0, 2);
  510. // Should be Mon, Jan 10
  511. dtB = dojo.date.add(dtA, interv, 6);
  512. t.is(dojo.date.difference(dtA, dtB, interv), 6);
  513. // Mon, Jan 3
  514. dtA = new Date(2000, 0, 3);
  515. // Should be Mon, Jan 17
  516. dtB = dojo.date.add(dtA, interv, 10);
  517. t.is(dojo.date.difference(dtA, dtB, interv), 10);
  518. // Sat, Jan 8
  519. dtA = new Date(2000, 0, 8);
  520. // Should be Mon, Jan 3
  521. dtB = dojo.date.add(dtA, interv, -5);
  522. t.is(dojo.date.difference(dtA, dtB, interv), -5);
  523. // Sun, Jan 9
  524. dtA = new Date(2000, 0, 9);
  525. // Should be Wed, Jan 5
  526. dtB = dojo.date.add(dtA, interv, -3);
  527. t.is(dojo.date.difference(dtA, dtB, interv), -3);
  528. // Sun, Jan 23
  529. dtA = new Date(2000, 0, 23);
  530. // Should be Fri, Jan 7
  531. dtB = dojo.date.add(dtA, interv, -11);
  532. t.is(dojo.date.difference(dtA, dtB, interv), -11);
  533. }, function test_date_add_diff_hour(t) {
  534. var interv = ''; // Interval (e.g., year, month)
  535. var dtA = null; // Date to increment
  536. var dtB = null; // Expected result date
  537. interv = "hour";
  538. dtA = new Date(2000, 0, 1, 11);
  539. dtB = dojo.date.add(dtA, interv, 1);
  540. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  541. dtA = new Date(2001, 9, 28, 0);
  542. dtB = dojo.date.add(dtA, interv, 1);
  543. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  544. dtA = new Date(2001, 9, 28, 23);
  545. dtB = dojo.date.add(dtA, interv, 1);
  546. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  547. dtA = new Date(2001, 11, 31, 23);
  548. dtB = dojo.date.add(dtA, interv, 1);
  549. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  550. }, function test_date_add_diff_minute(t) {
  551. var interv = ''; // Interval (e.g., year, month)
  552. var dtA = null; // Date to increment
  553. var dtB = null; // Expected result date
  554. interv = "minute";
  555. dtA = new Date(2000, 11, 31, 23, 59);
  556. dtB = dojo.date.add(dtA, interv, 1);
  557. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  558. dtA = new Date(2000, 11, 27, 12, 2);
  559. dtB = dojo.date.add(dtA, interv, 60);
  560. t.is(dojo.date.difference(dtA, dtB, interv), 60);
  561. }, function test_date_add_diff_second(t) {
  562. var interv = ''; // Interval (e.g., year, month)
  563. var dtA = null; // Date to increment
  564. var dtB = null; // Expected result date
  565. console.debug("second");
  566. interv = "second";
  567. dtA = new Date(2000, 11, 31, 23, 59, 59);
  568. dtB = dojo.date.add(dtA, interv, 1);
  569. t.is(dojo.date.difference(dtA, dtB, interv), 1);
  570. dtA = new Date(2000, 11, 27, 8, 10, 59);
  571. dtB = dojo.date.add(dtA, interv, 60);
  572. t.is(dojo.date.difference(dtA, dtB, interv), 60);
  573. // Test environment JS Date doesn't support millisec?
  574. // interv = "millisecond";
  575. //
  576. // dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
  577. // dtB = dojo.date.add(dtA, interv, 1);
  578. // t.is(dojo.date.difference(dtA, dtB, interv), 1);
  579. //
  580. // dtA = new Date(2000, 11, 27, 8, 10, 53, 2);
  581. // dtB = dojo.date.add(dtA, interv, 1000);
  582. // t.is(dojo.date.difference(dtA, dtB, interv), 1000);
  583. }]);
  584. dojo.require("tests.date.locale");
  585. dojo.require("tests.date.stamp");
  586. }