bf66b8846b7e5a03b42174cd825470885cf1ee5c.svn-base 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. if (!dojo._hasResource["tests.date.stamp"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["tests.date.stamp"] = true;
  6. dojo.provide("tests.date.stamp");
  7. dojo.require("dojo.date.stamp");
  8. tests.register("tests.date.stamp", [function test_date_iso(t) {
  9. var rfc = "2005-06-29T08:05:00-07:00";
  10. var date = dojo.date.stamp.fromISOString(rfc);
  11. t.is(2005, date.getFullYear());
  12. t.is(5, date.getMonth());
  13. t.is(29, date.getDate());
  14. t.is(15, date.getUTCHours());
  15. t.is(5, date.getMinutes());
  16. t.is(0, date.getSeconds());
  17. rfc = "2004-02-29";
  18. date = dojo.date.stamp.fromISOString(rfc);
  19. t.is(2004, date.getFullYear());
  20. t.is(1, date.getMonth());
  21. t.is(29, date.getDate());
  22. // No TZ info means local time
  23. rfc = "2004-02-29T01:23:45";
  24. date = dojo.date.stamp.fromISOString(rfc);
  25. t.is(2004, date.getFullYear());
  26. t.is(1, date.getMonth());
  27. t.is(29, date.getDate());
  28. t.is(1, date.getHours());
  29. date = new Date(2005, 5, 29, 8, 5, 0);
  30. rfc = dojo.date.stamp.toISOString(date);
  31. // truncate for comparison
  32. t.is("2005-06", rfc.substring(0, 7));
  33. date = dojo.date.stamp.fromISOString("T18:46:39");
  34. t.is(18, date.getHours());
  35. t.is(46, date.getMinutes());
  36. t.is(39, date.getSeconds());
  37. },
  38. function test_date_iso_tz(t) {
  39. // 23:59:59.9942 or 235959.9942
  40. // var date =
  41. // dojo.date.stamp.fromISOString("T18:46:39.9942");
  42. // t.is(18, date.getHours());
  43. // t.is(46, date.getMinutes());
  44. // t.is(39, date.getSeconds());
  45. // t.is(994, date.getMilliseconds());
  46. // 1995-02-04 24:00 = 1995-02-05 00:00
  47. // timezone tests
  48. var offset = allGetServerTime().getTimezoneOffset() / 60;
  49. date = dojo.date.stamp.fromISOString("T18:46:39+07:00");
  50. t.is(11, date.getUTCHours());
  51. date = dojo.date.stamp.fromISOString("T18:46:39+00:00");
  52. t.is(18, date.getUTCHours());
  53. date = dojo.date.stamp.fromISOString("T18:46:39Z");
  54. t.is(18, date.getUTCHours());
  55. date = dojo.date.stamp.fromISOString("T16:46:39-07:00");
  56. t.is(23, date.getUTCHours());
  57. // +hh:mm, +hhmm, or +hh
  58. // -hh:mm, -hhmm, or -hh
  59. }]);
  60. }