time.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>Test TextBox for Time</title>
  7. <script type="text/javascript" src="../../../dojo/dojo.js"
  8. djConfig="isDebug: true, extraLocale: ['zh-cn','fr-fr','ja-jp','ar-eg','ru-ru','hi-in','en-us']"></script>
  9. <script type="text/javascript" src="../../../dojo/currency.js"></script>
  10. <script type="text/javascript" src="../../../dojo/number.js"></script>
  11. <script type="text/javascript">
  12. dojo.require("dijit.form.ValidationTextBox");
  13. dojo.require("dojo.date.locale");
  14. dojo.require("dojo.date.stamp");
  15. dojo.require("dojo.date");
  16. dojo.require("dojo.string");
  17. dojo.require("dojo.parser"); // scan page for widgets and instantiate them
  18. dojo.require("doh.runner");
  19. </script>
  20. <script src="test_i18n.js"></script>
  21. <script type="text/javascript">
  22. dojo.addOnLoad(function(){
  23. doh.register("t", getAllTestCases());
  24. doh.run();
  25. });
  26. </script>
  27. <style type="text/css">
  28. @import "../../../dojo/resources/dojo.css";
  29. @import "../../themes/tundra/tundra.css";
  30. @import "../css/dijitTests.css";
  31. .title {
  32. background-color:#ddd;
  33. }
  34. .hint {
  35. background-color:#eee;
  36. }
  37. .testExample {
  38. background-color:#fbfbfb;
  39. padding:1em;
  40. margin-bottom:1em;
  41. border:1px solid #bfbfbf;
  42. }
  43. .dojoTitlePaneLabel label {
  44. font-weight:bold;
  45. }
  46. td {white-space:nowrap}
  47. </style>
  48. <script>
  49. dojo.declare(
  50. "dijit.form.TimeTextBox",
  51. dijit.form.ValidationTextBox,
  52. {
  53. regExpGen: dojo.date.locale.regexp,
  54. format: dojo.date.locale.format,
  55. parse: dojo.date.locale.parse,
  56. value: new Date()
  57. }
  58. );
  59. var tz_s = dojo.date.getTimezoneName(new Date());
  60. if (!tz_s) {
  61. var offset = new Date().getTimezoneOffset();
  62. var tz = [
  63. (offset <= 0 ? "+" : "-"),
  64. dojo.string.pad(Math.floor(Math.abs(offset) / 60), 2),
  65. dojo.string.pad(Math.abs(offset) % 60, 2)
  66. ];
  67. tz.splice(0, 0, "GMT");
  68. tz.splice(3, 0, ":");
  69. tz_s = tz.join("");
  70. }
  71. function gen4DateFormat(testCases, language, locale, date, short, shortCmt, medium, mediumCmt, long, longCmt, full, fullCmt) {
  72. var tz_l = language.indexOf("hi") == 0 && dojo.number.normalizeDigitChars ?
  73. dojo.number.normalizeDigitChars(tz_s, language) : tz_s;
  74. short = short.replace(/UTC/, tz_l);
  75. medium = medium.replace(/UTC/, tz_l);
  76. long = long.replace(/UTC/g, tz_l);
  77. full = full.replace(/UTC/, tz_l);
  78. var shortDate = null;
  79. testCases.push({
  80. attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'short', selector:'time', localeDigit:true}" : "{formatLength:'short', selector:'time'}",
  81. lang: language},
  82. desc: "Locale: <b>" + locale + "</b> Format: <b>Short</b>",
  83. value: typeof(date) == "string" ? date : shortDate = new Date(date.getYear(), date.getMonth(), date.getDay() - 5, date.getHours(), date.getMinutes()),
  84. expValue: short,
  85. comment: shortCmt
  86. });
  87. testCases.push({
  88. attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'medium', selector:'time', localeDigit:true}" : "{formatLength:'medium', selector:'time'}",
  89. lang: language},
  90. desc: "Locale: <b>" + locale + "</b> Format: <b>Medium</b>",
  91. value: date,
  92. expValue: medium,
  93. comment: mediumCmt
  94. });
  95. testCases.push({
  96. attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'long', selector:'time', localeDigit:true}" : "{formatLength:'long', selector:'time'}",
  97. lang: language},
  98. desc: "Locale: <b>" + locale + "</b> Format: <b>Long</b>",
  99. value: date,
  100. expValue: long,
  101. comment: longCmt
  102. });
  103. testCases.push({
  104. attrs: {constraints: language.indexOf("hi") == 0 ? "{formatLength:'full', selector:'time', localeDigit:true}" : "{formatLength:'full', selector:'time'}",
  105. lang: language},
  106. desc: "Locale: <b>" + locale + "</b> Format: <b>Full</b>",
  107. value: typeof(date) == "string" || language.indexOf("fr") ? date : shortDate,
  108. expValue: full,
  109. comment: fullCmt
  110. });
  111. date.processValue = function (value) {
  112. return value ? new Date(1970, 0, 1, value.getHours(), value.getMinutes(), value.getSeconds()) : value;
  113. };
  114. if (shortDate) {
  115. shortDate.processValue = date.processValue;
  116. }
  117. }
  118. </script>
  119. </head>
  120. <body class="tundra">
  121. <h1 class="testTitle">Dijit TextBox Globalization Test for Time</h1>
  122. <h2 class="testTitle">Press the following button to start all test after this page is loaded.</h2>
  123. <button id="startButton" onclick="startTest()">Start Test</button>
  124. <p>
  125. Before start this test, make sure the <b>dojo/cldr/nls</b> contains the data for "zh-cn", "fr-fr", "ja-jp", "ru-ru", "hi-in", "en-us" and "ar-eg". If not, convert these CLDR data and put them there.
  126. </p>
  127. <script>
  128. (function() {
  129. var testCases;
  130. testCases = new Array();
  131. gen4DateFormat(testCases, "ru-ru", "ru_RU", "1970-01-01T15:25:35",
  132. "15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>");
  133. gen4DateFormat(testCases, "zh-cn", "zh_CN", "1970-01-01T15:25:35",
  134. "下午3:25", "", "下午03:25:35", "", "下午03时25分35秒", "", "下午03时25分35秒 UTC", "<a href='#cmt_1'>See #1.</a>");
  135. gen4DateFormat(testCases, "en-us", "en_US", "1970-01-01T15:25:35",
  136. "3:25 PM", "", "3:25:35 PM", "", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>");
  137. gen4DateFormat(testCases, "fr-fr", "fr_FR", "1970-01-01T15:25:35",
  138. "15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15 h 25 UTC", "<a href='#cmt_1'>See #1.</a>");
  139. gen4DateFormat(testCases, "ja-jp", "ja_JP", "1970-01-01T15:25:35",
  140. "15:25", "", "15:25:35", "", "15:25:35:UTC", "<a href='#cmt_1'>See #1.</a>", "15時25分35秒UTC", "<a href='#cmt_1'>See #1.</a>");
  141. gen4DateFormat(testCases, "ar-eg", "ar_EG", "1970-01-01T15:25:35",
  142. "3:25 \u0645", "", "3:25:35 \u0645", "", "3:25:35 \u0645", "", "UTC 3:25:35 \u0645", "<a href='#cmt_1'>See #1.</a>");
  143. gen4DateFormat(testCases, "hi-in", "hi_IN", "1970-01-01T15:25:35",
  144. "३:२५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>");
  145. genFormatTestCases("Time Format", "dijit.form.TimeTextBox", testCases);
  146. testCases = new Array();
  147. gen4DateFormat(testCases, "ru-ru", "ru_RU", new Date(1970, 0, 1, 15, 25, 35),
  148. "15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>");
  149. gen4DateFormat(testCases, "zh-cn", "zh_CN", new Date(1970, 0, 1, 15, 25, 35),
  150. "下午3:25", "<a href='#cmt_3'>See #3.</a>", "下午03:25:35", "<a href='#cmt_3'>See #3.</a>", "下午03时25分35秒", "<a href='#cmt_3'>See #3.</a>", "下午03时25分35秒 UTC", "<a href='#cmt_1'>See #1.</a>");
  151. gen4DateFormat(testCases, "en-us", "en_US", new Date(1970, 0, 1, 15, 25, 35),
  152. "3:25 PM", "", "3:25:35 PM", "", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>", "3:25:35 PM UTC", "<a href='#cmt_1'>See #1.</a>");
  153. gen4DateFormat(testCases, "fr-fr", "fr_FR", new Date(1970, 0, 1, 15, 25, 35),
  154. "15:25", "", "15:25:35", "", "15:25:35 UTC", "<a href='#cmt_1'>See #1.</a>", "15 h 25 UTC", "<a href='#cmt_1'>See #1.</a>");
  155. gen4DateFormat(testCases, "ja-jp", "ja_JP", new Date(1970, 0, 1, 15, 25, 35),
  156. "15:25", "", "15:25:35", "", "15:25:35:UTC", "<a href='#cmt_1'>See #1.</a>", "15時25分35秒UTC", "<a href='#cmt_1'>See #1.</a>");
  157. gen4DateFormat(testCases, "ar-eg", "ar_EG", new Date(1970, 0, 1, 15, 25, 35),
  158. "3:25 \u0645", "", "3:25:35 \u0645", "", "3:25:35 \u0645", "", "UTC 3:25:35 \u0645", "<a href='#cmt_1'>See #1.</a>");
  159. gen4DateFormat(testCases, "hi-in", "hi_IN", new Date(1970, 0, 1, 15, 25, 35),
  160. "३:२५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न", "<a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>", "३:२५:३५ अपराह्न UTC", "<a href='#cmt_1'>See #1.</a> <a href='#cmt_2'>See #2.</a>");
  161. genValidateTestCases("Time Validate", "dijit.form.TimeTextBox", testCases);
  162. dojo.parser.parse();
  163. })();
  164. </script>
  165. <h2 class="testTitle">Issues &amp; Comments</h2>
  166. <a name="cmt_1"><h3 class="testTitle">Issue #1 <sup style="color:blue">Fixed</sup></h3></a>
  167. <p>
  168. Currently Dojo do not support parsing for most "long" and "full" time format which have a timezone mark in it.
  169. </p>
  170. <a name="cmt_2"><h3 class="testTitle">Issue #2 <sup style="color:blue">Fixed: added a "localeDigit" to the options</sup></h3></a>
  171. <p>
  172. Strictly speaking, the data conversion must support non-European number characters in some locales like Arabic and Hindi.
  173. For example, ICU formats a number data into Indic number characters by default in the Arabic locale.
  174. However, currently Dojo does not support this feature (Dojo uses the default number conversion of the browser).
  175. </p>
  176. <a name="cmt_3"><h3 class="testTitle">Issue #3 <sup style="color:blue">Fixed</sup></h3></a>
  177. <p>
  178. This defect only occurs on the "zh-cn" locale. Dojo accepts "下午"(pm) in the textbox, but it automatically changes it to
  179. "上午"(am) after the focus changed. The date value of the textbox is also changed.
  180. </p>
  181. <p>
  182. The root cause of this issue is that the parser method's code assumes am/pm symbol always appears after the hour value.
  183. But this is not true, for example, the pattern for "zh-cn" puts am/pm field before all the other fields.
  184. </p>
  185. </body>
  186. </html>