PageRenderTime 27ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tatami-1.1/j2ee/lib/tatami/com/objetdirect/tatami/public/dojox/date/php.js

http://tatami.googlecode.com/
JavaScript | 296 lines | 191 code | 51 blank | 54 comment | 29 complexity | 8c509a6f7b72d4189eed0e5882f651a7 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-2.0, MIT
  1. if(!dojo._hasResource["dojox.date.php"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2. dojo._hasResource["dojox.date.php"] = true;
  3. dojo.provide("dojox.date.php");
  4. dojo.require("dojo.date");
  5. dojox.date.php.format = function(/*Date*/ date, /*String*/ format, /*Object?*/ overrides){
  6. // summary: Get a formatted string for a given date object
  7. var df = new dojox.date.php.DateFormat(date);
  8. return df.format(format, overrides);
  9. }
  10. dojox.date.php.DateFormat = function(/*Date*/ date){
  11. this.date = date;
  12. }
  13. dojo.extend(dojox.date.php.DateFormat, {
  14. weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  15. weekdays_3: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  16. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  17. months_3: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  18. monthdays: [31,28,31,30,31,30,31,31,30,31,30,31],
  19. format: function(/*String*/ format, /*Object?*/ overrides){
  20. // summary: Format the internal date object
  21. var parts = [];
  22. for(var i = 0; i < format.length; i++){
  23. var chr = format.charAt(i);
  24. if(overrides && typeof overrides[chr] == "function"){
  25. parts.push(overrides[chr].call(this));
  26. }else if(typeof this[chr] == "function"){
  27. parts.push(this[chr]());
  28. }else{
  29. parts.push(chr);
  30. }
  31. }
  32. return parts.join("");
  33. },
  34. // Day
  35. d: function(){
  36. // summary: Day of the month, 2 digits with leading zeros
  37. var j = this.j();
  38. return (j.length == 1) ? "0" + j : j;
  39. },
  40. D: function(){
  41. // summary: A textual representation of a day, three letters
  42. return this.weekdays_3[this.date.getDay()];
  43. },
  44. j: function(){
  45. // summary: Day of the month without leading zeros
  46. return this.date.getDate() + "";
  47. },
  48. l: function(){
  49. // summary: A full textual representation of the day of the week
  50. return this.weekdays[this.date.getDay()];
  51. },
  52. N: function(){
  53. // summary: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
  54. var w = this.w();
  55. return (!w) ? 7 : w;
  56. },
  57. S: function(){
  58. // summary: English ordinal suffix for the day of the month, 2 characters
  59. switch(this.date.getDate()){
  60. case 11: case 12: case 13: return "th";
  61. case 1: case 21: case 31: return "st";
  62. case 2: case 22: return "nd";
  63. case 3: case 23: return "rd";
  64. default: return "th";
  65. }
  66. },
  67. w: function(){
  68. // summary: Numeric representation of the day of the week
  69. return this.date.getDay() + "";
  70. },
  71. z: function(){
  72. // summary: The day of the year (starting from 0)
  73. var millis = this.date.getTime() - new Date(this.date.getFullYear(), 0, 1).getTime();
  74. return Math.floor(millis/86400000) + "";
  75. },
  76. // Week
  77. W: function(){
  78. // summary: ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
  79. var week;
  80. var jan1_w = new Date(this.date.getFullYear(), 0, 1).getDay() + 1;
  81. var w = this.date.getDay() + 1;
  82. var z = parseInt(this.z());
  83. if(z <= (8 - jan1_w) && jan1_w > 4){
  84. var last_year = new Date(this.date.getFullYear() - 1, this.date.getMonth(), this.date.getDate());
  85. if(jan1_w == 5 || (jan1_w == 6 && dojo.date.isLeapYear(last_year))){
  86. week = 53;
  87. }else{
  88. week = 52;
  89. }
  90. }else{
  91. var i;
  92. if(Boolean(this.L())){
  93. i = 366;
  94. }else{
  95. i = 365;
  96. }
  97. if((i - z) < (4 - w)){
  98. week = 1;
  99. }else{
  100. var j = z + (7 - w) + (jan1_w - 1);
  101. week = Math.ceil(j / 7);
  102. if(jan1_w > 4){
  103. --week;
  104. }
  105. }
  106. }
  107. return week;
  108. },
  109. // Month
  110. F: function(){
  111. // summary: A full textual representation of a month, such as January or March
  112. return this.months[this.date.getMonth()];
  113. },
  114. m: function(){
  115. // summary: Numeric representation of a month, with leading zeros
  116. var n = this.n();
  117. return (n.length == 1) ? "0" + n : n;
  118. },
  119. M: function(){
  120. // summary: A short textual representation of a month, three letters
  121. return months_3[this.date.getMonth()];
  122. },
  123. n: function(){
  124. // summary: Numeric representation of a month, without leading zeros
  125. return this.date.getMonth() + 1 + "";
  126. },
  127. t: function(){
  128. // summary: Number of days in the given month
  129. return (Boolean(this.L()) && this.date.getMonth() == 1) ? 29 : this.monthdays[this.getMonth()];
  130. },
  131. // Year
  132. L: function(){
  133. // summary: Whether it's a leap year
  134. return (dojo.date.isLeapYear(this.date)) ? "1" : "0";
  135. },
  136. o: function(){
  137. // summary:
  138. // ISO-8601 year number. This has the same value as Y, except that if
  139. // the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)
  140. // TODO: Figure out what this means
  141. },
  142. Y: function(){
  143. // summary: A full numeric representation of a year, 4 digits
  144. return this.date.getFullYear() + "";
  145. },
  146. y: function(){
  147. // summary: A two digit representation of a year
  148. return this.date.getFullYear.substsring(2, 4);
  149. },
  150. // Time
  151. a: function(){
  152. // summary: Lowercase Ante meridiem and Post meridiem
  153. return this.date.getHours() >= 12 ? "pm" : "am";
  154. },
  155. b: function(){
  156. // summary: Uppercase Ante meridiem and Post meridiem
  157. return this.a().toUpperCase();
  158. },
  159. B: function(){
  160. // summary:
  161. // Swatch Internet time
  162. // A day is 1,000 beats. All time is measured from GMT + 1
  163. var off = this.date.getTimezoneOffset() + 60;
  164. var secs = (this.date.getHours() * 3600) + (this.date.getMinutes() * 60) + this.getSeconds() + (off * 60);
  165. var beat = Math.abs(Math.floor(secs / 86.4) % 1000) + "";
  166. while(beat.length < 2) beat = "0" + beat;
  167. return beat;
  168. },
  169. g: function(){
  170. // summary: 12-hour format of an hour without leading zeros
  171. return (this.date.getHours() > 12) ? this.date.getHours() - 12 + "" : this.date.getHours() + "";
  172. },
  173. G: function(){
  174. // summary: 24-hour format of an hour without leading zeros
  175. return this.date.getHours() + "";
  176. },
  177. h: function(){
  178. // summary: 12-hour format of an hour with leading zeros
  179. var g = this.g();
  180. return (g.length == 1) ? "0" + g : g;
  181. },
  182. H: function(){
  183. // summary: 24-hour format of an hour with leading zeros
  184. var G = this.G();
  185. return (G.length == 1) ? "0" + G : G;
  186. },
  187. i: function(){
  188. // summary: Minutes with leading zeros
  189. var mins = this.date.getMinutes() + "";
  190. return (mins.length == 1) ? "0" + mins : mins;
  191. },
  192. s: function(){
  193. // summary: Seconds, with leading zeros
  194. var secs = this.date.getSeconds() + "";
  195. return (secs.length == 1) ? "0" + secs : secs;
  196. },
  197. // Timezone
  198. e: function(){
  199. // summary: Timezone identifier (added in PHP 5.1.0)
  200. return dojo.date.getTimezoneName(this.date);
  201. },
  202. I: function(){
  203. // summary: Whether or not the date is in daylight saving time
  204. // TODO: Can dojo.date do this?
  205. },
  206. O: function(){
  207. // summary: Difference to Greenwich time (GMT) in hours
  208. var off = Math.abs(this.date.getTimezoneOffset());
  209. var hours = Math.floor(off / 60) + "";
  210. var mins = (off % 60) + "";
  211. if(hours.length == 1) hours = "0" + hours;
  212. if(mins.length == 1) hours = "0" + mins;
  213. return ((this.date.getTimezoneOffset() < 0) ? "+" : "-") + hours + mins;
  214. },
  215. P: function(){
  216. // summary: Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
  217. var O = this.O();
  218. return O.substring(0, 2) + ":" + O.substring(2, 4);
  219. },
  220. T: function(){
  221. // summary: Timezone abbreviation
  222. // Guess...
  223. return this.e().substring(0, 3);
  224. },
  225. Z: function(){
  226. // summary:
  227. // Timezone offset in seconds. The offset for timezones west of UTC is always negative,
  228. // and for those east of UTC is always positive.
  229. return this.date.getTimezoneOffset() * -60;
  230. },
  231. // Full Date/Time
  232. c: function(){
  233. // summary: ISO 8601 date (added in PHP 5)
  234. return this.Y() + "-" + this.m() + "-" + this.d() + "T" + this.h() + ":" + this.i() + ":" + this.s() + this.P();
  235. },
  236. r: function(){
  237. // summary: RFC 2822 formatted date
  238. return this.D() + ", " + this.d() + " " + this.M() + " " + this.Y() + " " + this.H() + ":" + this.i() + ":" + this.s() + " " + this.O();
  239. },
  240. U: function(){
  241. // summary: Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  242. return Math.floor(this.date.getTime() / 1000);
  243. }
  244. });
  245. }