gentelella-rails 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/assets/javascripts/date.js +5 -0
  4. data/assets/javascripts/date/core.js +4339 -0
  5. data/assets/javascripts/date/date-af-ZA.js +4526 -0
  6. data/assets/javascripts/date/date-ar-AE.js +4526 -0
  7. data/assets/javascripts/date/date-ar-BH.js +4526 -0
  8. data/assets/javascripts/date/date-ar-DZ.js +4526 -0
  9. data/assets/javascripts/date/date-ar-EG.js +4526 -0
  10. data/assets/javascripts/date/date-ar-IQ.js +4526 -0
  11. data/assets/javascripts/date/date-ar-JO.js +4526 -0
  12. data/assets/javascripts/date/date-ar-KW.js +4526 -0
  13. data/assets/javascripts/date/date-ar-LB.js +4526 -0
  14. data/assets/javascripts/date/date-ar-LY.js +4526 -0
  15. data/assets/javascripts/date/date-ar-MA.js +4526 -0
  16. data/assets/javascripts/date/date-ar-OM.js +4526 -0
  17. data/assets/javascripts/date/date-ar-QA.js +4526 -0
  18. data/assets/javascripts/date/date-ar-SA.js +4526 -0
  19. data/assets/javascripts/date/date-ar-SY.js +4526 -0
  20. data/assets/javascripts/date/date-ar-TN.js +4526 -0
  21. data/assets/javascripts/date/date-ar-YE.js +4526 -0
  22. data/assets/javascripts/date/date-az-Cyrl-AZ.js +4526 -0
  23. data/assets/javascripts/date/date-az-Latn-AZ.js +4526 -0
  24. data/assets/javascripts/date/date-be-BY.js +4526 -0
  25. data/assets/javascripts/date/date-bg-BG.js +4526 -0
  26. data/assets/javascripts/date/date-bs-Latn-BA.js +4526 -0
  27. data/assets/javascripts/date/date-ca-ES.js +4526 -0
  28. data/assets/javascripts/date/date-cs-CZ.js +4526 -0
  29. data/assets/javascripts/date/date-cy-GB.js +4526 -0
  30. data/assets/javascripts/date/date-da-DK.js +4526 -0
  31. data/assets/javascripts/date/date-de-AT.js +4526 -0
  32. data/assets/javascripts/date/date-de-CH.js +4526 -0
  33. data/assets/javascripts/date/date-de-DE.js +4526 -0
  34. data/assets/javascripts/date/date-de-LI.js +4526 -0
  35. data/assets/javascripts/date/date-de-LU.js +4526 -0
  36. data/assets/javascripts/date/date-dv-MV.js +4526 -0
  37. data/assets/javascripts/date/date-el-GR.js +4526 -0
  38. data/assets/javascripts/date/date-en-029.js +4526 -0
  39. data/assets/javascripts/date/date-en-AU.js +4526 -0
  40. data/assets/javascripts/date/date-en-BZ.js +4526 -0
  41. data/assets/javascripts/date/date-en-CA.js +4526 -0
  42. data/assets/javascripts/date/date-en-GB.js +4526 -0
  43. data/assets/javascripts/date/date-en-IE.js +4526 -0
  44. data/assets/javascripts/date/date-en-JM.js +4526 -0
  45. data/assets/javascripts/date/date-en-NZ.js +4526 -0
  46. data/assets/javascripts/date/date-en-PH.js +4526 -0
  47. data/assets/javascripts/date/date-en-TT.js +4526 -0
  48. data/assets/javascripts/date/date-en-US.js +4096 -0
  49. data/assets/javascripts/date/date-en-ZA.js +4526 -0
  50. data/assets/javascripts/date/date-en-ZW.js +4526 -0
  51. data/assets/javascripts/date/date-es-AR.js +4526 -0
  52. data/assets/javascripts/date/date-es-BO.js +4526 -0
  53. data/assets/javascripts/date/date-es-CL.js +4526 -0
  54. data/assets/javascripts/date/date-es-CO.js +4526 -0
  55. data/assets/javascripts/date/date-es-CR.js +4526 -0
  56. data/assets/javascripts/date/date-es-DO.js +4526 -0
  57. data/assets/javascripts/date/date-es-EC.js +4526 -0
  58. data/assets/javascripts/date/date-es-ES.js +4526 -0
  59. data/assets/javascripts/date/date-es-GT.js +4526 -0
  60. data/assets/javascripts/date/date-es-HN.js +4526 -0
  61. data/assets/javascripts/date/date-es-MX.js +4526 -0
  62. data/assets/javascripts/date/date-es-NI.js +4526 -0
  63. data/assets/javascripts/date/date-es-PA.js +4526 -0
  64. data/assets/javascripts/date/date-es-PE.js +4526 -0
  65. data/assets/javascripts/date/date-es-PR.js +4526 -0
  66. data/assets/javascripts/date/date-es-PY.js +4526 -0
  67. data/assets/javascripts/date/date-es-SV.js +4526 -0
  68. data/assets/javascripts/date/date-es-UY.js +4526 -0
  69. data/assets/javascripts/date/date-es-VE.js +4526 -0
  70. data/assets/javascripts/date/date-et-EE.js +4526 -0
  71. data/assets/javascripts/date/date-eu-ES.js +4526 -0
  72. data/assets/javascripts/date/date-fa-IR.js +4526 -0
  73. data/assets/javascripts/date/date-fi-FI.js +4526 -0
  74. data/assets/javascripts/date/date-fo-FO.js +4526 -0
  75. data/assets/javascripts/date/date-fr-BE.js +4526 -0
  76. data/assets/javascripts/date/date-fr-CA.js +4526 -0
  77. data/assets/javascripts/date/date-fr-CH.js +4526 -0
  78. data/assets/javascripts/date/date-fr-FR.js +4526 -0
  79. data/assets/javascripts/date/date-fr-LU.js +4526 -0
  80. data/assets/javascripts/date/date-fr-MC.js +4526 -0
  81. data/assets/javascripts/date/date-gl-ES.js +4526 -0
  82. data/assets/javascripts/date/date-gu-IN.js +4526 -0
  83. data/assets/javascripts/date/date-he-IL.js +4526 -0
  84. data/assets/javascripts/date/date-hi-IN.js +4526 -0
  85. data/assets/javascripts/date/date-hr-BA.js +4526 -0
  86. data/assets/javascripts/date/date-hr-HR.js +4526 -0
  87. data/assets/javascripts/date/date-hu-HU.js +4526 -0
  88. data/assets/javascripts/date/date-hy-AM.js +4526 -0
  89. data/assets/javascripts/date/date-id-ID.js +4526 -0
  90. data/assets/javascripts/date/date-is-IS.js +4526 -0
  91. data/assets/javascripts/date/date-it-CH.js +4526 -0
  92. data/assets/javascripts/date/date-it-IT.js +4526 -0
  93. data/assets/javascripts/date/date-ja-JP.js +4526 -0
  94. data/assets/javascripts/date/date-ka-GE.js +4526 -0
  95. data/assets/javascripts/date/date-kk-KZ.js +4526 -0
  96. data/assets/javascripts/date/date-kn-IN.js +4526 -0
  97. data/assets/javascripts/date/date-ko-KR.js +4526 -0
  98. data/assets/javascripts/date/date-kok-IN.js +4526 -0
  99. data/assets/javascripts/date/date-ky-KG.js +4526 -0
  100. data/assets/javascripts/date/date-lt-LT.js +4526 -0
  101. data/assets/javascripts/date/date-lv-LV.js +4526 -0
  102. data/assets/javascripts/date/date-mi-NZ.js +4526 -0
  103. data/assets/javascripts/date/date-mk-MK.js +4526 -0
  104. data/assets/javascripts/date/date-mn-MN.js +4526 -0
  105. data/assets/javascripts/date/date-mr-IN.js +4526 -0
  106. data/assets/javascripts/date/date-ms-BN.js +4526 -0
  107. data/assets/javascripts/date/date-ms-MY.js +4526 -0
  108. data/assets/javascripts/date/date-mt-MT.js +4526 -0
  109. data/assets/javascripts/date/date-nb-NO.js +4526 -0
  110. data/assets/javascripts/date/date-nl-BE.js +4526 -0
  111. data/assets/javascripts/date/date-nl-NL.js +4526 -0
  112. data/assets/javascripts/date/date-nn-NO.js +4526 -0
  113. data/assets/javascripts/date/date-ns-ZA.js +4526 -0
  114. data/assets/javascripts/date/date-pa-IN.js +4526 -0
  115. data/assets/javascripts/date/date-pl-PL.js +4526 -0
  116. data/assets/javascripts/date/date-pt-BR.js +4526 -0
  117. data/assets/javascripts/date/date-pt-PT.js +4526 -0
  118. data/assets/javascripts/date/date-quz-BO.js +4526 -0
  119. data/assets/javascripts/date/date-quz-EC.js +4526 -0
  120. data/assets/javascripts/date/date-quz-PE.js +4526 -0
  121. data/assets/javascripts/date/date-ro-RO.js +4526 -0
  122. data/assets/javascripts/date/date-ru-RU.js +4526 -0
  123. data/assets/javascripts/date/date-sa-IN.js +4526 -0
  124. data/assets/javascripts/date/date-se-FI.js +4526 -0
  125. data/assets/javascripts/date/date-se-NO.js +4526 -0
  126. data/assets/javascripts/date/date-se-SE.js +4526 -0
  127. data/assets/javascripts/date/date-sk-SK.js +4526 -0
  128. data/assets/javascripts/date/date-sl-SI.js +4526 -0
  129. data/assets/javascripts/date/date-sma-NO.js +4526 -0
  130. data/assets/javascripts/date/date-sma-SE.js +4526 -0
  131. data/assets/javascripts/date/date-smj-NO.js +4526 -0
  132. data/assets/javascripts/date/date-smj-SE.js +4526 -0
  133. data/assets/javascripts/date/date-smn-FI.js +4526 -0
  134. data/assets/javascripts/date/date-sms-FI.js +4526 -0
  135. data/assets/javascripts/date/date-sq-AL.js +4526 -0
  136. data/assets/javascripts/date/date-sr-Cyrl-BA.js +4526 -0
  137. data/assets/javascripts/date/date-sr-Cyrl-CS.js +4526 -0
  138. data/assets/javascripts/date/date-sr-Latn-BA.js +4526 -0
  139. data/assets/javascripts/date/date-sr-Latn-CS.js +4526 -0
  140. data/assets/javascripts/date/date-sv-FI.js +4526 -0
  141. data/assets/javascripts/date/date-sv-SE.js +4526 -0
  142. data/assets/javascripts/date/date-sw-KE.js +4526 -0
  143. data/assets/javascripts/date/date-syr-SY.js +4526 -0
  144. data/assets/javascripts/date/date-ta-IN.js +4526 -0
  145. data/assets/javascripts/date/date-te-IN.js +4526 -0
  146. data/assets/javascripts/date/date-th-TH.js +4526 -0
  147. data/assets/javascripts/date/date-tn-ZA.js +4526 -0
  148. data/assets/javascripts/date/date-tr-TR.js +4526 -0
  149. data/assets/javascripts/date/date-tt-RU.js +4526 -0
  150. data/assets/javascripts/date/date-uk-UA.js +4526 -0
  151. data/assets/javascripts/date/date-ur-PK.js +4526 -0
  152. data/assets/javascripts/date/date-uz-Cyrl-UZ.js +4526 -0
  153. data/assets/javascripts/date/date-uz-Latn-UZ.js +4526 -0
  154. data/assets/javascripts/date/date-vi-VN.js +4526 -0
  155. data/assets/javascripts/date/date-xh-ZA.js +4526 -0
  156. data/assets/javascripts/date/date-zh-CN.js +4526 -0
  157. data/assets/javascripts/date/date-zh-HK.js +4526 -0
  158. data/assets/javascripts/date/date-zh-MO.js +4526 -0
  159. data/assets/javascripts/date/date-zh-SG.js +4526 -0
  160. data/assets/javascripts/date/date-zh-TW.js +4526 -0
  161. data/assets/javascripts/date/date-zu-ZA.js +4526 -0
  162. data/lib/gentelella-rails.rb +0 -1
  163. data/lib/gentelella/engine.rb +1 -0
  164. data/lib/gentelella/version.rb +1 -1
  165. data/lib/tasks/bower.rake +4 -0
  166. metadata +161 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4039debf1d598763828399ad5fbb08482b5eefd5
4
- data.tar.gz: 4c0d54518b31aaba2197b38989c3aba5340f3a61
3
+ metadata.gz: 4809b8ee5389a733ddf1f43427372ef50432b987
4
+ data.tar.gz: 19c4c0d80d40187d2b4ba00ad48f455a2a627ca3
5
5
  SHA512:
6
- metadata.gz: db968b7a98d9fe79ea4ac2b1082f832069f5f1e1066b5348a46af6a4db1f31697e7d3ce5da7880c5983a982721639e776773d112d58c9e8860776e1c8f30127d
7
- data.tar.gz: b6738d6dbc0fe976bf84015c14f4569d833b681922e0dcab62953dbd611130e5dfef4956b4935d345fbae1ad2d64f8dfa3d4085841c195f339f2f10401f9db11
6
+ metadata.gz: f469f7c294e783ee949ec797c41f4ec9ecca4f6eee3be4d899800889a063294162a96b0e8e4950fac8deb70b26ef54e9331cfe1b1f02c160e49b454acba10be1
7
+ data.tar.gz: acfabd71d8f72b1537881ca36cf9d7b410c20b88b70d7b4d96e804d66f75ca580d0fa289e71a03a3face60f61cb68e64fa7abeedfe9a6a69218fc1d1a366ad9a
data/README.md CHANGED
@@ -30,7 +30,7 @@ out of date, I utilized the Bower supplied version.
30
30
  You may also find the demo [Rails 5.x project on github](https://github.com/mwlang/gentelella-rails-demo)
31
31
 
32
32
  ## Theme Demo
33
- ![Gentelella Bootstrap Admin Template](https://github.com/mwlang/gentelella-rails-demo/blob/master/public/images/gentelella-admin-template-preview.jpg "Gentelella Theme Browser Preview")
33
+ ![Gentelella Bootstrap Admin Template](https://github.com/mwlang/gentelella-rails-demo/blob/master/examples/shared/public/images/gentelella-admin-template-preview.jpg "Gentelella Theme Browser Preview")
34
34
 
35
35
  **[Template Demo](https://colorlib.com/polygon/gentelella/index.html)**
36
36
 
@@ -48,6 +48,8 @@ bundle install
48
48
  rails g gentelella:install
49
49
  ```
50
50
 
51
+ NOTE: If the generator fails to work, then make sure you stop Spring: ```spring stop``` and then try again.
52
+
51
53
  Add the following to your assets/javascripts/application.js
52
54
 
53
55
  ```javascript
@@ -68,6 +70,9 @@ If you're working with jquery.vmap, then your application.js will look something
68
70
  There is no need to include bootstrap-sprockets, font-awesome, jquery, etc. as these are all included via
69
71
  the gem when you "require gentelella"
70
72
 
73
+ NOTE: gentella-custom is meant to be edited! If you find things breaking from include/import lines of this file, comment out
74
+ the offending lines. gentella-custom is where you can place all project-specific scripts.
75
+
71
76
  Finally, add the stylesheet directives to your assets/stylesheets/application.scss
72
77
 
73
78
  ```sass
@@ -0,0 +1,5 @@
1
+ // This is the default set of what you get when you require date in
2
+ // your application. Each individual library can be used separately
3
+ //
4
+ //= require date/date-en-US
5
+ //= require date/core
@@ -0,0 +1,4339 @@
1
+ /**
2
+ * @overview datejs
3
+ * @version 1.0.0-rc3
4
+ * @author Gregory Wild-Smith <gregory@wild-smith.com>
5
+ * @copyright 2014 Gregory Wild-Smith
6
+ * @license MIT
7
+ * @homepage https://github.com/abritinthebay/datejs
8
+ */(function () {
9
+ var $D = Date;
10
+ var lang = Date.CultureStrings ? Date.CultureStrings.lang : null;
11
+ var loggedKeys = {}; // for debug purposes.
12
+ var getText = {
13
+ getFromKey: function (key, countryCode) {
14
+ var output;
15
+ if (Date.CultureStrings && Date.CultureStrings[countryCode] && Date.CultureStrings[countryCode][key]) {
16
+ output = Date.CultureStrings[countryCode][key];
17
+ } else {
18
+ output = getText.buildFromDefault(key);
19
+ }
20
+ if (key.charAt(0) === "/") { // Assume it's a regex
21
+ output = getText.buildFromRegex(key, countryCode);
22
+ }
23
+ return output;
24
+ },
25
+ getFromObjectValues: function (obj, countryCode) {
26
+ var key, output = {};
27
+ for(key in obj) {
28
+ if (obj.hasOwnProperty(key)) {
29
+ output[key] = getText.getFromKey(obj[key], countryCode);
30
+ }
31
+ }
32
+ return output;
33
+ },
34
+ getFromObjectKeys: function (obj, countryCode) {
35
+ var key, output = {};
36
+ for(key in obj) {
37
+ if (obj.hasOwnProperty(key)) {
38
+ output[getText.getFromKey(key, countryCode)] = obj[key];
39
+ }
40
+ }
41
+ return output;
42
+ },
43
+ getFromArray: function (arr, countryCode) {
44
+ var output = [];
45
+ for (var i=0; i < arr.length; i++){
46
+ if (i in arr) {
47
+ output[i] = getText.getFromKey(arr[i], countryCode);
48
+ }
49
+ }
50
+ return output;
51
+ },
52
+ buildFromDefault: function (key) {
53
+ var output, length, split, last;
54
+ switch(key) {
55
+ case "name":
56
+ output = "en-US";
57
+ break;
58
+ case "englishName":
59
+ output = "English (United States)";
60
+ break;
61
+ case "nativeName":
62
+ output = "English (United States)";
63
+ break;
64
+ case "twoDigitYearMax":
65
+ output = 2049;
66
+ break;
67
+ case "firstDayOfWeek":
68
+ output = 0;
69
+ break;
70
+ default:
71
+ output = key;
72
+ split = key.split("_");
73
+ length = split.length;
74
+ if (length > 1 && key.charAt(0) !== "/") {
75
+ // if the key isn't a regex and it has a split.
76
+ last = split[(length - 1)].toLowerCase();
77
+ if (last === "initial" || last === "abbr") {
78
+ output = split[0];
79
+ }
80
+ }
81
+ break;
82
+ }
83
+ return output;
84
+ },
85
+ buildFromRegex: function (key, countryCode) {
86
+ var output;
87
+ if (Date.CultureStrings && Date.CultureStrings[countryCode] && Date.CultureStrings[countryCode][key]) {
88
+ output = new RegExp(Date.CultureStrings[countryCode][key], "i");
89
+ } else {
90
+ output = new RegExp(key.replace(new RegExp("/", "g"),""), "i");
91
+ }
92
+ return output;
93
+ }
94
+ };
95
+
96
+ var shallowMerge = function (obj1, obj2) {
97
+ for (var attrname in obj2) {
98
+ if (obj2.hasOwnProperty(attrname)) {
99
+ obj1[attrname] = obj2[attrname];
100
+ }
101
+ }
102
+ };
103
+
104
+ var __ = function (key, language) {
105
+ var countryCode = (language) ? language : lang;
106
+ loggedKeys[key] = key;
107
+ if (typeof key === "object") {
108
+ if (key instanceof Array) {
109
+ return getText.getFromArray(key, countryCode);
110
+ } else {
111
+ return getText.getFromObjectKeys(key, countryCode);
112
+ }
113
+ } else {
114
+ return getText.getFromKey(key, countryCode);
115
+ }
116
+ };
117
+
118
+ var loadI18nScript = function (code) {
119
+ // paatterned after jQuery's getScript.
120
+ var url = Date.Config.i18n + code + ".js";
121
+ var head = document.getElementsByTagName("head")[0] || document.documentElement;
122
+ var script = document.createElement("script");
123
+ script.src = url;
124
+
125
+ var completed = false;
126
+ var events = {
127
+ done: function (){} // placeholder function
128
+ };
129
+ // Attach handlers for all browsers
130
+ script.onload = script.onreadystatechange = function() {
131
+ if ( !completed && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) {
132
+ events.done();
133
+ head.removeChild(script);
134
+ }
135
+ };
136
+
137
+ setTimeout(function() {
138
+ head.insertBefore(script, head.firstChild);
139
+ }, 0); // allows return to execute first
140
+
141
+ return {
142
+ done: function (cb) {
143
+ events.done = function() {
144
+ if (cb) {
145
+ setTimeout(cb,0);
146
+ }
147
+ };
148
+ }
149
+ };
150
+ };
151
+
152
+ var buildInfo = {
153
+ buildFromMethodHash: function (obj) {
154
+ var key;
155
+ for(key in obj) {
156
+ if (obj.hasOwnProperty(key)) {
157
+ obj[key] = buildInfo[obj[key]]();
158
+ }
159
+ }
160
+ return obj;
161
+ },
162
+ timeZoneDST: function () {
163
+ var DST = {
164
+ "CHADT": "+1345",
165
+ "NZDT": "+1300",
166
+ "AEDT": "+1100",
167
+ "ACDT": "+1030",
168
+ "AZST": "+0500",
169
+ "IRDT": "+0430",
170
+ "EEST": "+0300",
171
+ "CEST": "+0200",
172
+ "BST": "+0100",
173
+ "PMDT": "-0200",
174
+ "ADT": "-0300",
175
+ "NDT": "-0230",
176
+ "EDT": "-0400",
177
+ "CDT": "-0500",
178
+ "MDT": "-0600",
179
+ "PDT": "-0700",
180
+ "AKDT": "-0800",
181
+ "HADT": "-0900"
182
+ };
183
+ return __(DST);
184
+ },
185
+ timeZoneStandard: function () {
186
+ var standard = {
187
+ "LINT": "+1400",
188
+ "TOT": "+1300",
189
+ "CHAST": "+1245",
190
+ "NZST": "+1200",
191
+ "NFT": "+1130",
192
+ "SBT": "+1100",
193
+ "AEST": "+1000",
194
+ "ACST": "+0930",
195
+ "JST": "+0900",
196
+ "CWST": "+0845",
197
+ "CT": "+0800",
198
+ "ICT": "+0700",
199
+ "MMT": "+0630",
200
+ "BST": "+0600",
201
+ "NPT": "+0545",
202
+ "IST": "+0530",
203
+ "PKT": "+0500",
204
+ "AFT": "+0430",
205
+ "MSK": "+0400",
206
+ "IRST": "+0330",
207
+ "FET": "+0300",
208
+ "EET": "+0200",
209
+ "CET": "+0100",
210
+ "GMT": "+0000",
211
+ "UTC": "+0000",
212
+ "CVT": "-0100",
213
+ "GST": "-0200",
214
+ "BRT": "-0300",
215
+ "NST": "-0330",
216
+ "AST": "-0400",
217
+ "EST": "-0500",
218
+ "CST": "-0600",
219
+ "MST": "-0700",
220
+ "PST": "-0800",
221
+ "AKST": "-0900",
222
+ "MIT": "-0930",
223
+ "HST": "-1000",
224
+ "SST": "-1100",
225
+ "BIT": "-1200"
226
+ };
227
+ return __(standard);
228
+ },
229
+ timeZones: function (data) {
230
+ var zone;
231
+ data.timezones = [];
232
+ for (zone in data.abbreviatedTimeZoneStandard) {
233
+ if (data.abbreviatedTimeZoneStandard.hasOwnProperty(zone)) {
234
+ data.timezones.push({ name: zone, offset: data.abbreviatedTimeZoneStandard[zone]});
235
+ }
236
+ }
237
+ for (zone in data.abbreviatedTimeZoneDST) {
238
+ if (data.abbreviatedTimeZoneDST.hasOwnProperty(zone)) {
239
+ data.timezones.push({ name: zone, offset: data.abbreviatedTimeZoneDST[zone], dst: true});
240
+ }
241
+ }
242
+ return data.timezones;
243
+ },
244
+ days: function () {
245
+ return __(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]);
246
+ },
247
+ dayAbbr: function () {
248
+ return __(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]);
249
+ },
250
+ dayShortNames: function () {
251
+ return __(["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]);
252
+ },
253
+ dayFirstLetters: function () {
254
+ return __(["S_Sun_Initial", "M_Mon_Initial", "T_Tues_Initial", "W_Wed_Initial", "T_Thu_Initial", "F_Fri_Initial", "S_Sat_Initial"]);
255
+ },
256
+ months: function () {
257
+ return __(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
258
+ },
259
+ monthAbbr: function () {
260
+ return __(["Jan_Abbr", "Feb_Abbr", "Mar_Abbr", "Apr_Abbr", "May_Abbr", "Jun_Abbr", "Jul_Abbr", "Aug_Abbr", "Sep_Abbr", "Oct_Abbr", "Nov_Abbr", "Dec_Abbr"]);
261
+ },
262
+ formatPatterns: function () {
263
+ return getText.getFromObjectValues({
264
+ shortDate: "M/d/yyyy",
265
+ longDate: "dddd, MMMM dd, yyyy",
266
+ shortTime: "h:mm tt",
267
+ longTime: "h:mm:ss tt",
268
+ fullDateTime: "dddd, MMMM dd, yyyy h:mm:ss tt",
269
+ sortableDateTime: "yyyy-MM-ddTHH:mm:ss",
270
+ universalSortableDateTime: "yyyy-MM-dd HH:mm:ssZ",
271
+ rfc1123: "ddd, dd MMM yyyy HH:mm:ss",
272
+ monthDay: "MMMM dd",
273
+ yearMonth: "MMMM, yyyy"
274
+ }, Date.i18n.currentLanguage());
275
+ },
276
+ regex: function () {
277
+ return getText.getFromObjectValues({
278
+ inTheMorning: "/( in the )(morn(ing)?)\\b/",
279
+ thisMorning: "/(this )(morn(ing)?)\\b/",
280
+ amThisMorning: "/(\b\\d(am)? )(this )(morn(ing)?)/",
281
+ inTheEvening: "/( in the )(even(ing)?)\\b/",
282
+ thisEvening: "/(this )(even(ing)?)\\b/",
283
+ pmThisEvening: "/(\b\\d(pm)? )(this )(even(ing)?)/",
284
+ jan: "/jan(uary)?/",
285
+ feb: "/feb(ruary)?/",
286
+ mar: "/mar(ch)?/",
287
+ apr: "/apr(il)?/",
288
+ may: "/may/",
289
+ jun: "/jun(e)?/",
290
+ jul: "/jul(y)?/",
291
+ aug: "/aug(ust)?/",
292
+ sep: "/sep(t(ember)?)?/",
293
+ oct: "/oct(ober)?/",
294
+ nov: "/nov(ember)?/",
295
+ dec: "/dec(ember)?/",
296
+ sun: "/^su(n(day)?)?/",
297
+ mon: "/^mo(n(day)?)?/",
298
+ tue: "/^tu(e(s(day)?)?)?/",
299
+ wed: "/^we(d(nesday)?)?/",
300
+ thu: "/^th(u(r(s(day)?)?)?)?/",
301
+ fri: "/fr(i(day)?)?/",
302
+ sat: "/^sa(t(urday)?)?/",
303
+ future: "/^next/",
304
+ past: "/^last|past|prev(ious)?/",
305
+ add: "/^(\\+|aft(er)?|from|hence)/",
306
+ subtract: "/^(\\-|bef(ore)?|ago)/",
307
+ yesterday: "/^yes(terday)?/",
308
+ today: "/^t(od(ay)?)?/",
309
+ tomorrow: "/^tom(orrow)?/",
310
+ now: "/^n(ow)?/",
311
+ millisecond: "/^ms|milli(second)?s?/",
312
+ second: "/^sec(ond)?s?/",
313
+ minute: "/^mn|min(ute)?s?/",
314
+ hour: "/^h(our)?s?/",
315
+ week: "/^w(eek)?s?/",
316
+ month: "/^m(onth)?s?/",
317
+ day: "/^d(ay)?s?/",
318
+ year: "/^y(ear)?s?/",
319
+ shortMeridian: "/^(a|p)/",
320
+ longMeridian: "/^(a\\.?m?\\.?|p\\.?m?\\.?)/",
321
+ timezone: "/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)/",
322
+ ordinalSuffix: "/^\\s*(st|nd|rd|th)/",
323
+ timeContext: "/^\\s*(\\:|a(?!u|p)|p)/"
324
+ }, Date.i18n.currentLanguage());
325
+ }
326
+ };
327
+
328
+ var CultureInfo = function () {
329
+ var info = getText.getFromObjectValues({
330
+ name: "name",
331
+ englishName: "englishName",
332
+ nativeName: "nativeName",
333
+ amDesignator: "AM",
334
+ pmDesignator: "PM",
335
+ firstDayOfWeek: "firstDayOfWeek",
336
+ twoDigitYearMax: "twoDigitYearMax",
337
+ dateElementOrder: "mdy"
338
+ }, Date.i18n.currentLanguage());
339
+
340
+ var constructedInfo = buildInfo.buildFromMethodHash({
341
+ dayNames: "days",
342
+ abbreviatedDayNames: "dayAbbr",
343
+ shortestDayNames: "dayShortNames",
344
+ firstLetterDayNames: "dayFirstLetters",
345
+ monthNames: "months",
346
+ abbreviatedMonthNames: "monthAbbr",
347
+ formatPatterns: "formatPatterns",
348
+ regexPatterns: "regex",
349
+ abbreviatedTimeZoneDST: "timeZoneDST",
350
+ abbreviatedTimeZoneStandard: "timeZoneStandard"
351
+ });
352
+
353
+ shallowMerge(info, constructedInfo);
354
+ buildInfo.timeZones(info);
355
+ return info;
356
+ };
357
+
358
+ $D.i18n = {
359
+ __: function (key, lang) {
360
+ return __(key, lang);
361
+ },
362
+ currentLanguage: function () {
363
+ return lang || "en-US";
364
+ },
365
+ setLanguage: function (code, force, cb) {
366
+ var async = false;
367
+ if (force || code === "en-US" || (!!Date.CultureStrings && !!Date.CultureStrings[code])) {
368
+ lang = code;
369
+ Date.CultureStrings = Date.CultureStrings || {};
370
+ Date.CultureStrings.lang = code;
371
+ Date.CultureInfo = new CultureInfo();
372
+ } else {
373
+ if (!(!!Date.CultureStrings && !!Date.CultureStrings[code])) {
374
+ if (typeof exports !== "undefined" && this.exports !== exports) {
375
+ // we're in a Node enviroment, load it using require
376
+ try {
377
+ require("../i18n/" + code + ".js");
378
+ lang = code;
379
+ Date.CultureStrings.lang = code;
380
+ Date.CultureInfo = new CultureInfo();
381
+ } catch (e) {
382
+ // var str = "The language for '" + code + "' could not be loaded by Node. It likely does not exist.";
383
+ throw new Error("The DateJS IETF language tag '" + code + "' could not be loaded by Node. It likely does not exist.");
384
+ }
385
+ } else if (Date.Config && Date.Config.i18n) {
386
+ // we know the location of the files, so lets load them
387
+ async = true;
388
+ loadI18nScript(code).done(function(){
389
+ lang = code;
390
+ Date.CultureStrings = Date.CultureStrings || {};
391
+ Date.CultureStrings.lang = code;
392
+ Date.CultureInfo = new CultureInfo();
393
+ $D.Parsing.Normalizer.buildReplaceData(); // because this is async
394
+ if ($D.Grammar) {
395
+ $D.Grammar.buildGrammarFormats(); // so we can parse those strings...
396
+ }
397
+ if (cb) {
398
+ setTimeout(cb,0);
399
+ }
400
+ });
401
+ } else {
402
+ Date.console.error("The DateJS IETF language tag '" + code + "' is not available and has not been loaded.");
403
+ return false;
404
+ }
405
+ }
406
+ }
407
+ $D.Parsing.Normalizer.buildReplaceData(); // rebuild normalizer strings
408
+ if ($D.Grammar) {
409
+ $D.Grammar.buildGrammarFormats(); // so we can parse those strings...
410
+ }
411
+ if (!async && cb) {
412
+ setTimeout(cb,0);
413
+ }
414
+ },
415
+ getLoggedKeys: function () {
416
+ return loggedKeys;
417
+ },
418
+ updateCultureInfo: function () {
419
+ Date.CultureInfo = new CultureInfo();
420
+ }
421
+ };
422
+ $D.i18n.updateCultureInfo(); // run automatically
423
+ }());
424
+ (function () {
425
+ var $D = Date,
426
+ $P = $D.prototype,
427
+ p = function (s, l) {
428
+ if (!l) {
429
+ l = 2;
430
+ }
431
+ return ("000" + s).slice(l * -1);
432
+ };
433
+
434
+ if (typeof window !== "undefined" && typeof window.console !== "undefined" && typeof window.console.log !== "undefined") {
435
+ $D.console = console; // used only to raise non-critical errors if available
436
+ } else {
437
+ // set mock so we don't give errors.
438
+ $D.console = {
439
+ log: function(){},
440
+ error: function(){}
441
+ };
442
+ }
443
+ $D.Config = $D.Config || {};
444
+
445
+ $D.initOverloads = function() {
446
+ /**
447
+ * Overload of Date.now. Allows an alternate call for Date.now where it returns the
448
+ * current Date as an object rather than just milliseconds since the Unix Epoch.
449
+ *
450
+ * Also provides an implementation of now() for browsers (IE<9) that don't have it.
451
+ *
452
+ * Backwards compatible so with work with either:
453
+ * Date.now() [returns ms]
454
+ * or
455
+ * Date.now(true) [returns Date]
456
+ */
457
+ if (!$D.now) {
458
+ $D._now = function now() {
459
+ return new Date().getTime();
460
+ };
461
+ } else if (!$D._now) {
462
+ $D._now = $D.now;
463
+ }
464
+
465
+ $D.now = function (returnObj) {
466
+ if (returnObj) {
467
+ return $D.present();
468
+ } else {
469
+ return $D._now();
470
+ }
471
+ };
472
+
473
+ if ( !$P.toISOString ) {
474
+ $P.toISOString = function() {
475
+ return this.getUTCFullYear() +
476
+ "-" + p(this.getUTCMonth() + 1) +
477
+ "-" + p(this.getUTCDate()) +
478
+ "T" + p(this.getUTCHours()) +
479
+ ":" + p(this.getUTCMinutes()) +
480
+ ":" + p(this.getUTCSeconds()) +
481
+ "." + String( (this.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5) +
482
+ "Z";
483
+ };
484
+ }
485
+
486
+ // private
487
+ if ( $P._toString === undefined ){
488
+ $P._toString = $P.toString;
489
+ }
490
+
491
+ };
492
+ $D.initOverloads();
493
+
494
+
495
+ /**
496
+ * Gets a date that is set to the current date. The time is set to the start of the day (00:00 or 12:00 AM).
497
+ * @return {Date} The current date.
498
+ */
499
+ $D.today = function () {
500
+ return new Date().clearTime();
501
+ };
502
+
503
+ /**
504
+ * Gets a date that is set to the current date and time (same as new Date, but chainable)
505
+ * @return {Date} The current date.
506
+ */
507
+ $D.present = function () {
508
+ return new Date();
509
+ };
510
+
511
+ /**
512
+ * Compares the first date to the second date and returns an number indication of their relative values.
513
+ * @param {Date} First Date object to compare [Required].
514
+ * @param {Date} Second Date object to compare to [Required].
515
+ * @return {Number} -1 = date1 is lessthan date2. 0 = values are equal. 1 = date1 is greaterthan date2.
516
+ */
517
+ $D.compare = function (date1, date2) {
518
+ if (isNaN(date1) || isNaN(date2)) {
519
+ throw new Error(date1 + " - " + date2);
520
+ } else if (date1 instanceof Date && date2 instanceof Date) {
521
+ return (date1 < date2) ? -1 : (date1 > date2) ? 1 : 0;
522
+ } else {
523
+ throw new TypeError(date1 + " - " + date2);
524
+ }
525
+ };
526
+
527
+ /**
528
+ * Compares the first Date object to the second Date object and returns true if they are equal.
529
+ * @param {Date} First Date object to compare [Required]
530
+ * @param {Date} Second Date object to compare to [Required]
531
+ * @return {Boolean} true if dates are equal. false if they are not equal.
532
+ */
533
+ $D.equals = function (date1, date2) {
534
+ return (date1.compareTo(date2) === 0);
535
+ };
536
+
537
+ /**
538
+ * Gets the language appropriate day name when given the day number(0-6)
539
+ * eg - 0 == Sunday
540
+ * @return {String} The day name
541
+ */
542
+ $D.getDayName = function (n) {
543
+ return Date.CultureInfo.dayNames[n];
544
+ };
545
+
546
+ /**
547
+ * Gets the day number (0-6) if given a CultureInfo specific string which is a valid dayName, abbreviatedDayName or shortestDayName (two char).
548
+ * @param {String} The name of the day (eg. "Monday, "Mon", "tuesday", "tue", "We", "we").
549
+ * @return {Number} The day number
550
+ */
551
+ $D.getDayNumberFromName = function (name) {
552
+ var n = Date.CultureInfo.dayNames, m = Date.CultureInfo.abbreviatedDayNames, o = Date.CultureInfo.shortestDayNames, s = name.toLowerCase();
553
+ for (var i = 0; i < n.length; i++) {
554
+ if (n[i].toLowerCase() === s || m[i].toLowerCase() === s || o[i].toLowerCase() === s) {
555
+ return i;
556
+ }
557
+ }
558
+ return -1;
559
+ };
560
+
561
+ /**
562
+ * Gets the month number (0-11) if given a Culture Info specific string which is a valid monthName or abbreviatedMonthName.
563
+ * @param {String} The name of the month (eg. "February, "Feb", "october", "oct").
564
+ * @return {Number} The day number
565
+ */
566
+ $D.getMonthNumberFromName = function (name) {
567
+ var n = Date.CultureInfo.monthNames, m = Date.CultureInfo.abbreviatedMonthNames, s = name.toLowerCase();
568
+ for (var i = 0; i < n.length; i++) {
569
+ if (n[i].toLowerCase() === s || m[i].toLowerCase() === s) {
570
+ return i;
571
+ }
572
+ }
573
+ return -1;
574
+ };
575
+
576
+ /**
577
+ * Gets the language appropriate month name when given the month number(0-11)
578
+ * eg - 0 == January
579
+ * @return {String} The month name
580
+ */
581
+ $D.getMonthName = function (n) {
582
+ return Date.CultureInfo.monthNames[n];
583
+ };
584
+
585
+ /**
586
+ * Determines if the current date instance is within a LeapYear.
587
+ * @param {Number} The year.
588
+ * @return {Boolean} true if date is within a LeapYear, otherwise false.
589
+ */
590
+ $D.isLeapYear = function (year) {
591
+ return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
592
+ };
593
+
594
+ /**
595
+ * Gets the number of days in the month, given a year and month value. Automatically corrects for LeapYear.
596
+ * @param {Number} The year.
597
+ * @param {Number} The month (0-11).
598
+ * @return {Number} The number of days in the month.
599
+ */
600
+ $D.getDaysInMonth = function (year, month) {
601
+ if (!month && $D.validateMonth(year)) {
602
+ month = year;
603
+ year = Date.today().getFullYear();
604
+ }
605
+ return [31, ($D.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
606
+ };
607
+
608
+ $P.getDaysInMonth = function () {
609
+ return $D.getDaysInMonth(this.getFullYear(), this.getMonth());
610
+ };
611
+
612
+ $D.getTimezoneAbbreviation = function (offset, dst) {
613
+ var p, n = (dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST : Date.CultureInfo.abbreviatedTimeZoneStandard;
614
+ for (p in n) {
615
+ if (n.hasOwnProperty(p)) {
616
+ if (n[p] === offset) {
617
+ return p;
618
+ }
619
+ }
620
+ }
621
+ return null;
622
+ };
623
+
624
+ $D.getTimezoneOffset = function (name, dst) {
625
+ var i, a =[], z = Date.CultureInfo.timezones;
626
+ if (!name) { name = (new Date()).getTimezone();}
627
+ for (i = 0; i < z.length; i++) {
628
+ if (z[i].name === name.toUpperCase()) {
629
+ a.push(i);
630
+ }
631
+ }
632
+ if (!z[a[0]]) {
633
+ return null;
634
+ }
635
+ if (a.length === 1 || !dst) {
636
+ return z[a[0]].offset;
637
+ } else {
638
+ for (i=0; i < a.length; i++) {
639
+ if (z[a[i]].dst) {
640
+ return z[a[i]].offset;
641
+ }
642
+ }
643
+ }
644
+ };
645
+
646
+ $D.getQuarter = function (d) {
647
+ d = d || new Date(); // If no date supplied, use today
648
+ var q = [1,2,3,4];
649
+ return q[Math.floor(d.getMonth() / 3)]; // ~~~ is a bitwise op. Faster than Math.floor
650
+ };
651
+
652
+ $D.getDaysLeftInQuarter = function (d) {
653
+ d = d || new Date();
654
+ var qEnd = new Date(d);
655
+ qEnd.setMonth(qEnd.getMonth() + 3 - qEnd.getMonth() % 3, 0);
656
+ return Math.floor((qEnd - d) / 8.64e7);
657
+ };
658
+
659
+ // private
660
+ var validate = function (n, min, max, name) {
661
+ name = name ? name : "Object";
662
+ if (typeof n === "undefined") {
663
+ return false;
664
+ } else if (typeof n !== "number") {
665
+ throw new TypeError(n + " is not a Number.");
666
+ } else if (n < min || n > max) {
667
+ // As failing validation is *not* an exceptional circumstance
668
+ // lets not throw a RangeError Exception here.
669
+ // It's semantically correct but it's not sensible.
670
+ return false;
671
+ }
672
+ return true;
673
+ };
674
+
675
+ /**
676
+ * Validates the number is within an acceptable range for milliseconds [0-999].
677
+ * @param {Number} The number to check if within range.
678
+ * @return {Boolean} true if within range, otherwise false.
679
+ */
680
+ $D.validateMillisecond = function (value) {
681
+ return validate(value, 0, 999, "millisecond");
682
+ };
683
+
684
+ /**
685
+ * Validates the number is within an acceptable range for seconds [0-59].
686
+ * @param {Number} The number to check if within range.
687
+ * @return {Boolean} true if within range, otherwise false.
688
+ */
689
+ $D.validateSecond = function (value) {
690
+ return validate(value, 0, 59, "second");
691
+ };
692
+
693
+ /**
694
+ * Validates the number is within an acceptable range for minutes [0-59].
695
+ * @param {Number} The number to check if within range.
696
+ * @return {Boolean} true if within range, otherwise false.
697
+ */
698
+ $D.validateMinute = function (value) {
699
+ return validate(value, 0, 59, "minute");
700
+ };
701
+
702
+ /**
703
+ * Validates the number is within an acceptable range for hours [0-23].
704
+ * @param {Number} The number to check if within range.
705
+ * @return {Boolean} true if within range, otherwise false.
706
+ */
707
+ $D.validateHour = function (value) {
708
+ return validate(value, 0, 23, "hour");
709
+ };
710
+
711
+ /**
712
+ * Validates the number is within an acceptable range for the days in a month [0-MaxDaysInMonth].
713
+ * @param {Number} The number to check if within range.
714
+ * @return {Boolean} true if within range, otherwise false.
715
+ */
716
+ $D.validateDay = function (value, year, month) {
717
+ if (year === undefined || year === null || month === undefined || month === null) { return false;}
718
+ return validate(value, 1, $D.getDaysInMonth(year, month), "day");
719
+ };
720
+
721
+ /**
722
+ * Validates the number is within an acceptable range for months [0-11].
723
+ * @param {Number} The number to check if within range.
724
+ * @return {Boolean} true if within range, otherwise false.
725
+ */
726
+ $D.validateWeek = function (value) {
727
+ return validate(value, 0, 53, "week");
728
+ };
729
+
730
+ /**
731
+ * Validates the number is within an acceptable range for months [0-11].
732
+ * @param {Number} The number to check if within range.
733
+ * @return {Boolean} true if within range, otherwise false.
734
+ */
735
+ $D.validateMonth = function (value) {
736
+ return validate(value, 0, 11, "month");
737
+ };
738
+
739
+ /**
740
+ * Validates the number is within an acceptable range for years.
741
+ * @param {Number} The number to check if within range.
742
+ * @return {Boolean} true if within range, otherwise false.
743
+ */
744
+ $D.validateYear = function (value) {
745
+ /**
746
+ * Per ECMAScript spec the range of times supported by Date objects is
747
+ * exactly -100,000,000 days to +100,000,000 days measured relative to
748
+ * midnight at the beginning of 01 January, 1970 UTC.
749
+ * This gives a range of 8,640,000,000,000,000 milliseconds to either
750
+ * side of 01 January, 1970 UTC.
751
+ *
752
+ * Earliest possible date: Tue, 20 Apr 271,822 B.C. 00:00:00 UTC
753
+ * Latest possible date: Sat, 13 Sep 275,760 00:00:00 UTC
754
+ */
755
+ return validate(value, -271822, 275760, "year");
756
+ };
757
+ $D.validateTimezone = function(value) {
758
+ var timezones = {"ACDT":1,"ACST":1,"ACT":1,"ADT":1,"AEDT":1,"AEST":1,"AFT":1,"AKDT":1,"AKST":1,"AMST":1,"AMT":1,"ART":1,"AST":1,"AWDT":1,"AWST":1,"AZOST":1,"AZT":1,"BDT":1,"BIOT":1,"BIT":1,"BOT":1,"BRT":1,"BST":1,"BTT":1,"CAT":1,"CCT":1,"CDT":1,"CEDT":1,"CEST":1,"CET":1,"CHADT":1,"CHAST":1,"CHOT":1,"ChST":1,"CHUT":1,"CIST":1,"CIT":1,"CKT":1,"CLST":1,"CLT":1,"COST":1,"COT":1,"CST":1,"CT":1,"CVT":1,"CWST":1,"CXT":1,"DAVT":1,"DDUT":1,"DFT":1,"EASST":1,"EAST":1,"EAT":1,"ECT":1,"EDT":1,"EEDT":1,"EEST":1,"EET":1,"EGST":1,"EGT":1,"EIT":1,"EST":1,"FET":1,"FJT":1,"FKST":1,"FKT":1,"FNT":1,"GALT":1,"GAMT":1,"GET":1,"GFT":1,"GILT":1,"GIT":1,"GMT":1,"GST":1,"GYT":1,"HADT":1,"HAEC":1,"HAST":1,"HKT":1,"HMT":1,"HOVT":1,"HST":1,"ICT":1,"IDT":1,"IOT":1,"IRDT":1,"IRKT":1,"IRST":1,"IST":1,"JST":1,"KGT":1,"KOST":1,"KRAT":1,"KST":1,"LHST":1,"LINT":1,"MAGT":1,"MART":1,"MAWT":1,"MDT":1,"MET":1,"MEST":1,"MHT":1,"MIST":1,"MIT":1,"MMT":1,"MSK":1,"MST":1,"MUT":1,"MVT":1,"MYT":1,"NCT":1,"NDT":1,"NFT":1,"NPT":1,"NST":1,"NT":1,"NUT":1,"NZDT":1,"NZST":1,"OMST":1,"ORAT":1,"PDT":1,"PET":1,"PETT":1,"PGT":1,"PHOT":1,"PHT":1,"PKT":1,"PMDT":1,"PMST":1,"PONT":1,"PST":1,"PYST":1,"PYT":1,"RET":1,"ROTT":1,"SAKT":1,"SAMT":1,"SAST":1,"SBT":1,"SCT":1,"SGT":1,"SLST":1,"SRT":1,"SST":1,"SYOT":1,"TAHT":1,"THA":1,"TFT":1,"TJT":1,"TKT":1,"TLT":1,"TMT":1,"TOT":1,"TVT":1,"UCT":1,"ULAT":1,"UTC":1,"UYST":1,"UYT":1,"UZT":1,"VET":1,"VLAT":1,"VOLT":1,"VOST":1,"VUT":1,"WAKT":1,"WAST":1,"WAT":1,"WEDT":1,"WEST":1,"WET":1,"WST":1,"YAKT":1,"YEKT":1,"Z":1};
759
+ return (timezones[value] === 1);
760
+ };
761
+ $D.validateTimezoneOffset= function(value) {
762
+ // timezones go from +14hrs to -12hrs, the +X hours are negative offsets.
763
+ return (value > -841 && value < 721);
764
+ };
765
+
766
+ }());
767
+
768
+ (function () {
769
+ var $D = Date,
770
+ $P = $D.prototype,
771
+ p = function (s, l) {
772
+ if (!l) {
773
+ l = 2;
774
+ }
775
+ return ("000" + s).slice(l * -1);
776
+ };
777
+
778
+ var validateConfigObject = function (obj) {
779
+ var result = {}, self = this, prop, testFunc;
780
+ testFunc = function (prop, func, value) {
781
+ if (prop === "day") {
782
+ var month = (obj.month !== undefined) ? obj.month : self.getMonth();
783
+ var year = (obj.year !== undefined) ? obj.year : self.getFullYear();
784
+ return $D[func](value, year, month);
785
+ } else {
786
+ return $D[func](value);
787
+ }
788
+ };
789
+ for (prop in obj) {
790
+ if (hasOwnProperty.call(obj, prop)) {
791
+ var func = "validate" + prop.charAt(0).toUpperCase() + prop.slice(1);
792
+
793
+ if ($D[func] && obj[prop] !== null && testFunc(prop, func, obj[prop])) {
794
+ result[prop] = obj[prop];
795
+ }
796
+ }
797
+ }
798
+ return result;
799
+ };
800
+ /**
801
+ * Resets the time of this Date object to 12:00 AM (00:00), which is the start of the day.
802
+ * @param {Boolean} .clone() this date instance before clearing Time
803
+ * @return {Date} this
804
+ */
805
+ $P.clearTime = function () {
806
+ this.setHours(0);
807
+ this.setMinutes(0);
808
+ this.setSeconds(0);
809
+ this.setMilliseconds(0);
810
+ return this;
811
+ };
812
+
813
+ /**
814
+ * Resets the time of this Date object to the current time ('now').
815
+ * @return {Date} this
816
+ */
817
+ $P.setTimeToNow = function () {
818
+ var n = new Date();
819
+ this.setHours(n.getHours());
820
+ this.setMinutes(n.getMinutes());
821
+ this.setSeconds(n.getSeconds());
822
+ this.setMilliseconds(n.getMilliseconds());
823
+ return this;
824
+ };
825
+ /**
826
+ * Returns a new Date object that is an exact date and time copy of the original instance.
827
+ * @return {Date} A new Date instance
828
+ */
829
+ $P.clone = function () {
830
+ return new Date(this.getTime());
831
+ };
832
+
833
+ /**
834
+ * Compares this instance to a Date object and returns an number indication of their relative values.
835
+ * @param {Date} Date object to compare [Required]
836
+ * @return {Number} -1 = this is lessthan date. 0 = values are equal. 1 = this is greaterthan date.
837
+ */
838
+ $P.compareTo = function (date) {
839
+ return Date.compare(this, date);
840
+ };
841
+
842
+ /**
843
+ * Compares this instance to another Date object and returns true if they are equal.
844
+ * @param {Date} Date object to compare. If no date to compare, new Date() [now] is used.
845
+ * @return {Boolean} true if dates are equal. false if they are not equal.
846
+ */
847
+ $P.equals = function (date) {
848
+ return Date.equals(this, (date !== undefined ? date : new Date()));
849
+ };
850
+
851
+ /**
852
+ * Determines if this instance is between a range of two dates or equal to either the start or end dates.
853
+ * @param {Date} Start of range [Required]
854
+ * @param {Date} End of range [Required]
855
+ * @return {Boolean} true is this is between or equal to the start and end dates, else false
856
+ */
857
+ $P.between = function (start, end) {
858
+ return this.getTime() >= start.getTime() && this.getTime() <= end.getTime();
859
+ };
860
+
861
+ /**
862
+ * Determines if this date occurs after the date to compare to.
863
+ * @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used.
864
+ * @return {Boolean} true if this date instance is greater than the date to compare to (or "now"), otherwise false.
865
+ */
866
+ $P.isAfter = function (date) {
867
+ return this.compareTo(date || new Date()) === 1;
868
+ };
869
+
870
+ /**
871
+ * Determines if this date occurs before the date to compare to.
872
+ * @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used.
873
+ * @return {Boolean} true if this date instance is less than the date to compare to (or "now").
874
+ */
875
+ $P.isBefore = function (date) {
876
+ return (this.compareTo(date || new Date()) === -1);
877
+ };
878
+
879
+ /**
880
+ * Determines if the current Date instance occurs today.
881
+ * @return {Boolean} true if this date instance is 'today', otherwise false.
882
+ */
883
+
884
+ /**
885
+ * Determines if the current Date instance occurs on the same Date as the supplied 'date'.
886
+ * If no 'date' to compare to is provided, the current Date instance is compared to 'today'.
887
+ * @param {date} Date object to compare. If no date to compare, the current Date ("now") is used.
888
+ * @return {Boolean} true if this Date instance occurs on the same Day as the supplied 'date'.
889
+ */
890
+ $P.isToday = $P.isSameDay = function (date) {
891
+ return this.clone().clearTime().equals((date || new Date()).clone().clearTime());
892
+ };
893
+
894
+ /**
895
+ * Adds the specified number of milliseconds to this instance.
896
+ * @param {Number} The number of milliseconds to add. The number can be positive or negative [Required]
897
+ * @return {Date} this
898
+ */
899
+ $P.addMilliseconds = function (value) {
900
+ if (!value) { return this; }
901
+ this.setTime(this.getTime() + value * 1);
902
+ return this;
903
+ };
904
+
905
+ /**
906
+ * Adds the specified number of seconds to this instance.
907
+ * @param {Number} The number of seconds to add. The number can be positive or negative [Required]
908
+ * @return {Date} this
909
+ */
910
+ $P.addSeconds = function (value) {
911
+ if (!value) { return this; }
912
+ return this.addMilliseconds(value * 1000);
913
+ };
914
+
915
+ /**
916
+ * Adds the specified number of seconds to this instance.
917
+ * @param {Number} The number of seconds to add. The number can be positive or negative [Required]
918
+ * @return {Date} this
919
+ */
920
+ $P.addMinutes = function (value) {
921
+ if (!value) { return this; }
922
+ return this.addMilliseconds(value * 60000); // 60*1000
923
+ };
924
+
925
+ /**
926
+ * Adds the specified number of hours to this instance.
927
+ * @param {Number} The number of hours to add. The number can be positive or negative [Required]
928
+ * @return {Date} this
929
+ */
930
+ $P.addHours = function (value) {
931
+ if (!value) { return this; }
932
+ return this.addMilliseconds(value * 3600000); // 60*60*1000
933
+ };
934
+
935
+ /**
936
+ * Adds the specified number of days to this instance.
937
+ * @param {Number} The number of days to add. The number can be positive or negative [Required]
938
+ * @return {Date} this
939
+ */
940
+ $P.addDays = function (value) {
941
+ if (!value) { return this; }
942
+ this.setDate(this.getDate() + value * 1);
943
+ return this;
944
+ };
945
+
946
+ /**
947
+ * Adds the specified number of weekdays (ie - not sat or sun) to this instance.
948
+ * @param {Number} The number of days to add. The number can be positive or negative [Required]
949
+ * @return {Date} this
950
+ */
951
+ $P.addWeekdays = function (value) {
952
+ if (!value) { return this; }
953
+ var day = this.getDay();
954
+ var weeks = (Math.ceil(Math.abs(value)/7));
955
+ if (day === 0 || day === 6) {
956
+ if (value > 0) {
957
+ this.next().monday();
958
+ this.addDays(-1);
959
+ day = this.getDay();
960
+ }
961
+ }
962
+
963
+ if (value < 0) {
964
+ while (value < 0) {
965
+ this.addDays(-1);
966
+ day = this.getDay();
967
+ if (day !== 0 && day !== 6) {
968
+ value++;
969
+ }
970
+ }
971
+ return this;
972
+ } else if (value > 5 || (6-day) <= value) {
973
+ value = value + (weeks * 2);
974
+ }
975
+
976
+ return this.addDays(value);
977
+ };
978
+
979
+ /**
980
+ * Adds the specified number of weeks to this instance.
981
+ * @param {Number} The number of weeks to add. The number can be positive or negative [Required]
982
+ * @return {Date} this
983
+ */
984
+ $P.addWeeks = function (value) {
985
+ if (!value) { return this; }
986
+ return this.addDays(value * 7);
987
+ };
988
+
989
+
990
+ /**
991
+ * Adds the specified number of months to this instance.
992
+ * @param {Number} The number of months to add. The number can be positive or negative [Required]
993
+ * @return {Date} this
994
+ */
995
+ $P.addMonths = function (value) {
996
+ if (!value) { return this; }
997
+ var n = this.getDate();
998
+ this.setDate(1);
999
+ this.setMonth(this.getMonth() + value * 1);
1000
+ this.setDate(Math.min(n, $D.getDaysInMonth(this.getFullYear(), this.getMonth())));
1001
+ return this;
1002
+ };
1003
+
1004
+ $P.addQuarters = function (value) {
1005
+ if (!value) { return this; }
1006
+ // note this will take you to the same point in the quarter as you are now.
1007
+ // i.e. - if you are 15 days into the quarter you'll be 15 days into the resulting one.
1008
+ // bonus: this allows adding fractional quarters
1009
+ return this.addMonths(value * 3);
1010
+ };
1011
+
1012
+ /**
1013
+ * Adds the specified number of years to this instance.
1014
+ * @param {Number} The number of years to add. The number can be positive or negative [Required]
1015
+ * @return {Date} this
1016
+ */
1017
+ $P.addYears = function (value) {
1018
+ if (!value) { return this; }
1019
+ return this.addMonths(value * 12);
1020
+ };
1021
+
1022
+ /**
1023
+ * Adds (or subtracts) to the value of the years, months, weeks, days, hours, minutes, seconds, milliseconds of the date instance using given configuration object. Positive and Negative values allowed.
1024
+ * Example
1025
+ <pre><code>
1026
+ Date.today().add( { days: 1, months: 1 } )
1027
+
1028
+ new Date().add( { years: -1 } )
1029
+ </code></pre>
1030
+ * @param {Object} Configuration object containing attributes (months, days, etc.)
1031
+ * @return {Date} this
1032
+ */
1033
+ $P.add = function (config) {
1034
+ if (typeof config === "number") {
1035
+ this._orient = config;
1036
+ return this;
1037
+ }
1038
+
1039
+ var x = config;
1040
+
1041
+ if (x.day) {
1042
+ // If we should be a different date than today (eg: for 'tomorrow -1d', etc).
1043
+ // Should only effect parsing, not direct usage (eg, Finish and FinishExact)
1044
+ if ((x.day - this.getDate()) !== 0) {
1045
+ this.setDate(x.day);
1046
+ }
1047
+ }
1048
+ if (x.milliseconds) {
1049
+ this.addMilliseconds(x.milliseconds);
1050
+ }
1051
+ if (x.seconds) {
1052
+ this.addSeconds(x.seconds);
1053
+ }
1054
+ if (x.minutes) {
1055
+ this.addMinutes(x.minutes);
1056
+ }
1057
+ if (x.hours) {
1058
+ this.addHours(x.hours);
1059
+ }
1060
+ if (x.weeks) {
1061
+ this.addWeeks(x.weeks);
1062
+ }
1063
+ if (x.months) {
1064
+ this.addMonths(x.months);
1065
+ }
1066
+ if (x.years) {
1067
+ this.addYears(x.years);
1068
+ }
1069
+ if (x.days) {
1070
+ this.addDays(x.days);
1071
+ }
1072
+ return this;
1073
+ };
1074
+
1075
+ /**
1076
+ * Get the week number. Week one (1) is the week which contains the first Thursday of the year. Monday is considered the first day of the week.
1077
+ * The .getWeek() function does NOT convert the date to UTC. The local datetime is used.
1078
+ * Please use .getISOWeek() to get the week of the UTC converted date.
1079
+ * @return {Number} 1 to 53
1080
+ */
1081
+ $P.getWeek = function (utc) {
1082
+ // Create a copy of this date object
1083
+ var self, target = new Date(this.valueOf());
1084
+ if (utc) {
1085
+ target.addMinutes(target.getTimezoneOffset());
1086
+ self = target.clone();
1087
+ } else {
1088
+ self = this;
1089
+ }
1090
+ // ISO week date weeks start on monday
1091
+ // so correct the day number
1092
+ var dayNr = (self.getDay() + 6) % 7;
1093
+ // ISO 8601 states that week 1 is the week
1094
+ // with the first thursday of that year.
1095
+ // Set the target date to the thursday in the target week
1096
+ target.setDate(target.getDate() - dayNr + 3);
1097
+ // Store the millisecond value of the target date
1098
+ var firstThursday = target.valueOf();
1099
+ // Set the target to the first thursday of the year
1100
+ // First set the target to january first
1101
+ target.setMonth(0, 1);
1102
+ // Not a thursday? Correct the date to the next thursday
1103
+ if (target.getDay() !== 4) {
1104
+ target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
1105
+ }
1106
+ // The weeknumber is the number of weeks between the
1107
+ // first thursday of the year and the thursday in the target week
1108
+ return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
1109
+ };
1110
+
1111
+ /**
1112
+ * Get the ISO 8601 week number. Week one ("01") is the week which contains the first Thursday of the year. Monday is considered the first day of the week.
1113
+ * The .getISOWeek() function does convert the date to it's UTC value. Please use .getWeek() to get the week of the local date.
1114
+ * @return {String} "01" to "53"
1115
+ */
1116
+ $P.getISOWeek = function () {
1117
+ return p(this.getWeek(true));
1118
+ };
1119
+
1120
+ /**
1121
+ * Moves the date to Monday of the week set. Week one (1) is the week which contains the first Thursday of the year.
1122
+ * @param {Number} A Number (1 to 53) that represents the week of the year.
1123
+ * @return {Date} this
1124
+ */
1125
+ $P.setWeek = function (n) {
1126
+ if ((n - this.getWeek()) === 0) {
1127
+ if (this.getDay() !== 1) {
1128
+ return this.moveToDayOfWeek(1, (this.getDay() > 1 ? -1 : 1));
1129
+ } else {
1130
+ return this;
1131
+ }
1132
+ } else {
1133
+ return this.moveToDayOfWeek(1, (this.getDay() > 1 ? -1 : 1)).addWeeks(n - this.getWeek());
1134
+ }
1135
+ };
1136
+
1137
+ $P.setQuarter = function (qtr) {
1138
+ var month = Math.abs(((qtr-1) * 3) + 1);
1139
+ return this.setMonth(month, 1);
1140
+ };
1141
+
1142
+ $P.getQuarter = function () {
1143
+ return Date.getQuarter(this);
1144
+ };
1145
+
1146
+ $P.getDaysLeftInQuarter = function () {
1147
+ return Date.getDaysLeftInQuarter(this);
1148
+ };
1149
+
1150
+ /**
1151
+ * Moves the date to the next n'th occurrence of the dayOfWeek starting from the beginning of the month. The number (-1) is a magic number and will return the last occurrence of the dayOfWeek in the month.
1152
+ * @param {Number} The dayOfWeek to move to
1153
+ * @param {Number} The n'th occurrence to move to. Use (-1) to return the last occurrence in the month
1154
+ * @return {Date} this
1155
+ */
1156
+ $P.moveToNthOccurrence = function (dayOfWeek, occurrence) {
1157
+ if (dayOfWeek === "Weekday") {
1158
+ if (occurrence > 0) {
1159
+ this.moveToFirstDayOfMonth();
1160
+ if (this.is().weekday()) {
1161
+ occurrence -= 1;
1162
+ }
1163
+ } else if (occurrence < 0) {
1164
+ this.moveToLastDayOfMonth();
1165
+ if (this.is().weekday()) {
1166
+ occurrence += 1;
1167
+ }
1168
+ } else {
1169
+ return this;
1170
+ }
1171
+ return this.addWeekdays(occurrence);
1172
+ }
1173
+ var shift = 0;
1174
+ if (occurrence > 0) {
1175
+ shift = occurrence - 1;
1176
+ }
1177
+ else if (occurrence === -1) {
1178
+ this.moveToLastDayOfMonth();
1179
+ if (this.getDay() !== dayOfWeek) {
1180
+ this.moveToDayOfWeek(dayOfWeek, -1);
1181
+ }
1182
+ return this;
1183
+ }
1184
+ return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek, +1).addWeeks(shift);
1185
+ };
1186
+
1187
+
1188
+ var moveToN = function (getFunc, addFunc, nVal) {
1189
+ return function (value, orient) {
1190
+ var diff = (value - this[getFunc]() + nVal * (orient || +1)) % nVal;
1191
+ return this[addFunc]((diff === 0) ? diff += nVal * (orient || +1) : diff);
1192
+ };
1193
+ };
1194
+ /**
1195
+ * Move to the next or last dayOfWeek based on the orient value.
1196
+ * @param {Number} The dayOfWeek to move to
1197
+ * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional]
1198
+ * @return {Date} this
1199
+ */
1200
+ $P.moveToDayOfWeek = moveToN("getDay", "addDays", 7);
1201
+ /**
1202
+ * Move to the next or last month based on the orient value.
1203
+ * @param {Number} The month to move to. 0 = January, 11 = December
1204
+ * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional]
1205
+ * @return {Date} this
1206
+ */
1207
+ $P.moveToMonth = moveToN("getMonth", "addMonths", 12);
1208
+ /**
1209
+ * Get the Ordinate of the current day ("th", "st", "rd").
1210
+ * @return {String}
1211
+ */
1212
+ $P.getOrdinate = function () {
1213
+ var num = this.getDate();
1214
+ return ord(num);
1215
+ };
1216
+ /**
1217
+ * Get the Ordinal day (numeric day number) of the year, adjusted for leap year.
1218
+ * @return {Number} 1 through 365 (366 in leap years)
1219
+ */
1220
+ $P.getOrdinalNumber = function () {
1221
+ return Math.ceil((this.clone().clearTime() - new Date(this.getFullYear(), 0, 1)) / 86400000) + 1;
1222
+ };
1223
+
1224
+ /**
1225
+ * Get the time zone abbreviation of the current date.
1226
+ * @return {String} The abbreviated time zone name (e.g. "EST")
1227
+ */
1228
+ $P.getTimezone = function () {
1229
+ return $D.getTimezoneAbbreviation(this.getUTCOffset(), this.isDaylightSavingTime());
1230
+ };
1231
+
1232
+ $P.setTimezoneOffset = function (offset) {
1233
+ var here = this.getTimezoneOffset(), there = Number(offset) * -6 / 10;
1234
+ return (there || there === 0) ? this.addMinutes(there - here) : this;
1235
+ };
1236
+
1237
+ $P.setTimezone = function (offset) {
1238
+ return this.setTimezoneOffset($D.getTimezoneOffset(offset));
1239
+ };
1240
+
1241
+ /**
1242
+ * Indicates whether Daylight Saving Time is observed in the current time zone.
1243
+ * @return {Boolean} true|false
1244
+ */
1245
+ $P.hasDaylightSavingTime = function () {
1246
+ return (Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== Date.today().set({month: 6, day: 1}).getTimezoneOffset());
1247
+ };
1248
+
1249
+ /**
1250
+ * Indicates whether this Date instance is within the Daylight Saving Time range for the current time zone.
1251
+ * @return {Boolean} true|false
1252
+ */
1253
+ $P.isDaylightSavingTime = function () {
1254
+ return Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== this.getTimezoneOffset();
1255
+ };
1256
+
1257
+ /**
1258
+ * Get the offset from UTC of the current date.
1259
+ * @return {String} The 4-character offset string prefixed with + or - (e.g. "-0500")
1260
+ */
1261
+ $P.getUTCOffset = function (offset) {
1262
+ var n = (offset || this.getTimezoneOffset()) * -10 / 6, r;
1263
+ if (n < 0) {
1264
+ r = (n - 10000).toString();
1265
+ return r.charAt(0) + r.substr(2);
1266
+ } else {
1267
+ r = (n + 10000).toString();
1268
+ return "+" + r.substr(1);
1269
+ }
1270
+ };
1271
+
1272
+ /**
1273
+ * Returns the number of milliseconds between this date and date.
1274
+ * @param {Date} Defaults to now
1275
+ * @return {Number} The diff in milliseconds
1276
+ */
1277
+ $P.getElapsed = function (date) {
1278
+ return (date || new Date()) - this;
1279
+ };
1280
+
1281
+ /**
1282
+ * Set the value of year, month, day, hour, minute, second, millisecond of date instance using given configuration object.
1283
+ * Example
1284
+ <pre><code>
1285
+ Date.today().set( { day: 20, month: 1 } )
1286
+
1287
+ new Date().set( { millisecond: 0 } )
1288
+ </code></pre>
1289
+ *
1290
+ * @param {Object} Configuration object containing attributes (month, day, etc.)
1291
+ * @return {Date} this
1292
+ */
1293
+ $P.set = function (config) {
1294
+ config = validateConfigObject.call(this, config);
1295
+ var key;
1296
+ for (key in config) {
1297
+ if (hasOwnProperty.call(config, key)) {
1298
+ var name = key.charAt(0).toUpperCase() + key.slice(1);
1299
+ var addFunc, getFunc;
1300
+ if (key !== "week" && key !== "month" && key !== "timezone" && key !== "timezoneOffset") {
1301
+ name += "s";
1302
+ }
1303
+ addFunc = "add" + name;
1304
+ getFunc = "get" + name;
1305
+ if (key === "month") {
1306
+ addFunc = addFunc + "s";
1307
+ } else if (key === "year"){
1308
+ getFunc = "getFullYear";
1309
+ }
1310
+ if (key !== "day" && key !== "timezone" && key !== "timezoneOffset" && key !== "week" && key !== "hour") {
1311
+ this[addFunc](config[key] - this[getFunc]());
1312
+ } else if ( key === "timezone"|| key === "timezoneOffset" || key === "week" || key === "hour") {
1313
+ this["set"+name](config[key]);
1314
+ }
1315
+ }
1316
+ }
1317
+ // day has to go last because you can't validate the day without first knowing the month
1318
+ if (config.day) {
1319
+ this.addDays(config.day - this.getDate());
1320
+ }
1321
+
1322
+ return this;
1323
+ };
1324
+
1325
+ /**
1326
+ * Moves the date to the first day of the month.
1327
+ * @return {Date} this
1328
+ */
1329
+ $P.moveToFirstDayOfMonth = function () {
1330
+ return this.set({ day: 1 });
1331
+ };
1332
+
1333
+ /**
1334
+ * Moves the date to the last day of the month.
1335
+ * @return {Date} this
1336
+ */
1337
+ $P.moveToLastDayOfMonth = function () {
1338
+ return this.set({ day: $D.getDaysInMonth(this.getFullYear(), this.getMonth())});
1339
+ };
1340
+
1341
+
1342
+ /**
1343
+ * Converts the value of the current Date object to its equivalent string representation.
1344
+ * Format Specifiers
1345
+ * CUSTOM DATE AND TIME FORMAT STRINGS
1346
+ * Format Description Example
1347
+ * ------ --------------------------------------------------------------------------- -----------------------
1348
+ * s The seconds of the minute between 0-59. "0" to "59"
1349
+ * ss The seconds of the minute with leading zero if required. "00" to "59"
1350
+ *
1351
+ * m The minute of the hour between 0-59. "0" or "59"
1352
+ * mm The minute of the hour with leading zero if required. "00" or "59"
1353
+ *
1354
+ * h The hour of the day between 1-12. "1" to "12"
1355
+ * hh The hour of the day with leading zero if required. "01" to "12"
1356
+ *
1357
+ * H The hour of the day between 0-23. "0" to "23"
1358
+ * HH The hour of the day with leading zero if required. "00" to "23"
1359
+ *
1360
+ * d The day of the month between 1 and 31. "1" to "31"
1361
+ * dd The day of the month with leading zero if required. "01" to "31"
1362
+ * ddd Abbreviated day name. Date.CultureInfo.abbreviatedDayNames. "Mon" to "Sun"
1363
+ * dddd The full day name. Date.CultureInfo.dayNames. "Monday" to "Sunday"
1364
+ *
1365
+ * M The month of the year between 1-12. "1" to "12"
1366
+ * MM The month of the year with leading zero if required. "01" to "12"
1367
+ * MMM Abbreviated month name. Date.CultureInfo.abbreviatedMonthNames. "Jan" to "Dec"
1368
+ * MMMM The full month name. Date.CultureInfo.monthNames. "January" to "December"
1369
+ *
1370
+ * yy The year as a two-digit number. "99" or "08"
1371
+ * yyyy The full four digit year. "1999" or "2008"
1372
+ *
1373
+ * t Displays the first character of the A.M./P.M. designator. "A" or "P"
1374
+ * Date.CultureInfo.amDesignator or Date.CultureInfo.pmDesignator
1375
+ * tt Displays the A.M./P.M. designator. "AM" or "PM"
1376
+ * Date.CultureInfo.amDesignator or Date.CultureInfo.pmDesignator
1377
+ *
1378
+ * S The ordinal suffix ("st, "nd", "rd" or "th") of the current day. "st, "nd", "rd" or "th"
1379
+ *
1380
+ * STANDARD DATE AND TIME FORMAT STRINGS
1381
+ * Format Description Example
1382
+ *------ --------------------------------------------------------------------------- -----------------------
1383
+ * d The CultureInfo shortDate Format Pattern "M/d/yyyy"
1384
+ * D The CultureInfo longDate Format Pattern "dddd, MMMM dd, yyyy"
1385
+ * F The CultureInfo fullDateTime Format Pattern "dddd, MMMM dd, yyyy h:mm:ss tt"
1386
+ * m The CultureInfo monthDay Format Pattern "MMMM dd"
1387
+ * r The CultureInfo rfc1123 Format Pattern "ddd, dd MMM yyyy HH:mm:ss GMT"
1388
+ * s The CultureInfo sortableDateTime Format Pattern "yyyy-MM-ddTHH:mm:ss"
1389
+ * t The CultureInfo shortTime Format Pattern "h:mm tt"
1390
+ * T The CultureInfo longTime Format Pattern "h:mm:ss tt"
1391
+ * u The CultureInfo universalSortableDateTime Format Pattern "yyyy-MM-dd HH:mm:ssZ"
1392
+ * y The CultureInfo yearMonth Format Pattern "MMMM, yyyy"
1393
+ *
1394
+ * @param {String} A format string consisting of one or more format spcifiers [Optional].
1395
+ * @return {String} A string representation of the current Date object.
1396
+ */
1397
+
1398
+ var ord = function (n) {
1399
+ switch (n * 1) {
1400
+ case 1:
1401
+ case 21:
1402
+ case 31:
1403
+ return "st";
1404
+ case 2:
1405
+ case 22:
1406
+ return "nd";
1407
+ case 3:
1408
+ case 23:
1409
+ return "rd";
1410
+ default:
1411
+ return "th";
1412
+ }
1413
+ };
1414
+ var parseStandardFormats = function (format) {
1415
+ var y, c = Date.CultureInfo.formatPatterns;
1416
+ switch (format) {
1417
+ case "d":
1418
+ return this.toString(c.shortDate);
1419
+ case "D":
1420
+ return this.toString(c.longDate);
1421
+ case "F":
1422
+ return this.toString(c.fullDateTime);
1423
+ case "m":
1424
+ return this.toString(c.monthDay);
1425
+ case "r":
1426
+ case "R":
1427
+ y = this.clone().addMinutes(this.getTimezoneOffset());
1428
+ return y.toString(c.rfc1123) + " GMT";
1429
+ case "s":
1430
+ return this.toString(c.sortableDateTime);
1431
+ case "t":
1432
+ return this.toString(c.shortTime);
1433
+ case "T":
1434
+ return this.toString(c.longTime);
1435
+ case "u":
1436
+ y = this.clone().addMinutes(this.getTimezoneOffset());
1437
+ return y.toString(c.universalSortableDateTime);
1438
+ case "y":
1439
+ return this.toString(c.yearMonth);
1440
+ default:
1441
+ return false;
1442
+ }
1443
+ };
1444
+ var parseFormatStringsClosure = function (context) {
1445
+ return function (m) {
1446
+ if (m.charAt(0) === "\\") {
1447
+ return m.replace("\\", "");
1448
+ }
1449
+ switch (m) {
1450
+ case "hh":
1451
+ return p(context.getHours() < 13 ? (context.getHours() === 0 ? 12 : context.getHours()) : (context.getHours() - 12));
1452
+ case "h":
1453
+ return context.getHours() < 13 ? (context.getHours() === 0 ? 12 : context.getHours()) : (context.getHours() - 12);
1454
+ case "HH":
1455
+ return p(context.getHours());
1456
+ case "H":
1457
+ return context.getHours();
1458
+ case "mm":
1459
+ return p(context.getMinutes());
1460
+ case "m":
1461
+ return context.getMinutes();
1462
+ case "ss":
1463
+ return p(context.getSeconds());
1464
+ case "s":
1465
+ return context.getSeconds();
1466
+ case "yyyy":
1467
+ return p(context.getFullYear(), 4);
1468
+ case "yy":
1469
+ return p(context.getFullYear());
1470
+ case "y":
1471
+ return context.getFullYear();
1472
+ case "E":
1473
+ case "dddd":
1474
+ return Date.CultureInfo.dayNames[context.getDay()];
1475
+ case "ddd":
1476
+ return Date.CultureInfo.abbreviatedDayNames[context.getDay()];
1477
+ case "dd":
1478
+ return p(context.getDate());
1479
+ case "d":
1480
+ return context.getDate();
1481
+ case "MMMM":
1482
+ return Date.CultureInfo.monthNames[context.getMonth()];
1483
+ case "MMM":
1484
+ return Date.CultureInfo.abbreviatedMonthNames[context.getMonth()];
1485
+ case "MM":
1486
+ return p((context.getMonth() + 1));
1487
+ case "M":
1488
+ return context.getMonth() + 1;
1489
+ case "t":
1490
+ return context.getHours() < 12 ? Date.CultureInfo.amDesignator.substring(0, 1) : Date.CultureInfo.pmDesignator.substring(0, 1);
1491
+ case "tt":
1492
+ return context.getHours() < 12 ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
1493
+ case "S":
1494
+ return ord(context.getDate());
1495
+ case "W":
1496
+ return context.getWeek();
1497
+ case "WW":
1498
+ return context.getISOWeek();
1499
+ case "Q":
1500
+ return "Q" + context.getQuarter();
1501
+ case "q":
1502
+ return String(context.getQuarter());
1503
+ case "z":
1504
+ return context.getTimezone();
1505
+ case "Z":
1506
+ case "X":
1507
+ return Date.getTimezoneOffset(context.getTimezone());
1508
+ case "ZZ": // Timezone offset in seconds
1509
+ return context.getTimezoneOffset() * -60;
1510
+ case "u":
1511
+ return context.getDay();
1512
+ case "L":
1513
+ return ($D.isLeapYear(context.getFullYear())) ? 1 : 0;
1514
+ case "B":
1515
+ // Swatch Internet Time (.beats)
1516
+ return "@"+((context.getUTCSeconds() + (context.getUTCMinutes()*60) + ((context.getUTCHours()+1)*3600))/86.4);
1517
+ default:
1518
+ return m;
1519
+ }
1520
+ };
1521
+ };
1522
+ $P.toString = function (format, ignoreStandards) {
1523
+
1524
+ // Standard Date and Time Format Strings. Formats pulled from CultureInfo file and
1525
+ // may vary by culture.
1526
+ if (!ignoreStandards && format && format.length === 1) {
1527
+ output = parseStandardFormats.call(this, format);
1528
+ if (output) {
1529
+ return output;
1530
+ }
1531
+ }
1532
+ var parseFormatStrings = parseFormatStringsClosure(this);
1533
+ return format ? format.replace(/((\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S|q|Q|WW?W?W?)(?![^\[]*\]))/g, parseFormatStrings).replace(/\[|\]/g, "") : this._toString();
1534
+ };
1535
+
1536
+ }());
1537
+ /*************************************************************
1538
+ * SugarPak - Domain Specific Language - Syntactical Sugar *
1539
+ *************************************************************/
1540
+
1541
+ (function () {
1542
+ var $D = Date, $P = $D.prototype, $N = Number.prototype;
1543
+
1544
+ // private
1545
+ $P._orient = +1;
1546
+
1547
+ // private
1548
+ $P._nth = null;
1549
+
1550
+ // private
1551
+ $P._is = false;
1552
+
1553
+ // private
1554
+ $P._same = false;
1555
+
1556
+ // private
1557
+ $P._isSecond = false;
1558
+
1559
+ // private
1560
+ $N._dateElement = "days";
1561
+
1562
+ /**
1563
+ * Moves the date to the next instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
1564
+ * Example
1565
+ <pre><code>
1566
+ Date.today().next().friday();
1567
+ Date.today().next().fri();
1568
+ Date.today().next().march();
1569
+ Date.today().next().mar();
1570
+ Date.today().next().week();
1571
+ </code></pre>
1572
+ *
1573
+ * @return {Date} date
1574
+ */
1575
+ $P.next = function () {
1576
+ this._move = true;
1577
+ this._orient = +1;
1578
+ return this;
1579
+ };
1580
+
1581
+ /**
1582
+ * Creates a new Date (Date.today()) and moves the date to the next instance of the date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
1583
+ * Example
1584
+ <pre><code>
1585
+ Date.next().friday();
1586
+ Date.next().fri();
1587
+ Date.next().march();
1588
+ Date.next().mar();
1589
+ Date.next().week();
1590
+ </code></pre>
1591
+ *
1592
+ * @return {Date} date
1593
+ */
1594
+ $D.next = function () {
1595
+ return $D.today().next();
1596
+ };
1597
+
1598
+ /**
1599
+ * Moves the date to the previous instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
1600
+ * Example
1601
+ <pre><code>
1602
+ Date.today().last().friday();
1603
+ Date.today().last().fri();
1604
+ Date.today().last().march();
1605
+ Date.today().last().mar();
1606
+ Date.today().last().week();
1607
+ </code></pre>
1608
+ *
1609
+ * @return {Date} date
1610
+ */
1611
+ $P.last = $P.prev = $P.previous = function () {
1612
+ this._move = true;
1613
+ this._orient = -1;
1614
+ return this;
1615
+ };
1616
+
1617
+ /**
1618
+ * Creates a new Date (Date.today()) and moves the date to the previous instance of the date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
1619
+ * Example
1620
+ <pre><code>
1621
+ Date.last().friday();
1622
+ Date.last().fri();
1623
+ Date.previous().march();
1624
+ Date.prev().mar();
1625
+ Date.last().week();
1626
+ </code></pre>
1627
+ *
1628
+ * @return {Date} date
1629
+ */
1630
+ $D.last = $D.prev = $D.previous = function () {
1631
+ return $D.today().last();
1632
+ };
1633
+
1634
+ /**
1635
+ * Performs a equality check when followed by either a month name, day name or .weekday() function.
1636
+ * Example
1637
+ <pre><code>
1638
+ Date.today().is().friday(); // true|false
1639
+ Date.today().is().fri();
1640
+ Date.today().is().march();
1641
+ Date.today().is().mar();
1642
+ </code></pre>
1643
+ *
1644
+ * @return {Boolean} true|false
1645
+ */
1646
+ $P.is = function () {
1647
+ this._is = true;
1648
+ return this;
1649
+ };
1650
+
1651
+ /**
1652
+ * Determines if two date objects occur on/in exactly the same instance of the subsequent date part function.
1653
+ * The function .same() must be followed by a date part function (example: .day(), .month(), .year(), etc).
1654
+ *
1655
+ * An optional Date can be passed in the date part function. If now date is passed as a parameter, 'Now' is used.
1656
+ *
1657
+ * The following example demonstrates how to determine if two dates fall on the exact same day.
1658
+ *
1659
+ * Example
1660
+ <pre><code>
1661
+ var d1 = Date.today(); // today at 00:00
1662
+ var d2 = new Date(); // exactly now.
1663
+
1664
+ // Do they occur on the same day?
1665
+ d1.same().day(d2); // true
1666
+
1667
+ // Do they occur on the same hour?
1668
+ d1.same().hour(d2); // false, unless d2 hour is '00' (midnight).
1669
+
1670
+ // What if it's the same day, but one year apart?
1671
+ var nextYear = Date.today().add(1).year();
1672
+
1673
+ d1.same().day(nextYear); // false, because the dates must occur on the exact same day.
1674
+ </code></pre>
1675
+ *
1676
+ * Scenario: Determine if a given date occurs during some week period 2 months from now.
1677
+ *
1678
+ * Example
1679
+ <pre><code>
1680
+ var future = Date.today().add(2).months();
1681
+ return someDate.same().week(future); // true|false;
1682
+ </code></pre>
1683
+ *
1684
+ * @return {Boolean} true|false
1685
+ */
1686
+ $P.same = function () {
1687
+ this._same = true;
1688
+ this._isSecond = false;
1689
+ return this;
1690
+ };
1691
+
1692
+ /**
1693
+ * Determines if the current date/time occurs during Today. Must be preceded by the .is() function.
1694
+ * Example
1695
+ <pre><code>
1696
+ someDate.is().today(); // true|false
1697
+ new Date().is().today(); // true
1698
+ Date.today().is().today();// true
1699
+ Date.today().add(-1).day().is().today(); // false
1700
+ </code></pre>
1701
+ *
1702
+ * @return {Boolean} true|false
1703
+ */
1704
+ $P.today = function () {
1705
+ return this.same().day();
1706
+ };
1707
+
1708
+ /**
1709
+ * Determines if the current date is a weekday. This function must be preceded by the .is() function.
1710
+ * Example
1711
+ <pre><code>
1712
+ Date.today().is().weekday(); // true|false
1713
+ </code></pre>
1714
+ *
1715
+ * @return {Boolean} true|false
1716
+ */
1717
+ $P.weekday = function () {
1718
+ if (this._nth) {
1719
+ return df("Weekday").call(this);
1720
+ }
1721
+ if (this._move) {
1722
+ return this.addWeekdays(this._orient);
1723
+ }
1724
+ if (this._is) {
1725
+ this._is = false;
1726
+ return (!this.is().sat() && !this.is().sun());
1727
+ }
1728
+ return false;
1729
+ };
1730
+ /**
1731
+ * Determines if the current date is on the weekend. This function must be preceded by the .is() function.
1732
+ * Example
1733
+ <pre><code>
1734
+ Date.today().is().weekend(); // true|false
1735
+ </code></pre>
1736
+ *
1737
+ * @return {Boolean} true|false
1738
+ */
1739
+ $P.weekend = function () {
1740
+ if (this._is) {
1741
+ this._is = false;
1742
+ return (this.is().sat() || this.is().sun());
1743
+ }
1744
+ return false;
1745
+ };
1746
+
1747
+ /**
1748
+ * Sets the Time of the current Date instance. A string "6:15 pm" or config object {hour:18, minute:15} are accepted.
1749
+ * Example
1750
+ <pre><code>
1751
+ // Set time to 6:15pm with a String
1752
+ Date.today().at("6:15pm");
1753
+
1754
+ // Set time to 6:15pm with a config object
1755
+ Date.today().at({hour:18, minute:15});
1756
+ </code></pre>
1757
+ *
1758
+ * @return {Date} date
1759
+ */
1760
+ $P.at = function (time) {
1761
+ return (typeof time === "string") ? $D.parse(this.toString("d") + " " + time) : this.set(time);
1762
+ };
1763
+
1764
+ /**
1765
+ * Creates a new Date() and adds this (Number) to the date based on the preceding date element function (eg. second|minute|hour|day|month|year).
1766
+ * Example
1767
+ <pre><code>
1768
+ // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript.
1769
+ (3).days().fromNow();
1770
+ (6).months().fromNow();
1771
+
1772
+ // Declared Number variables do not require parentheses.
1773
+ var n = 6;
1774
+ n.months().fromNow();
1775
+ </code></pre>
1776
+ *
1777
+ * @return {Date} A new Date instance
1778
+ */
1779
+ $N.fromNow = $N.after = function (date) {
1780
+ var c = {};
1781
+ c[this._dateElement] = this;
1782
+ return ((!date) ? new Date() : date.clone()).add(c);
1783
+ };
1784
+
1785
+ /**
1786
+ * Creates a new Date() and subtract this (Number) from the date based on the preceding date element function (eg. second|minute|hour|day|month|year).
1787
+ * Example
1788
+ <pre><code>
1789
+ // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript.
1790
+ (3).days().ago();
1791
+ (6).months().ago();
1792
+
1793
+ // Declared Number variables do not require parentheses.
1794
+ var n = 6;
1795
+ n.months().ago();
1796
+ </code></pre>
1797
+ *
1798
+ * @return {Date} A new Date instance
1799
+ */
1800
+ $N.ago = $N.before = function (date) {
1801
+ var c = {},
1802
+ s = (this._dateElement[this._dateElement.length-1] !== "s") ? this._dateElement + "s" : this._dateElement;
1803
+ c[s] = this * -1;
1804
+ return ((!date) ? new Date() : date.clone()).add(c);
1805
+ };
1806
+
1807
+ // Do NOT modify the following string tokens. These tokens are used to build dynamic functions.
1808
+ // All culture-specific strings can be found in the CultureInfo files.
1809
+ var dx = ("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),
1810
+ mx = ("january february march april may june july august september october november december").split(/\s/),
1811
+ px = ("Millisecond Second Minute Hour Day Week Month Year Quarter Weekday").split(/\s/),
1812
+ pxf = ("Milliseconds Seconds Minutes Hours Date Week Month FullYear Quarter").split(/\s/),
1813
+ nth = ("final first second third fourth fifth").split(/\s/),
1814
+ de;
1815
+
1816
+ /**
1817
+ * Returns an object literal of all the date parts.
1818
+ * Example
1819
+ <pre><code>
1820
+ var o = new Date().toObject();
1821
+
1822
+ // { year: 2008, month: 4, week: 20, day: 13, hour: 18, minute: 9, second: 32, millisecond: 812 }
1823
+
1824
+ // The object properties can be referenced directly from the object.
1825
+
1826
+ alert(o.day); // alerts "13"
1827
+ alert(o.year); // alerts "2008"
1828
+ </code></pre>
1829
+ *
1830
+ * @return {Date} An object literal representing the original date object.
1831
+ */
1832
+ $P.toObject = function () {
1833
+ var o = {};
1834
+ for (var i = 0; i < px.length; i++) {
1835
+ if (this["get" + pxf[i]]) {
1836
+ o[px[i].toLowerCase()] = this["get" + pxf[i]]();
1837
+ }
1838
+ }
1839
+ return o;
1840
+ };
1841
+
1842
+ /**
1843
+ * Returns a date created from an object literal. Ignores the .week property if set in the config.
1844
+ * Example
1845
+ <pre><code>
1846
+ var o = new Date().toObject();
1847
+
1848
+ return Date.fromObject(o); // will return the same date.
1849
+
1850
+ var o2 = {month: 1, day: 20, hour: 18}; // birthday party!
1851
+ Date.fromObject(o2);
1852
+ </code></pre>
1853
+ *
1854
+ * @return {Date} An object literal representing the original date object.
1855
+ */
1856
+ $D.fromObject = function(config) {
1857
+ config.week = null;
1858
+ return Date.today().set(config);
1859
+ };
1860
+
1861
+ // Create day name functions and abbreviated day name functions (eg. monday(), friday(), fri()).
1862
+
1863
+ var df = function (n) {
1864
+ return function () {
1865
+ if (this._is) {
1866
+ this._is = false;
1867
+ return this.getDay() === n;
1868
+ }
1869
+ if (this._move) { this._move = null; }
1870
+ if (this._nth !== null) {
1871
+ // If the .second() function was called earlier, remove the _orient
1872
+ // from the date, and then continue.
1873
+ // This is required because 'second' can be used in two different context.
1874
+ //
1875
+ // Example
1876
+ //
1877
+ // Date.today().add(1).second();
1878
+ // Date.march().second().monday();
1879
+ //
1880
+ // Things get crazy with the following...
1881
+ // Date.march().add(1).second().second().monday(); // but it works!!
1882
+ //
1883
+ if (this._isSecond) {
1884
+ this.addSeconds(this._orient * -1);
1885
+ }
1886
+ // make sure we reset _isSecond
1887
+ this._isSecond = false;
1888
+
1889
+ var ntemp = this._nth;
1890
+ this._nth = null;
1891
+ var temp = this.clone().moveToLastDayOfMonth();
1892
+ this.moveToNthOccurrence(n, ntemp);
1893
+ if (this > temp) {
1894
+ throw new RangeError($D.getDayName(n) + " does not occur " + ntemp + " times in the month of " + $D.getMonthName(temp.getMonth()) + " " + temp.getFullYear() + ".");
1895
+ }
1896
+ return this;
1897
+ }
1898
+ return this.moveToDayOfWeek(n, this._orient);
1899
+ };
1900
+ };
1901
+
1902
+ var sdf = function (n) {
1903
+ return function () {
1904
+ var t = $D.today(), shift = n - t.getDay();
1905
+ if (n === 0 && Date.CultureInfo.firstDayOfWeek === 1 && t.getDay() !== 0) {
1906
+ shift = shift + 7;
1907
+ }
1908
+ return t.addDays(shift);
1909
+ };
1910
+ };
1911
+
1912
+
1913
+
1914
+ // Create month name functions and abbreviated month name functions (eg. january(), march(), mar()).
1915
+ var month_instance_functions = function (n) {
1916
+ return function () {
1917
+ if (this._is) {
1918
+ this._is = false;
1919
+ return this.getMonth() === n;
1920
+ }
1921
+ return this.moveToMonth(n, this._orient);
1922
+ };
1923
+ };
1924
+
1925
+ var month_static_functions = function (n) {
1926
+ return function () {
1927
+ return $D.today().set({ month: n, day: 1 });
1928
+ };
1929
+ };
1930
+
1931
+ var processTerms = function (names, staticFunc, instanceFunc) {
1932
+ for (var i = 0; i < names.length; i++) {
1933
+ // Create constant static Name variables.
1934
+ $D[names[i].toUpperCase()] = $D[names[i].toUpperCase().substring(0, 3)] = i;
1935
+ // Create Name functions.
1936
+ $D[names[i]] = $D[names[i].substring(0, 3)] = staticFunc(i);
1937
+ // Create Name instance functions.
1938
+ $P[names[i]] = $P[names[i].substring(0, 3)] = instanceFunc(i);
1939
+ }
1940
+
1941
+ };
1942
+
1943
+ processTerms(dx, sdf, df);
1944
+ processTerms(mx, month_static_functions, month_instance_functions);
1945
+
1946
+ // Create date element functions and plural date element functions used with Date (eg. day(), days(), months()).
1947
+ var ef = function (j) {
1948
+ return function () {
1949
+ // if the .second() function was called earlier, the _orient
1950
+ // has alread been added. Just return this and reset _isSecond.
1951
+ if (this._isSecond) {
1952
+ this._isSecond = false;
1953
+ return this;
1954
+ }
1955
+
1956
+ if (this._same) {
1957
+ this._same = this._is = false;
1958
+ var o1 = this.toObject(),
1959
+ o2 = (arguments[0] || new Date()).toObject(),
1960
+ v = "",
1961
+ k = j.toLowerCase();
1962
+
1963
+ // the substr trick with -1 doesn't work in IE8 or less
1964
+ k = (k[k.length-1] === "s") ? k.substring(0,k.length-1) : k;
1965
+
1966
+ for (var m = (px.length - 1); m > -1; m--) {
1967
+ v = px[m].toLowerCase();
1968
+ if (o1[v] !== o2[v]) {
1969
+ return false;
1970
+ }
1971
+ if (k === v) {
1972
+ break;
1973
+ }
1974
+ }
1975
+ return true;
1976
+ }
1977
+
1978
+ if (j.substring(j.length - 1) !== "s") {
1979
+ j += "s";
1980
+ }
1981
+ if (this._move) { this._move = null; }
1982
+ return this["add" + j](this._orient);
1983
+ };
1984
+ };
1985
+
1986
+
1987
+ var nf = function (n) {
1988
+ return function () {
1989
+ this._dateElement = n;
1990
+ return this;
1991
+ };
1992
+ };
1993
+
1994
+ for (var k = 0; k < px.length; k++) {
1995
+ de = px[k].toLowerCase();
1996
+ if(de !== "weekday") {
1997
+ // Create date element functions and plural date element functions used with Date (eg. day(), days(), months()).
1998
+ $P[de] = $P[de + "s"] = ef(px[k]);
1999
+
2000
+ // Create date element functions and plural date element functions used with Number (eg. day(), days(), months()).
2001
+ $N[de] = $N[de + "s"] = nf(de + "s");
2002
+ }
2003
+ }
2004
+
2005
+ $P._ss = ef("Second");
2006
+
2007
+ var nthfn = function (n) {
2008
+ return function (dayOfWeek) {
2009
+ if (this._same) {
2010
+ return this._ss(arguments[0]);
2011
+ }
2012
+ if (dayOfWeek || dayOfWeek === 0) {
2013
+ return this.moveToNthOccurrence(dayOfWeek, n);
2014
+ }
2015
+ this._nth = n;
2016
+
2017
+ // if the operator is 'second' add the _orient, then deal with it later...
2018
+ if (n === 2 && (dayOfWeek === undefined || dayOfWeek === null)) {
2019
+ this._isSecond = true;
2020
+ return this.addSeconds(this._orient);
2021
+ }
2022
+ return this;
2023
+ };
2024
+ };
2025
+
2026
+ for (var l = 0; l < nth.length; l++) {
2027
+ $P[nth[l]] = (l === 0) ? nthfn(-1) : nthfn(l);
2028
+ }
2029
+ }());
2030
+
2031
+ (function () {
2032
+ "use strict";
2033
+ Date.Parsing = {
2034
+ Exception: function (s) {
2035
+ this.message = "Parse error at '" + s.substring(0, 10) + " ...'";
2036
+ }
2037
+ };
2038
+ var $P = Date.Parsing;
2039
+ var dayOffsets = {
2040
+ standard: [0,31,59,90,120,151,181,212,243,273,304,334],
2041
+ leap: [0,31,60,91,121,152,182,213,244,274,305,335]
2042
+ };
2043
+
2044
+ $P.isLeapYear = function(year) {
2045
+ return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
2046
+ };
2047
+
2048
+ var utils = {
2049
+ multiReplace : function (str, hash ) {
2050
+ var key;
2051
+ for (key in hash) {
2052
+ if (Object.prototype.hasOwnProperty.call(hash, key)) {
2053
+ var regex;
2054
+ if (typeof hash[key] === "function") {
2055
+
2056
+ } else {
2057
+ regex = (hash[key] instanceof RegExp) ? hash[key] : new RegExp(hash[key], "g");
2058
+ }
2059
+ str = str.replace(regex, key);
2060
+ }
2061
+ }
2062
+ return str;
2063
+ },
2064
+ getDayOfYearFromWeek : function (obj) {
2065
+ var d, jan4, offset;
2066
+ obj.weekDay = (!obj.weekDay && obj.weekDay !== 0) ? 1 : obj.weekDay;
2067
+ d = new Date(obj.year, 0, 4);
2068
+ jan4 = d.getDay() === 0 ? 7 : d.getDay(); // JS is 0 indexed on Sunday.
2069
+ offset = jan4+3;
2070
+ obj.dayOfYear = ((obj.week * 7) + (obj.weekDay === 0 ? 7 : obj.weekDay))-offset;
2071
+ return obj;
2072
+ },
2073
+ getDayOfYear : function (obj, dayOffset) {
2074
+ if (!obj.dayOfYear) {
2075
+ obj = utils.getDayOfYearFromWeek(obj);
2076
+ }
2077
+ for (var i=0;i <= dayOffset.length;i++) {
2078
+ if (obj.dayOfYear < dayOffset[i] || i === dayOffset.length) {
2079
+ obj.day = obj.day ? obj.day : (obj.dayOfYear - dayOffset[i-1]);
2080
+ break;
2081
+ } else {
2082
+ obj.month = i;
2083
+ }
2084
+ }
2085
+ return obj;
2086
+ },
2087
+ adjustForTimeZone : function (obj, date) {
2088
+ var offset;
2089
+ if (obj.zone.toUpperCase() === "Z" || (obj.zone_hours === 0 && obj.zone_minutes === 0)) {
2090
+ // it's UTC/GML so work out the current timeszone offset
2091
+ offset = -date.getTimezoneOffset();
2092
+ } else {
2093
+ offset = (obj.zone_hours*60) + (obj.zone_minutes || 0);
2094
+ if (obj.zone_sign === "+") {
2095
+ offset *= -1;
2096
+ }
2097
+ offset -= date.getTimezoneOffset();
2098
+ }
2099
+ date.setMinutes(date.getMinutes()+offset);
2100
+ return date;
2101
+ },
2102
+ setDefaults : function (obj) {
2103
+ obj.year = obj.year || Date.today().getFullYear();
2104
+ obj.hours = obj.hours || 0;
2105
+ obj.minutes = obj.minutes || 0;
2106
+ obj.seconds = obj.seconds || 0;
2107
+ obj.milliseconds = obj.milliseconds || 0;
2108
+ if (!(!obj.month && (obj.week || obj.dayOfYear))) {
2109
+ // if we have a month, or if we don't but don't have the day calculation data
2110
+ obj.month = obj.month || 0;
2111
+ obj.day = obj.day || 1;
2112
+ }
2113
+ return obj;
2114
+ },
2115
+ dataNum: function (data, mod, explict, postProcess) {
2116
+ var dataNum = data*1;
2117
+ if (mod) {
2118
+ if (postProcess) {
2119
+ return data ? mod(data)*1 : data;
2120
+ } else {
2121
+ return data ? mod(dataNum) : data;
2122
+ }
2123
+ } else if (!explict){
2124
+ return data ? dataNum : data;
2125
+ } else {
2126
+ return (data && typeof data !== "undefined") ? dataNum : data;
2127
+ }
2128
+ },
2129
+ timeDataProcess: function (obj) {
2130
+ var timeObj = {};
2131
+ for (var x in obj.data) {
2132
+ if (obj.data.hasOwnProperty(x)) {
2133
+ timeObj[x] = obj.ignore[x] ? obj.data[x] : utils.dataNum(obj.data[x], obj.mods[x], obj.explict[x], obj.postProcess[x]);
2134
+ }
2135
+ }
2136
+ if (obj.data.secmins) {
2137
+ obj.data.secmins = obj.data.secmins.replace(",", ".") * 60;
2138
+ if (!timeObj.minutes) {
2139
+ timeObj.minutes = obj.data.secmins;
2140
+ } else if (!timeObj.seconds) {
2141
+ timeObj.seconds = obj.data.secmins;
2142
+ }
2143
+ delete obj.secmins;
2144
+ }
2145
+ return timeObj;
2146
+ },
2147
+ buildTimeObjectFromData: function (data) {
2148
+ var time = utils.timeDataProcess({
2149
+ data: {
2150
+ year : data[1],
2151
+ month : data[5],
2152
+ day : data[7],
2153
+ week : data[8],
2154
+ dayOfYear : data[10],
2155
+ hours : data[15],
2156
+ zone_hours : data[23],
2157
+ zone_minutes : data[24],
2158
+ zone : data[21],
2159
+ zone_sign : data[22],
2160
+ weekDay : data[9],
2161
+ minutes: data[16],
2162
+ seconds: data[19],
2163
+ milliseconds: data[20],
2164
+ secmins: data[18]
2165
+ },
2166
+ mods: {
2167
+ month: function(data) {
2168
+ return data-1;
2169
+ },
2170
+ weekDay: function (data) {
2171
+ data = Math.abs(data);
2172
+ return (data === 7 ? 0 : data);
2173
+ },
2174
+ minutes: function (data) {
2175
+ return data.replace(":","");
2176
+ },
2177
+ seconds: function (data) {
2178
+ return Math.floor( (data.replace(":","").replace(",","."))*1 );
2179
+ },
2180
+ milliseconds: function (data) {
2181
+ return (data.replace(",",".")*1000);
2182
+ }
2183
+ },
2184
+ postProcess: {
2185
+ minutes: true,
2186
+ seconds: true,
2187
+ milliseconds: true
2188
+ },
2189
+ explict: {
2190
+ zone_hours: true,
2191
+ zone_minutes: true
2192
+ },
2193
+ ignore: {
2194
+ zone: true,
2195
+ zone_sign: true,
2196
+ secmins: true
2197
+ }
2198
+ });
2199
+ return time;
2200
+ },
2201
+ addToHash: function (hash, keys, data) {
2202
+ keys = keys;
2203
+ data = data;
2204
+ var len = keys.length;
2205
+ for (var i = 0; i < len; i++) {
2206
+ hash[keys[i]] = data[i];
2207
+ }
2208
+ return hash;
2209
+ },
2210
+ combineRegex: function (r1, r2) {
2211
+ return new RegExp("(("+r1.source+")\\s("+r2.source+"))");
2212
+ },
2213
+ getDateNthString: function(add, last, inc){
2214
+ if (add) {
2215
+ return Date.today().addDays(inc).toString("d");
2216
+ } else if (last) {
2217
+ return Date.today().last()[inc]().toString("d");
2218
+ }
2219
+
2220
+ },
2221
+ buildRegexData: function (array) {
2222
+ var arr = [];
2223
+ var len = array.length;
2224
+ for (var i=0; i < len; i++) {
2225
+ if (Object.prototype.toString.call(array[i]) === '[object Array]') { // oldIE compat version of Array.isArray
2226
+ arr.push(this.combineRegex(array[i][0], array[i][1]));
2227
+ } else {
2228
+ arr.push(array[i]);
2229
+ }
2230
+ }
2231
+ return arr;
2232
+ }
2233
+ };
2234
+
2235
+ $P.processTimeObject = function (obj) {
2236
+ var date, dayOffset;
2237
+
2238
+ utils.setDefaults(obj);
2239
+ dayOffset = ($P.isLeapYear(obj.year)) ? dayOffsets.leap : dayOffsets.standard;
2240
+
2241
+ if (!obj.month && (obj.week || obj.dayOfYear)) {
2242
+ utils.getDayOfYear(obj, dayOffset);
2243
+ } else {
2244
+ obj.dayOfYear = dayOffset[obj.month] + obj.day;
2245
+ }
2246
+
2247
+ date = new Date(obj.year, obj.month, obj.day, obj.hours, obj.minutes, obj.seconds, obj.milliseconds);
2248
+
2249
+ if (obj.zone) {
2250
+ utils.adjustForTimeZone(obj, date); // adjust (and calculate) for timezone
2251
+ }
2252
+ return date;
2253
+ };
2254
+
2255
+ $P.ISO = {
2256
+ regex : /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-4])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?\s?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/,
2257
+ parse : function (s) {
2258
+ var time, data = s.match(this.regex);
2259
+ if (!data || !data.length) {
2260
+ return null;
2261
+ }
2262
+
2263
+ time = utils.buildTimeObjectFromData(data);
2264
+
2265
+ if (!time.year || (!time.year && (!time.month && !time.day) && (!time.week && !time.dayOfYear)) ) {
2266
+ return null;
2267
+ }
2268
+ return $P.processTimeObject(time);
2269
+ }
2270
+ };
2271
+
2272
+ $P.Numeric = {
2273
+ isNumeric: function (e){return!isNaN(parseFloat(e))&&isFinite(e);},
2274
+ regex: /\b([0-1]?[0-9])([0-3]?[0-9])([0-2]?[0-9]?[0-9][0-9])\b/i,
2275
+ parse: function (s) {
2276
+ var data, i,
2277
+ time = {},
2278
+ order = Date.CultureInfo.dateElementOrder.split("");
2279
+ if (!(this.isNumeric(s)) || // if it's non-numeric OR
2280
+ (s[0] === "+" && s[0] === "-")) { // It's an arithmatic string (eg +/-1000)
2281
+ return null;
2282
+ }
2283
+ if (s.length < 5 && s.indexOf(".") < 0 && s.indexOf("/") < 0) { // assume it's just a year.
2284
+ time.year = s;
2285
+ return $P.processTimeObject(time);
2286
+ }
2287
+ data = s.match(this.regex);
2288
+ if (!data || !data.length) {
2289
+ return null;
2290
+ }
2291
+ for (i=0; i < order.length; i++) {
2292
+ switch(order[i]) {
2293
+ case "d":
2294
+ time.day = data[i+1];
2295
+ break;
2296
+ case "m":
2297
+ time.month = (data[i+1]-1);
2298
+ break;
2299
+ case "y":
2300
+ time.year = data[i+1];
2301
+ break;
2302
+ }
2303
+ }
2304
+ return $P.processTimeObject(time);
2305
+ }
2306
+ };
2307
+
2308
+ $P.Normalizer = {
2309
+ regexData: function () {
2310
+ var $R = Date.CultureInfo.regexPatterns;
2311
+ return utils.buildRegexData([
2312
+ $R.tomorrow,
2313
+ $R.yesterday,
2314
+ [$R.past, $R.mon],
2315
+ [$R.past, $R.tue],
2316
+ [$R.past, $R.wed],
2317
+ [$R.past, $R.thu],
2318
+ [$R.past, $R.fri],
2319
+ [$R.past, $R.sat],
2320
+ [$R.past, $R.sun]
2321
+ ]);
2322
+ },
2323
+ basicReplaceHash : function() {
2324
+ var $R = Date.CultureInfo.regexPatterns;
2325
+ return {
2326
+ "January": $R.jan.source,
2327
+ "February": $R.feb,
2328
+ "March": $R.mar,
2329
+ "April": $R.apr,
2330
+ "May": $R.may,
2331
+ "June": $R.jun,
2332
+ "July": $R.jul,
2333
+ "August": $R.aug,
2334
+ "September": $R.sep,
2335
+ "October": $R.oct,
2336
+ "November": $R.nov,
2337
+ "December": $R.dec,
2338
+ "": /\bat\b/gi,
2339
+ " ": /\s{2,}/,
2340
+ "am": $R.inTheMorning,
2341
+ "9am": $R.thisMorning,
2342
+ "pm": $R.inTheEvening,
2343
+ "7pm":$R.thisEvening
2344
+ };
2345
+ },
2346
+ keys : function(){
2347
+ return [
2348
+ utils.getDateNthString(true, false, 1), // tomorrow
2349
+ utils.getDateNthString(true, false, -1), // yesterday
2350
+ utils.getDateNthString(false, true, "monday"), //last mon
2351
+ utils.getDateNthString(false, true, "tuesday"), //last tues
2352
+ utils.getDateNthString(false, true, "wednesday"), //last wed
2353
+ utils.getDateNthString(false, true, "thursday"), //last thurs
2354
+ utils.getDateNthString(false, true, "friday"), //last fri
2355
+ utils.getDateNthString(false, true, "saturday"), //last sat
2356
+ utils.getDateNthString(false, true, "sunday") //last sun
2357
+ ];
2358
+ },
2359
+ buildRegexFunctions: function () {
2360
+ var $R = Date.CultureInfo.regexPatterns;
2361
+ var __ = Date.i18n.__;
2362
+ var tomorrowRE = new RegExp("(\\b\\d\\d?("+__("AM")+"|"+__("PM")+")? )("+$R.tomorrow.source.slice(1)+")", "i"); // adapted tomorrow regex for AM PM relative dates
2363
+ var todayRE = new RegExp($R.today.source + "(?!\\s*([+-]))\\b"); // today, but excludes the math operators (eg "today + 2h")
2364
+
2365
+ this.replaceFuncs = [
2366
+ [todayRE, function (full) {
2367
+ return (full.length > 1) ? Date.today().toString("d") : full;
2368
+ }],
2369
+ [tomorrowRE,
2370
+ function(full, m1) {
2371
+ var t = Date.today().addDays(1).toString("d");
2372
+ return (t + " " + m1);
2373
+ }],
2374
+ [$R.amThisMorning, function(str, am){return am;}],
2375
+ [$R.pmThisEvening, function(str, pm){return pm;}]
2376
+ ];
2377
+
2378
+ },
2379
+ buildReplaceData: function () {
2380
+ this.buildRegexFunctions();
2381
+ this.replaceHash = utils.addToHash(this.basicReplaceHash(), this.keys(), this.regexData());
2382
+ },
2383
+ stringReplaceFuncs: function (s) {
2384
+ for (var i=0; i < this.replaceFuncs.length; i++) {
2385
+ s = s.replace(this.replaceFuncs[i][0], this.replaceFuncs[i][1]);
2386
+ }
2387
+ return s;
2388
+ },
2389
+ parse: function (s) {
2390
+ s = this.stringReplaceFuncs(s);
2391
+ s = utils.multiReplace(s, this.replaceHash);
2392
+
2393
+ try {
2394
+ var n = s.split(/([\s\-\.\,\/\x27]+)/);
2395
+ if (n.length === 3 &&
2396
+ $P.Numeric.isNumeric(n[0]) &&
2397
+ $P.Numeric.isNumeric(n[2]) &&
2398
+ (n[2].length >= 4)) {
2399
+ // ok, so we're dealing with x/year. But that's not a full date.
2400
+ // This fixes wonky dateElementOrder parsing when set to dmy order.
2401
+ if (Date.CultureInfo.dateElementOrder[0] === "d") {
2402
+ s = "1/" + n[0] + "/" + n[2]; // set to 1st of month and normalize the seperator
2403
+ }
2404
+ }
2405
+ } catch (e) {}
2406
+
2407
+ return s;
2408
+ }
2409
+ };
2410
+ $P.Normalizer.buildReplaceData();
2411
+ }());
2412
+ (function () {
2413
+ var $P = Date.Parsing;
2414
+ var _ = $P.Operators = {
2415
+ //
2416
+ // Tokenizers
2417
+ //
2418
+ rtoken: function (r) { // regex token
2419
+ return function (s) {
2420
+ var mx = s.match(r);
2421
+ if (mx) {
2422
+ return ([ mx[0], s.substring(mx[0].length) ]);
2423
+ } else {
2424
+ throw new $P.Exception(s);
2425
+ }
2426
+ };
2427
+ },
2428
+ token: function () { // whitespace-eating token
2429
+ return function (s) {
2430
+ return _.rtoken(new RegExp("^\\s*" + s + "\\s*"))(s);
2431
+ };
2432
+ },
2433
+ stoken: function (s) { // string token
2434
+ return _.rtoken(new RegExp("^" + s));
2435
+ },
2436
+
2437
+ // Atomic Operators
2438
+
2439
+ until: function (p) {
2440
+ return function (s) {
2441
+ var qx = [], rx = null;
2442
+ while (s.length) {
2443
+ try {
2444
+ rx = p.call(this, s);
2445
+ } catch (e) {
2446
+ qx.push(rx[0]);
2447
+ s = rx[1];
2448
+ continue;
2449
+ }
2450
+ break;
2451
+ }
2452
+ return [ qx, s ];
2453
+ };
2454
+ },
2455
+ many: function (p) {
2456
+ return function (s) {
2457
+ var rx = [], r = null;
2458
+ while (s.length) {
2459
+ try {
2460
+ r = p.call(this, s);
2461
+ } catch (e) {
2462
+ return [ rx, s ];
2463
+ }
2464
+ rx.push(r[0]);
2465
+ s = r[1];
2466
+ }
2467
+ return [ rx, s ];
2468
+ };
2469
+ },
2470
+
2471
+ // generator operators -- see below
2472
+ optional: function (p) {
2473
+ return function (s) {
2474
+ var r = null;
2475
+ try {
2476
+ r = p.call(this, s);
2477
+ } catch (e) {
2478
+ return [ null, s ];
2479
+ }
2480
+ return [ r[0], r[1] ];
2481
+ };
2482
+ },
2483
+ not: function (p) {
2484
+ return function (s) {
2485
+ try {
2486
+ p.call(this, s);
2487
+ } catch (e) {
2488
+ return [null, s];
2489
+ }
2490
+ throw new $P.Exception(s);
2491
+ };
2492
+ },
2493
+ ignore: function (p) {
2494
+ return p ?
2495
+ function (s) {
2496
+ var r = null;
2497
+ r = p.call(this, s);
2498
+ return [null, r[1]];
2499
+ } : null;
2500
+ },
2501
+ product: function () {
2502
+ var px = arguments[0],
2503
+ qx = Array.prototype.slice.call(arguments, 1), rx = [];
2504
+ for (var i = 0 ; i < px.length ; i++) {
2505
+ rx.push(_.each(px[i], qx));
2506
+ }
2507
+ return rx;
2508
+ },
2509
+ cache: function (rule) {
2510
+ var cache = {}, cache_length = 0, cache_keys = [], CACHE_MAX = Date.Config.CACHE_MAX || 100000, r = null;
2511
+ var cacheCheck = function () {
2512
+ if (cache_length === CACHE_MAX) {
2513
+ // kill several keys, don't want to have to do this all the time...
2514
+ for (var i=0; i < 10; i++) {
2515
+ var key = cache_keys.shift();
2516
+ if (key) {
2517
+ delete cache[key];
2518
+ cache_length--;
2519
+ }
2520
+ }
2521
+ }
2522
+ };
2523
+ return function (s) {
2524
+ cacheCheck();
2525
+ try {
2526
+ r = cache[s] = (cache[s] || rule.call(this, s));
2527
+ } catch (e) {
2528
+ r = cache[s] = e;
2529
+ }
2530
+ cache_length++;
2531
+ cache_keys.push(s);
2532
+ if (r instanceof $P.Exception) {
2533
+ throw r;
2534
+ } else {
2535
+ return r;
2536
+ }
2537
+ };
2538
+ },
2539
+
2540
+ // vector operators -- see below
2541
+ any: function () {
2542
+ var px = arguments;
2543
+ return function (s) {
2544
+ var r = null;
2545
+ for (var i = 0; i < px.length; i++) {
2546
+ if (px[i] == null) {
2547
+ continue;
2548
+ }
2549
+ try {
2550
+ r = (px[i].call(this, s));
2551
+ } catch (e) {
2552
+ r = null;
2553
+ }
2554
+ if (r) {
2555
+ return r;
2556
+ }
2557
+ }
2558
+ throw new $P.Exception(s);
2559
+ };
2560
+ },
2561
+ each: function () {
2562
+ var px = arguments;
2563
+ return function (s) {
2564
+ var rx = [], r = null;
2565
+ for (var i = 0; i < px.length ; i++) {
2566
+ if (px[i] == null) {
2567
+ continue;
2568
+ }
2569
+ try {
2570
+ r = (px[i].call(this, s));
2571
+ } catch (e) {
2572
+ throw new $P.Exception(s);
2573
+ }
2574
+ rx.push(r[0]);
2575
+ s = r[1];
2576
+ }
2577
+ return [ rx, s];
2578
+ };
2579
+ },
2580
+ all: function () {
2581
+ var px = arguments, _ = _;
2582
+ return _.each(_.optional(px));
2583
+ },
2584
+
2585
+ // delimited operators
2586
+ sequence: function (px, d, c) {
2587
+ d = d || _.rtoken(/^\s*/);
2588
+ c = c || null;
2589
+
2590
+ if (px.length === 1) {
2591
+ return px[0];
2592
+ }
2593
+ return function (s) {
2594
+ var r = null, q = null;
2595
+ var rx = [];
2596
+ for (var i = 0; i < px.length ; i++) {
2597
+ try {
2598
+ r = px[i].call(this, s);
2599
+ } catch (e) {
2600
+ break;
2601
+ }
2602
+ rx.push(r[0]);
2603
+ try {
2604
+ q = d.call(this, r[1]);
2605
+ } catch (ex) {
2606
+ q = null;
2607
+ break;
2608
+ }
2609
+ s = q[1];
2610
+ }
2611
+ if (!r) {
2612
+ throw new $P.Exception(s);
2613
+ }
2614
+ if (q) {
2615
+ throw new $P.Exception(q[1]);
2616
+ }
2617
+ if (c) {
2618
+ try {
2619
+ r = c.call(this, r[1]);
2620
+ } catch (ey) {
2621
+ throw new $P.Exception(r[1]);
2622
+ }
2623
+ }
2624
+ return [ rx, (r?r[1]:s) ];
2625
+ };
2626
+ },
2627
+
2628
+ //
2629
+ // Composite Operators
2630
+ //
2631
+
2632
+ between: function (d1, p, d2) {
2633
+ d2 = d2 || d1;
2634
+ var _fn = _.each(_.ignore(d1), p, _.ignore(d2));
2635
+ return function (s) {
2636
+ var rx = _fn.call(this, s);
2637
+ return [[rx[0][0], r[0][2]], rx[1]];
2638
+ };
2639
+ },
2640
+ list: function (p, d, c) {
2641
+ d = d || _.rtoken(/^\s*/);
2642
+ c = c || null;
2643
+ return (p instanceof Array ?
2644
+ _.each(_.product(p.slice(0, -1), _.ignore(d)), p.slice(-1), _.ignore(c)) :
2645
+ _.each(_.many(_.each(p, _.ignore(d))), px, _.ignore(c)));
2646
+ },
2647
+ set: function (px, d, c) {
2648
+ d = d || _.rtoken(/^\s*/);
2649
+ c = c || null;
2650
+ return function (s) {
2651
+ // r is the current match, best the current 'best' match
2652
+ // which means it parsed the most amount of input
2653
+ var r = null, p = null, q = null, rx = null, best = [[], s], last = false;
2654
+ // go through the rules in the given set
2655
+ for (var i = 0; i < px.length ; i++) {
2656
+
2657
+ // last is a flag indicating whether this must be the last element
2658
+ // if there is only 1 element, then it MUST be the last one
2659
+ q = null;
2660
+ p = null;
2661
+ r = null;
2662
+ last = (px.length === 1);
2663
+ // first, we try simply to match the current pattern
2664
+ // if not, try the next pattern
2665
+ try {
2666
+ r = px[i].call(this, s);
2667
+ } catch (e) {
2668
+ continue;
2669
+ }
2670
+ // since we are matching against a set of elements, the first
2671
+ // thing to do is to add r[0] to matched elements
2672
+ rx = [[r[0]], r[1]];
2673
+ // if we matched and there is still input to parse and
2674
+ // we don't already know this is the last element,
2675
+ // we're going to next check for the delimiter ...
2676
+ // if there's none, or if there's no input left to parse
2677
+ // than this must be the last element after all ...
2678
+ if (r[1].length > 0 && ! last) {
2679
+ try {
2680
+ q = d.call(this, r[1]);
2681
+ } catch (ex) {
2682
+ last = true;
2683
+ }
2684
+ } else {
2685
+ last = true;
2686
+ }
2687
+
2688
+ // if we parsed the delimiter and now there's no more input,
2689
+ // that means we shouldn't have parsed the delimiter at all
2690
+ // so don't update r and mark this as the last element ...
2691
+ if (!last && q[1].length === 0) {
2692
+ last = true;
2693
+ }
2694
+
2695
+
2696
+ // so, if this isn't the last element, we're going to see if
2697
+ // we can get any more matches from the remaining (unmatched)
2698
+ // elements ...
2699
+ if (!last) {
2700
+ // build a list of the remaining rules we can match against,
2701
+ // i.e., all but the one we just matched against
2702
+ var qx = [];
2703
+ for (var j = 0; j < px.length ; j++) {
2704
+ if (i !== j) {
2705
+ qx.push(px[j]);
2706
+ }
2707
+ }
2708
+
2709
+ // now invoke recursively set with the remaining input
2710
+ // note that we don't include the closing delimiter ...
2711
+ // we'll check for that ourselves at the end
2712
+ p = _.set(qx, d).call(this, q[1]);
2713
+
2714
+ // if we got a non-empty set as a result ...
2715
+ // (otw rx already contains everything we want to match)
2716
+ if (p[0].length > 0) {
2717
+ // update current result, which is stored in rx ...
2718
+ // basically, pick up the remaining text from p[1]
2719
+ // and concat the result from p[0] so that we don't
2720
+ // get endless nesting ...
2721
+ rx[0] = rx[0].concat(p[0]);
2722
+ rx[1] = p[1];
2723
+ }
2724
+ }
2725
+
2726
+ // at this point, rx either contains the last matched element
2727
+ // or the entire matched set that starts with this element.
2728
+
2729
+ // now we just check to see if this variation is better than
2730
+ // our best so far, in terms of how much of the input is parsed
2731
+ if (rx[1].length < best[1].length) {
2732
+ best = rx;
2733
+ }
2734
+
2735
+ // if we've parsed all the input, then we're finished
2736
+ if (best[1].length === 0) {
2737
+ break;
2738
+ }
2739
+ }
2740
+
2741
+ // so now we've either gone through all the patterns trying them
2742
+ // as the initial match; or we found one that parsed the entire
2743
+ // input string ...
2744
+
2745
+ // if best has no matches, just return empty set ...
2746
+ if (best[0].length === 0) {
2747
+ return best;
2748
+ }
2749
+
2750
+ // if a closing delimiter is provided, then we have to check it also
2751
+ if (c) {
2752
+ // we try this even if there is no remaining input because the pattern
2753
+ // may well be optional or match empty input ...
2754
+ try {
2755
+ q = c.call(this, best[1]);
2756
+ } catch (ey) {
2757
+ throw new $P.Exception(best[1]);
2758
+ }
2759
+
2760
+ // it parsed ... be sure to update the best match remaining input
2761
+ best[1] = q[1];
2762
+ }
2763
+ // if we're here, either there was no closing delimiter or we parsed it
2764
+ // so now we have the best match; just return it!
2765
+ return best;
2766
+ };
2767
+ },
2768
+ forward: function (gr, fname) {
2769
+ return function (s) {
2770
+ return gr[fname].call(this, s);
2771
+ };
2772
+ },
2773
+
2774
+ //
2775
+ // Translation Operators
2776
+ //
2777
+ replace: function (rule, repl) {
2778
+ return function (s) {
2779
+ var r = rule.call(this, s);
2780
+ return [repl, r[1]];
2781
+ };
2782
+ },
2783
+ process: function (rule, fn) {
2784
+ return function (s) {
2785
+ var r = rule.call(this, s);
2786
+ return [fn.call(this, r[0]), r[1]];
2787
+ };
2788
+ },
2789
+ min: function (min, rule) {
2790
+ return function (s) {
2791
+ var rx = rule.call(this, s);
2792
+ if (rx[0].length < min) {
2793
+ throw new $P.Exception(s);
2794
+ }
2795
+ return rx;
2796
+ };
2797
+ }
2798
+ };
2799
+
2800
+
2801
+ // Generator Operators And Vector Operators
2802
+
2803
+ // Generators are operators that have a signature of F(R) => R,
2804
+ // taking a given rule and returning another rule, such as
2805
+ // ignore, which parses a given rule and throws away the result.
2806
+
2807
+ // Vector operators are those that have a signature of F(R1,R2,...) => R,
2808
+ // take a list of rules and returning a new rule, such as each.
2809
+
2810
+ // Generator operators are converted (via the following _generator
2811
+ // function) into functions that can also take a list or array of rules
2812
+ // and return an array of new rules as though the function had been
2813
+ // called on each rule in turn (which is what actually happens).
2814
+
2815
+ // This allows generators to be used with vector operators more easily.
2816
+ // Example:
2817
+ // each(ignore(foo, bar)) instead of each(ignore(foo), ignore(bar))
2818
+
2819
+ // This also turns generators into vector operators, which allows
2820
+ // constructs like:
2821
+ // not(cache(foo, bar))
2822
+
2823
+ var _generator = function (op) {
2824
+ function gen() {
2825
+ var args = null, rx = [], px, i;
2826
+ if (arguments.length > 1) {
2827
+ args = Array.prototype.slice.call(arguments);
2828
+ } else if (arguments[0] instanceof Array) {
2829
+ args = arguments[0];
2830
+ }
2831
+ if (args) {
2832
+ px = args.shift();
2833
+ if (px.length > 0) {
2834
+ args.unshift(px[i]);
2835
+ rx.push(op.apply(null, args));
2836
+ args.shift();
2837
+ return rx;
2838
+ }
2839
+ } else {
2840
+ return op.apply(null, arguments);
2841
+ }
2842
+ }
2843
+
2844
+ return gen;
2845
+ };
2846
+
2847
+ var gx = "optional not ignore cache".split(/\s/);
2848
+
2849
+ for (var i = 0 ; i < gx.length ; i++) {
2850
+ _[gx[i]] = _generator(_[gx[i]]);
2851
+ }
2852
+
2853
+ var _vector = function (op) {
2854
+ return function () {
2855
+ if (arguments[0] instanceof Array) {
2856
+ return op.apply(null, arguments[0]);
2857
+ } else {
2858
+ return op.apply(null, arguments);
2859
+ }
2860
+ };
2861
+ };
2862
+
2863
+ var vx = "each any all".split(/\s/);
2864
+
2865
+ for (var j = 0 ; j < vx.length ; j++) {
2866
+ _[vx[j]] = _vector(_[vx[j]]);
2867
+ }
2868
+
2869
+ }());
2870
+ (function () {
2871
+ var $D = Date;
2872
+
2873
+ var flattenAndCompact = function (ax) {
2874
+ var rx = [];
2875
+ for (var i = 0; i < ax.length; i++) {
2876
+ if (ax[i] instanceof Array) {
2877
+ rx = rx.concat(flattenAndCompact(ax[i]));
2878
+ } else {
2879
+ if (ax[i]) {
2880
+ rx.push(ax[i]);
2881
+ }
2882
+ }
2883
+ }
2884
+ return rx;
2885
+ };
2886
+
2887
+ var parseMeridian = function () {
2888
+ if (this.meridian && (this.hour || this.hour === 0)) {
2889
+ if (this.meridian === "a" && this.hour > 11 && Date.Config.strict24hr){
2890
+ throw "Invalid hour and meridian combination";
2891
+ } else if (this.meridian === "p" && this.hour < 12 && Date.Config.strict24hr){
2892
+ throw "Invalid hour and meridian combination";
2893
+ } else if (this.meridian === "p" && this.hour < 12) {
2894
+ this.hour = this.hour + 12;
2895
+ } else if (this.meridian === "a" && this.hour === 12) {
2896
+ this.hour = 0;
2897
+ }
2898
+ }
2899
+ };
2900
+
2901
+ var setDefaults = function () {
2902
+ var now = new Date();
2903
+ if ((this.hour || this.minute) && (!this.month && !this.year && !this.day)) {
2904
+ this.day = now.getDate();
2905
+ }
2906
+
2907
+ if (!this.year) {
2908
+ this.year = now.getFullYear();
2909
+ }
2910
+
2911
+ if (!this.month && this.month !== 0) {
2912
+ this.month = now.getMonth();
2913
+ }
2914
+
2915
+ if (!this.day) {
2916
+ this.day = 1;
2917
+ }
2918
+
2919
+ if (!this.hour) {
2920
+ this.hour = 0;
2921
+ }
2922
+
2923
+ if (!this.minute) {
2924
+ this.minute = 0;
2925
+ }
2926
+
2927
+ if (!this.second) {
2928
+ this.second = 0;
2929
+ }
2930
+ if (!this.millisecond) {
2931
+ this.millisecond = 0;
2932
+ }
2933
+ };
2934
+
2935
+ var finishUtils = {
2936
+ getToday: function () {
2937
+ if (this.now || "hour minute second".indexOf(this.unit) !== -1) {
2938
+ return new Date();
2939
+ } else {
2940
+ return $D.today();
2941
+ }
2942
+ },
2943
+ setDaysFromWeekday: function (today, orient){
2944
+ var gap;
2945
+ orient = orient || 1;
2946
+ this.unit = "day";
2947
+ gap = ($D.getDayNumberFromName(this.weekday) - today.getDay());
2948
+ this.days = gap ? ((gap + (orient * 7)) % 7) : (orient * 7);
2949
+ return this;
2950
+ },
2951
+ setMonthsFromMonth: function (today, orient) {
2952
+ var gap;
2953
+ orient = orient || 1;
2954
+ this.unit = "month";
2955
+ gap = (this.month - today.getMonth());
2956
+ this.months = gap ? ((gap + (orient * 12)) % 12) : (orient * 12);
2957
+ this.month = null;
2958
+ return this;
2959
+ },
2960
+ setDMYFromWeekday: function () {
2961
+ var d = Date[this.weekday]();
2962
+ this.day = d.getDate();
2963
+ if (!this.month) {
2964
+ this.month = d.getMonth();
2965
+ }
2966
+ this.year = d.getFullYear();
2967
+ return this;
2968
+ },
2969
+ setUnitValue: function (orient) {
2970
+ if (!this.value && this.operator && this.operator !== null && this[this.unit + "s"] && this[this.unit + "s"] !== null) {
2971
+ this[this.unit + "s"] = this[this.unit + "s"] + ((this.operator === "add") ? 1 : -1) + (this.value||0) * orient;
2972
+ } else if (this[this.unit + "s"] == null || this.operator != null) {
2973
+ if (!this.value) {
2974
+ this.value = 1;
2975
+ }
2976
+ this[this.unit + "s"] = this.value * orient;
2977
+ }
2978
+ },
2979
+ generateDateFromWeeks: function () {
2980
+ var weekday = (this.weekday !== undefined) ? this.weekday : "today";
2981
+ var d = Date[weekday]().addWeeks(this.weeks);
2982
+ if (this.now) {
2983
+ d.setTimeToNow();
2984
+ }
2985
+ return d;
2986
+ }
2987
+ };
2988
+
2989
+ $D.Translator = {
2990
+ hour: function (s) {
2991
+ return function () {
2992
+ this.hour = Number(s);
2993
+ };
2994
+ },
2995
+ minute: function (s) {
2996
+ return function () {
2997
+ this.minute = Number(s);
2998
+ };
2999
+ },
3000
+ second: function (s) {
3001
+ return function () {
3002
+ this.second = Number(s);
3003
+ };
3004
+ },
3005
+ /* for ss.s format */
3006
+ secondAndMillisecond: function (s) {
3007
+ return function () {
3008
+ var mx = s.match(/^([0-5][0-9])\.([0-9]{1,3})/);
3009
+ this.second = Number(mx[1]);
3010
+ this.millisecond = Number(mx[2]);
3011
+ };
3012
+ },
3013
+ meridian: function (s) {
3014
+ return function () {
3015
+ this.meridian = s.slice(0, 1).toLowerCase();
3016
+ };
3017
+ },
3018
+ timezone: function (s) {
3019
+ return function () {
3020
+ var n = s.replace(/[^\d\+\-]/g, "");
3021
+ if (n.length) {
3022
+ this.timezoneOffset = Number(n);
3023
+ } else {
3024
+ this.timezone = s.toLowerCase();
3025
+ }
3026
+ };
3027
+ },
3028
+ day: function (x) {
3029
+ var s = x[0];
3030
+ return function () {
3031
+ this.day = Number(s.match(/\d+/)[0]);
3032
+ if (this.day < 1) {
3033
+ throw "invalid day";
3034
+ }
3035
+ };
3036
+ },
3037
+ month: function (s) {
3038
+ return function () {
3039
+ this.month = (s.length === 3) ? "jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4 : Number(s) - 1;
3040
+ if (this.month < 0) {
3041
+ throw "invalid month";
3042
+ }
3043
+ };
3044
+ },
3045
+ year: function (s) {
3046
+ return function () {
3047
+ var n = Number(s);
3048
+ this.year = ((s.length > 2) ? n :
3049
+ (n + (((n + 2000) < Date.CultureInfo.twoDigitYearMax) ? 2000 : 1900)));
3050
+ };
3051
+ },
3052
+ rday: function (s) {
3053
+ return function () {
3054
+ switch (s) {
3055
+ case "yesterday":
3056
+ this.days = -1;
3057
+ break;
3058
+ case "tomorrow":
3059
+ this.days = 1;
3060
+ break;
3061
+ case "today":
3062
+ this.days = 0;
3063
+ break;
3064
+ case "now":
3065
+ this.days = 0;
3066
+ this.now = true;
3067
+ break;
3068
+ }
3069
+ };
3070
+ },
3071
+ finishExact: function (x) {
3072
+ var d;
3073
+ x = (x instanceof Array) ? x : [x];
3074
+
3075
+ for (var i = 0 ; i < x.length ; i++) {
3076
+ if (x[i]) {
3077
+ x[i].call(this);
3078
+ }
3079
+ }
3080
+
3081
+ setDefaults.call(this);
3082
+ parseMeridian.call(this);
3083
+
3084
+ if (this.day > $D.getDaysInMonth(this.year, this.month)) {
3085
+ throw new RangeError(this.day + " is not a valid value for days.");
3086
+ }
3087
+
3088
+ d = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
3089
+ if (this.year < 100) {
3090
+ d.setFullYear(this.year); // means years less that 100 are process correctly. JS will parse it otherwise as 1900-1999.
3091
+ }
3092
+ if (this.timezone) {
3093
+ d.set({ timezone: this.timezone });
3094
+ } else if (this.timezoneOffset) {
3095
+ d.set({ timezoneOffset: this.timezoneOffset });
3096
+ }
3097
+
3098
+ return d;
3099
+ },
3100
+ finish: function (x) {
3101
+ var today, expression, orient, temp;
3102
+
3103
+ x = (x instanceof Array) ? flattenAndCompact(x) : [ x ];
3104
+
3105
+ if (x.length === 0) {
3106
+ return null;
3107
+ }
3108
+
3109
+ for (var i = 0 ; i < x.length ; i++) {
3110
+ if (typeof x[i] === "function") {
3111
+ x[i].call(this);
3112
+ }
3113
+ }
3114
+ if (this.now && !this.unit && !this.operator) {
3115
+ return new Date();
3116
+ } else {
3117
+ today = finishUtils.getToday.call(this);
3118
+ }
3119
+
3120
+ expression = !!(this.days && this.days !== null || this.orient || this.operator);
3121
+ orient = ((this.orient === "past" || this.operator === "subtract") ? -1 : 1);
3122
+
3123
+ if (this.month && this.unit === "week") {
3124
+ this.value = this.month + 1;
3125
+ delete this.month;
3126
+ delete this.day;
3127
+ }
3128
+
3129
+ if ((this.month || this.month === 0) && "year day hour minute second".indexOf(this.unit) !== -1) {
3130
+ if (!this.value) {
3131
+ this.value = this.month + 1;
3132
+ }
3133
+ this.month = null;
3134
+ expression = true;
3135
+ }
3136
+
3137
+ if (!expression && this.weekday && !this.day && !this.days) {
3138
+ finishUtils.setDMYFromWeekday.call(this);
3139
+ }
3140
+
3141
+ if (expression && this.weekday && this.unit !== "month" && this.unit !== "week") {
3142
+ finishUtils.setDaysFromWeekday.call(this, today, orient);
3143
+ }
3144
+
3145
+ if (this.weekday && this.unit !== "week" && !this.day && !this.days) {
3146
+ temp = Date[this.weekday]();
3147
+ this.day = temp.getDate();
3148
+ if (temp.getMonth() !== today.getMonth()) {
3149
+ this.month = temp.getMonth();
3150
+ }
3151
+ }
3152
+
3153
+ if (this.month && this.unit === "day" && this.operator) {
3154
+ if (!this.value) {
3155
+ this.value = (this.month + 1);
3156
+ }
3157
+ this.month = null;
3158
+ }
3159
+
3160
+ if (this.value != null && this.month != null && this.year != null) {
3161
+ this.day = this.value * 1;
3162
+ }
3163
+
3164
+ if (this.month && !this.day && this.value) {
3165
+ today.set({ day: this.value * 1 });
3166
+ if (!expression) {
3167
+ this.day = this.value * 1;
3168
+ }
3169
+ }
3170
+
3171
+ if (!this.month && this.value && this.unit === "month" && !this.now) {
3172
+ this.month = this.value;
3173
+ expression = true;
3174
+ }
3175
+
3176
+ if (expression && (this.month || this.month === 0) && this.unit !== "year") {
3177
+ finishUtils.setMonthsFromMonth.call(this, today, orient);
3178
+ }
3179
+
3180
+ if (!this.unit) {
3181
+ this.unit = "day";
3182
+ }
3183
+
3184
+ finishUtils.setUnitValue.call(this, orient);
3185
+ parseMeridian.call(this);
3186
+
3187
+ if ((this.month || this.month === 0) && !this.day) {
3188
+ this.day = 1;
3189
+ }
3190
+
3191
+ if (!this.orient && !this.operator && this.unit === "week" && this.value && !this.day && !this.month) {
3192
+ return Date.today().setWeek(this.value);
3193
+ }
3194
+
3195
+ if (this.unit === "week" && this.weeks && !this.day && !this.month) {
3196
+ return finishUtils.generateDateFromWeeks.call(this);
3197
+ }
3198
+
3199
+ if (expression && this.timezone && this.day && this.days) {
3200
+ this.day = this.days;
3201
+ }
3202
+
3203
+ if (expression){
3204
+ today.add(this);
3205
+ } else {
3206
+ today.set(this);
3207
+ }
3208
+
3209
+ if (this.timezone) {
3210
+ this.timezone = this.timezone.toUpperCase();
3211
+ var offset = $D.getTimezoneOffset(this.timezone);
3212
+ var timezone;
3213
+ if (today.hasDaylightSavingTime()) {
3214
+ // lets check that we're being sane with timezone setting
3215
+ timezone = $D.getTimezoneAbbreviation(offset, today.isDaylightSavingTime());
3216
+ if (timezone !== this.timezone) {
3217
+ // bugger, we're in a place where things like EST vs EDT matters.
3218
+ if (today.isDaylightSavingTime()) {
3219
+ today.addHours(-1);
3220
+ } else {
3221
+ today.addHours(1);
3222
+ }
3223
+ }
3224
+ }
3225
+ today.setTimezoneOffset(offset);
3226
+ }
3227
+
3228
+ return today;
3229
+ }
3230
+ };
3231
+ }());
3232
+ (function () {
3233
+ var $D = Date;
3234
+ $D.Grammar = {};
3235
+ var _ = $D.Parsing.Operators, g = $D.Grammar, t = $D.Translator, _fn;
3236
+ // Allow rolling up into general purpose rules
3237
+ _fn = function () {
3238
+ return _.each(_.any.apply(null, arguments), _.not(g.ctoken2("timeContext")));
3239
+ };
3240
+
3241
+ g.datePartDelimiter = _.rtoken(/^([\s\-\.\,\/\x27]+)/);
3242
+ g.timePartDelimiter = _.stoken(":");
3243
+ g.whiteSpace = _.rtoken(/^\s*/);
3244
+ g.generalDelimiter = _.rtoken(/^(([\s\,]|at|@|on)+)/);
3245
+
3246
+ var _C = {};
3247
+ g.ctoken = function (keys) {
3248
+ var fn = _C[keys];
3249
+ if (! fn) {
3250
+ var c = Date.CultureInfo.regexPatterns;
3251
+ var kx = keys.split(/\s+/), px = [];
3252
+ for (var i = 0; i < kx.length ; i++) {
3253
+ px.push(_.replace(_.rtoken(c[kx[i]]), kx[i]));
3254
+ }
3255
+ fn = _C[keys] = _.any.apply(null, px);
3256
+ }
3257
+ return fn;
3258
+ };
3259
+ g.ctoken2 = function (key) {
3260
+ return _.rtoken(Date.CultureInfo.regexPatterns[key]);
3261
+ };
3262
+ var cacheProcessRtoken = function (key, token, type, eachToken) {
3263
+ if (eachToken) {
3264
+ g[key] = _.cache(_.process(_.each(_.rtoken(token),_.optional(g.ctoken2(eachToken))), type));
3265
+ } else {
3266
+ g[key] = _.cache(_.process(_.rtoken(token), type));
3267
+ }
3268
+ };
3269
+ var cacheProcessCtoken = function (token, type) {
3270
+ return _.cache(_.process(g.ctoken2(token), type));
3271
+ };
3272
+ var _F = {}; //function cache
3273
+
3274
+ var _get = function (f) {
3275
+ _F[f] = (_F[f] || g.format(f)[0]);
3276
+ return _F[f];
3277
+ };
3278
+
3279
+ g.allformats = function (fx) {
3280
+ var rx = [];
3281
+ if (fx instanceof Array) {
3282
+ for (var i = 0; i < fx.length; i++) {
3283
+ rx.push(_get(fx[i]));
3284
+ }
3285
+ } else {
3286
+ rx.push(_get(fx));
3287
+ }
3288
+ return rx;
3289
+ };
3290
+
3291
+ g.formats = function (fx) {
3292
+ if (fx instanceof Array) {
3293
+ var rx = [];
3294
+ for (var i = 0 ; i < fx.length ; i++) {
3295
+ rx.push(_get(fx[i]));
3296
+ }
3297
+ return _.any.apply(null, rx);
3298
+ } else {
3299
+ return _get(fx);
3300
+ }
3301
+ };
3302
+
3303
+ var grammarFormats = {
3304
+ timeFormats: function(){
3305
+ var i,
3306
+ RTokenKeys = [
3307
+ "h",
3308
+ "hh",
3309
+ "H",
3310
+ "HH",
3311
+ "m",
3312
+ "mm",
3313
+ "s",
3314
+ "ss",
3315
+ "ss.s",
3316
+ "z",
3317
+ "zz"
3318
+ ],
3319
+ RToken = [
3320
+ /^(0[0-9]|1[0-2]|[1-9])/,
3321
+ /^(0[0-9]|1[0-2])/,
3322
+ /^([0-1][0-9]|2[0-3]|[0-9])/,
3323
+ /^([0-1][0-9]|2[0-3])/,
3324
+ /^([0-5][0-9]|[0-9])/,
3325
+ /^[0-5][0-9]/,
3326
+ /^([0-5][0-9]|[0-9])/,
3327
+ /^[0-5][0-9]/,
3328
+ /^[0-5][0-9]\.[0-9]{1,3}/,
3329
+ /^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/,
3330
+ /^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/
3331
+ ],
3332
+ tokens = [
3333
+ t.hour,
3334
+ t.hour,
3335
+ t.hour,
3336
+ t.minute,
3337
+ t.minute,
3338
+ t.second,
3339
+ t.second,
3340
+ t.secondAndMillisecond,
3341
+ t.timezone,
3342
+ t.timezone,
3343
+ t.timezone
3344
+ ];
3345
+
3346
+ for (i=0; i < RTokenKeys.length; i++) {
3347
+ cacheProcessRtoken(RTokenKeys[i], RToken[i], tokens[i]);
3348
+ }
3349
+
3350
+ g.hms = _.cache(_.sequence([g.H, g.m, g.s], g.timePartDelimiter));
3351
+
3352
+ g.t = cacheProcessCtoken("shortMeridian", t.meridian);
3353
+ g.tt = cacheProcessCtoken("longMeridian", t.meridian);
3354
+ g.zzz = cacheProcessCtoken("timezone", t.timezone);
3355
+
3356
+ g.timeSuffix = _.each(_.ignore(g.whiteSpace), _.set([ g.tt, g.zzz ]));
3357
+ g.time = _.each(_.optional(_.ignore(_.stoken("T"))), g.hms, g.timeSuffix);
3358
+ },
3359
+ dateFormats: function () {
3360
+ // pre-loaded rules for different date part order preferences
3361
+ var _setfn = function () {
3362
+ return _.set(arguments, g.datePartDelimiter);
3363
+ };
3364
+ var i,
3365
+ RTokenKeys = [
3366
+ "d",
3367
+ "dd",
3368
+ "M",
3369
+ "MM",
3370
+ "y",
3371
+ "yy",
3372
+ "yyy",
3373
+ "yyyy"
3374
+ ],
3375
+ RToken = [
3376
+ /^([0-2]\d|3[0-1]|\d)/,
3377
+ /^([0-2]\d|3[0-1])/,
3378
+ /^(1[0-2]|0\d|\d)/,
3379
+ /^(1[0-2]|0\d)/,
3380
+ /^(\d+)/,
3381
+ /^(\d\d)/,
3382
+ /^(\d\d?\d?\d?)/,
3383
+ /^(\d\d\d\d)/
3384
+ ],
3385
+ tokens = [
3386
+ t.day,
3387
+ t.day,
3388
+ t.month,
3389
+ t.month,
3390
+ t.year,
3391
+ t.year,
3392
+ t.year,
3393
+ t.year
3394
+ ],
3395
+ eachToken = [
3396
+ "ordinalSuffix",
3397
+ "ordinalSuffix"
3398
+ ];
3399
+ for (i=0; i < RTokenKeys.length; i++) {
3400
+ cacheProcessRtoken(RTokenKeys[i], RToken[i], tokens[i], eachToken[i]);
3401
+ }
3402
+
3403
+ g.MMM = g.MMMM = _.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"), t.month));
3404
+ g.ddd = g.dddd = _.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),
3405
+ function (s) {
3406
+ return function () {
3407
+ this.weekday = s;
3408
+ };
3409
+ }
3410
+ ));
3411
+
3412
+ g.day = _fn(g.d, g.dd);
3413
+ g.month = _fn(g.M, g.MMM);
3414
+ g.year = _fn(g.yyyy, g.yy);
3415
+
3416
+ g.mdy = _setfn(g.ddd, g.month, g.day, g.year);
3417
+ g.ymd = _setfn(g.ddd, g.year, g.month, g.day);
3418
+ g.dmy = _setfn(g.ddd, g.day, g.month, g.year);
3419
+
3420
+ g.date = function (s) {
3421
+ return ((g[Date.CultureInfo.dateElementOrder] || g.mdy).call(this, s));
3422
+ };
3423
+ },
3424
+ relative: function () {
3425
+ // relative date / time expressions
3426
+ g.orientation = _.process(g.ctoken("past future"),
3427
+ function (s) {
3428
+ return function () {
3429
+ this.orient = s;
3430
+ };
3431
+ }
3432
+ );
3433
+
3434
+ g.operator = _.process(g.ctoken("add subtract"),
3435
+ function (s) {
3436
+ return function () {
3437
+ this.operator = s;
3438
+ };
3439
+ }
3440
+ );
3441
+ g.rday = _.process(g.ctoken("yesterday tomorrow today now"), t.rday);
3442
+ g.unit = _.process(g.ctoken("second minute hour day week month year"),
3443
+ function (s) {
3444
+ return function () {
3445
+ this.unit = s;
3446
+ };
3447
+ }
3448
+ );
3449
+ }
3450
+ };
3451
+
3452
+ g.buildGrammarFormats = function () {
3453
+ // these need to be rebuilt every time the language changes.
3454
+ _C = {};
3455
+
3456
+ grammarFormats.timeFormats();
3457
+ grammarFormats.dateFormats();
3458
+ grammarFormats.relative();
3459
+
3460
+
3461
+ g.value = _.process(_.rtoken(/^([-+]?\d+)?(st|nd|rd|th)?/),
3462
+ function (s) {
3463
+ return function () {
3464
+ this.value = s.replace(/\D/g, "");
3465
+ };
3466
+ }
3467
+ );
3468
+ g.expression = _.set([g.rday, g.operator, g.value, g.unit, g.orientation, g.ddd, g.MMM ]);
3469
+
3470
+ g.format = _.process(_.many(
3471
+ _.any(
3472
+ // translate format specifiers into grammar rules
3473
+ _.process(
3474
+ _.rtoken(/^(dd?d?d?(?!e)|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),
3475
+ function (fmt) {
3476
+ if (g[fmt]) {
3477
+ return g[fmt];
3478
+ } else {
3479
+ throw $D.Parsing.Exception(fmt);
3480
+ }
3481
+ }
3482
+ ),
3483
+ // translate separator tokens into token rules
3484
+ _.process(_.rtoken(/^[^dMyhHmstz]+/), // all legal separators
3485
+ function (s) {
3486
+ return _.ignore(_.stoken(s));
3487
+ }
3488
+ )
3489
+ )
3490
+ ),
3491
+ // construct the parser ...
3492
+ function (rules) {
3493
+ return _.process(_.each.apply(null, rules), t.finishExact);
3494
+ }
3495
+ );
3496
+
3497
+ // starting rule for general purpose grammar
3498
+ g._start = _.process(_.set([ g.date, g.time, g.expression ],
3499
+ g.generalDelimiter, g.whiteSpace), t.finish);
3500
+ };
3501
+
3502
+ g.buildGrammarFormats();
3503
+ // parsing date format specifiers - ex: "h:m:s tt"
3504
+ // this little guy will generate a custom parser based
3505
+ // on the format string, ex: g.format("h:m:s tt")
3506
+ // check for these formats first
3507
+ g._formats = g.formats([
3508
+ "\"yyyy-MM-ddTHH:mm:ssZ\"",
3509
+ "yyyy-MM-ddTHH:mm:ss.sz",
3510
+ "yyyy-MM-ddTHH:mm:ssZ",
3511
+ "yyyy-MM-ddTHH:mm:ssz",
3512
+ "yyyy-MM-ddTHH:mm:ss",
3513
+ "yyyy-MM-ddTHH:mmZ",
3514
+ "yyyy-MM-ddTHH:mmz",
3515
+ "yyyy-MM-ddTHH:mm",
3516
+ "ddd, MMM dd, yyyy H:mm:ss tt",
3517
+ "ddd MMM d yyyy HH:mm:ss zzz",
3518
+ "MMddyyyy",
3519
+ "ddMMyyyy",
3520
+ "Mddyyyy",
3521
+ "ddMyyyy",
3522
+ "Mdyyyy",
3523
+ "dMyyyy",
3524
+ "yyyy",
3525
+ "Mdyy",
3526
+ "dMyy",
3527
+ "d"
3528
+ ]);
3529
+
3530
+ // real starting rule: tries selected formats first,
3531
+ // then general purpose rule
3532
+ g.start = function (s) {
3533
+ try {
3534
+ var r = g._formats.call({}, s);
3535
+ if (r[1].length === 0) {
3536
+ return r;
3537
+ }
3538
+ } catch (e) {}
3539
+ return g._start.call({}, s);
3540
+ };
3541
+ }());
3542
+ (function () {
3543
+ var $D = Date;
3544
+
3545
+ /**
3546
+ * @desc Converts the specified string value into its JavaScript Date equivalent using CultureInfo specific format information.
3547
+ *
3548
+ * Example
3549
+ <pre><code>
3550
+ ///////////
3551
+ // Dates //
3552
+ ///////////
3553
+
3554
+ // 15-Oct-2004
3555
+ var d1 = Date.parse("10/15/2004");
3556
+
3557
+ // 15-Oct-2004
3558
+ var d1 = Date.parse("15-Oct-2004");
3559
+
3560
+ // 15-Oct-2004
3561
+ var d1 = Date.parse("2004.10.15");
3562
+
3563
+ //Fri Oct 15, 2004
3564
+ var d1 = Date.parse("Fri Oct 15, 2004");
3565
+
3566
+ ///////////
3567
+ // Times //
3568
+ ///////////
3569
+
3570
+ // Today at 10 PM.
3571
+ var d1 = Date.parse("10 PM");
3572
+
3573
+ // Today at 10:30 PM.
3574
+ var d1 = Date.parse("10:30 P.M.");
3575
+
3576
+ // Today at 6 AM.
3577
+ var d1 = Date.parse("06am");
3578
+
3579
+ /////////////////////
3580
+ // Dates and Times //
3581
+ /////////////////////
3582
+
3583
+ // 8-July-2004 @ 10:30 PM
3584
+ var d1 = Date.parse("July 8th, 2004, 10:30 PM");
3585
+
3586
+ // 1-July-2004 @ 10:30 PM
3587
+ var d1 = Date.parse("2004-07-01T22:30:00");
3588
+
3589
+ ////////////////////
3590
+ // Relative Dates //
3591
+ ////////////////////
3592
+
3593
+ // Returns today's date. The string "today" is culture specific.
3594
+ var d1 = Date.parse("today");
3595
+
3596
+ // Returns yesterday's date. The string "yesterday" is culture specific.
3597
+ var d1 = Date.parse("yesterday");
3598
+
3599
+ // Returns the date of the next thursday.
3600
+ var d1 = Date.parse("Next thursday");
3601
+
3602
+ // Returns the date of the most previous monday.
3603
+ var d1 = Date.parse("last monday");
3604
+
3605
+ // Returns today's day + one year.
3606
+ var d1 = Date.parse("next year");
3607
+
3608
+ ///////////////
3609
+ // Date Math //
3610
+ ///////////////
3611
+
3612
+ // Today + 2 days
3613
+ var d1 = Date.parse("t+2");
3614
+
3615
+ // Today + 2 days
3616
+ var d1 = Date.parse("today + 2 days");
3617
+
3618
+ // Today + 3 months
3619
+ var d1 = Date.parse("t+3m");
3620
+
3621
+ // Today - 1 year
3622
+ var d1 = Date.parse("today - 1 year");
3623
+
3624
+ // Today - 1 year
3625
+ var d1 = Date.parse("t-1y");
3626
+
3627
+
3628
+ /////////////////////////////
3629
+ // Partial Dates and Times //
3630
+ /////////////////////////////
3631
+
3632
+ // July 15th of this year.
3633
+ var d1 = Date.parse("July 15");
3634
+
3635
+ // 15th day of current day and year.
3636
+ var d1 = Date.parse("15");
3637
+
3638
+ // July 1st of current year at 10pm.
3639
+ var d1 = Date.parse("7/1 10pm");
3640
+ </code></pre>
3641
+ *
3642
+ * @param {String} The string value to convert into a Date object [Required]
3643
+ * @return {Date} A Date object or null if the string cannot be converted into a Date.
3644
+ */
3645
+ var parseUtils = {
3646
+ removeOrds: function (s) {
3647
+ ords = s.match(/\b(\d+)(?:st|nd|rd|th)\b/); // find ordinal matches
3648
+ s = ((ords && ords.length === 2) ? s.replace(ords[0], ords[1]) : s);
3649
+ return s;
3650
+ },
3651
+ grammarParser: function (s) {
3652
+ var r = null;
3653
+ try {
3654
+ r = $D.Grammar.start.call({}, s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
3655
+ } catch (e) {
3656
+ return null;
3657
+ }
3658
+
3659
+ return ((r[1].length === 0) ? r[0] : null);
3660
+ },
3661
+ nativeFallback: function(s) {
3662
+ var t;
3663
+ try {
3664
+ // ok we haven't parsed it, last ditch attempt with the built-in parser.
3665
+ t = Date._parse(s);
3666
+ return (t || t === 0) ? new Date(t) : null;
3667
+ } catch (e) {
3668
+ return null;
3669
+ }
3670
+ }
3671
+ };
3672
+ function parse (s) {
3673
+ var d;
3674
+ if (!s) {
3675
+ return null;
3676
+ }
3677
+ if (s instanceof Date) {
3678
+ return s.clone();
3679
+ }
3680
+ if (s.length >= 4 && s.charAt(0) !== "0" && s.charAt(0) !== "+"&& s.charAt(0) !== "-") { // ie: 2004 will pass, 0800 won't.
3681
+ // Start with specific formats
3682
+ d = $D.Parsing.ISO.parse(s) || $D.Parsing.Numeric.parse(s);
3683
+ }
3684
+ if (d instanceof Date && !isNaN(d.getTime())) {
3685
+ return d;
3686
+ } else {
3687
+ // find ordinal dates (1st, 3rd, 8th, etc and remove them as they cause parsing issues)
3688
+ s = $D.Parsing.Normalizer.parse(parseUtils.removeOrds(s));
3689
+ d = parseUtils.grammarParser(s);
3690
+ if (d !== null) {
3691
+ return d;
3692
+ } else {
3693
+ return parseUtils.nativeFallback(s);
3694
+ }
3695
+ }
3696
+ }
3697
+
3698
+ if (!$D._parse) {
3699
+ $D._parse = $D.parse;
3700
+ }
3701
+ $D.parse = parse;
3702
+
3703
+ Date.getParseFunction = function (fx) {
3704
+ var fns = Date.Grammar.allformats(fx);
3705
+ return function (s) {
3706
+ var r = null;
3707
+ for (var i = 0; i < fns.length; i++) {
3708
+ try {
3709
+ r = fns[i].call({}, s);
3710
+ } catch (e) {
3711
+ continue;
3712
+ }
3713
+ if (r[1].length === 0) {
3714
+ return r[0];
3715
+ }
3716
+ }
3717
+ return null;
3718
+ };
3719
+ };
3720
+
3721
+ /**
3722
+ * Converts the specified string value into its JavaScript Date equivalent using the specified format {String} or formats {Array} and the CultureInfo specific format information.
3723
+ * The format of the string value must match one of the supplied formats exactly.
3724
+ *
3725
+ * Example
3726
+ <pre><code>
3727
+ // 15-Oct-2004
3728
+ var d1 = Date.parseExact("10/15/2004", "M/d/yyyy");
3729
+
3730
+ // 15-Oct-2004
3731
+ var d1 = Date.parse("15-Oct-2004", "M-ddd-yyyy");
3732
+
3733
+ // 15-Oct-2004
3734
+ var d1 = Date.parse("2004.10.15", "yyyy.MM.dd");
3735
+
3736
+ // Multiple formats
3737
+ var d1 = Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]);
3738
+ </code></pre>
3739
+ *
3740
+ * @param {String} The string value to convert into a Date object [Required].
3741
+ * @param {Object} The expected format {String} or an array of expected formats {Array} of the date string [Required].
3742
+ * @return {Date} A Date object or null if the string cannot be converted into a Date.
3743
+ */
3744
+ $D.parseExact = function (s, fx) {
3745
+ return $D.getParseFunction(fx)(s);
3746
+ };
3747
+ }());
3748
+
3749
+ (function () {
3750
+ var $D = Date,
3751
+ $P = $D.prototype,
3752
+ // $C = $D.CultureInfo, // not used atm
3753
+ p = function (s, l) {
3754
+ if (!l) {
3755
+ l = 2;
3756
+ }
3757
+ return ("000" + s).slice(l * -1);
3758
+ };
3759
+ /**
3760
+ * Converts a PHP format string to Java/.NET format string.
3761
+ * A PHP format string can be used with ._format or .format.
3762
+ * A Java/.NET format string can be used with .toString().
3763
+ * The .parseExact function will only accept a Java/.NET format string
3764
+ *
3765
+ * Example
3766
+ * var f1 = "%m/%d/%y"
3767
+ * var f2 = Date.normalizeFormat(f1); // "MM/dd/yy"
3768
+ *
3769
+ * new Date().format(f1); // "04/13/08"
3770
+ * new Date()._format(f1); // "04/13/08"
3771
+ * new Date().toString(f2); // "04/13/08"
3772
+ *
3773
+ * var date = Date.parseExact("04/13/08", f2); // Sun Apr 13 2008
3774
+ *
3775
+ * @param {String} A PHP format string consisting of one or more format spcifiers.
3776
+ * @return {String} The PHP format converted to a Java/.NET format string.
3777
+ */
3778
+ var normalizerSubstitutions = {
3779
+ "d" : "dd",
3780
+ "%d": "dd",
3781
+ "D" : "ddd",
3782
+ "%a": "ddd",
3783
+ "j" : "dddd",
3784
+ "l" : "dddd",
3785
+ "%A": "dddd",
3786
+ "S" : "S",
3787
+ "F" : "MMMM",
3788
+ "%B": "MMMM",
3789
+ "m" : "MM",
3790
+ "%m": "MM",
3791
+ "M" : "MMM",
3792
+ "%b": "MMM",
3793
+ "%h": "MMM",
3794
+ "n" : "M",
3795
+ "Y" : "yyyy",
3796
+ "%Y": "yyyy",
3797
+ "y" : "yy",
3798
+ "%y": "yy",
3799
+ "g" : "h",
3800
+ "%I": "h",
3801
+ "G" : "H",
3802
+ "h" : "hh",
3803
+ "H" : "HH",
3804
+ "%H": "HH",
3805
+ "i" : "mm",
3806
+ "%M": "mm",
3807
+ "s" : "ss",
3808
+ "%S": "ss",
3809
+ "%r": "hh:mm tt",
3810
+ "%R": "H:mm",
3811
+ "%T": "H:mm:ss",
3812
+ "%X": "t",
3813
+ "%x": "d",
3814
+ "%e": "d",
3815
+ "%D": "MM/dd/yy",
3816
+ "%n": "\\n",
3817
+ "%t": "\\t",
3818
+ "e" : "z",
3819
+ "T" : "z",
3820
+ "%z": "z",
3821
+ "%Z": "z",
3822
+ "Z" : "ZZ",
3823
+ "N" : "u",
3824
+ "w" : "u",
3825
+ "%w": "u",
3826
+ "W" : "W",
3827
+ "%V": "W"
3828
+ };
3829
+ var normalizer = {
3830
+ substitutes: function (m) {
3831
+ return normalizerSubstitutions[m];
3832
+ },
3833
+ interpreted: function (m, x) {
3834
+ var y;
3835
+ switch (m) {
3836
+ case "%u":
3837
+ return x.getDay() + 1;
3838
+ case "z":
3839
+ return x.getOrdinalNumber();
3840
+ case "%j":
3841
+ return p(x.getOrdinalNumber(), 3);
3842
+ case "%U":
3843
+ var d1 = x.clone().set({month: 0, day: 1}).addDays(-1).moveToDayOfWeek(0),
3844
+ d2 = x.clone().addDays(1).moveToDayOfWeek(0, -1);
3845
+ return (d2 < d1) ? "00" : p((d2.getOrdinalNumber() - d1.getOrdinalNumber()) / 7 + 1);
3846
+
3847
+ case "%W":
3848
+ return p(x.getWeek());
3849
+ case "t":
3850
+ return $D.getDaysInMonth(x.getFullYear(), x.getMonth());
3851
+ case "o":
3852
+ case "%G":
3853
+ return x.setWeek(x.getISOWeek()).toString("yyyy");
3854
+ case "%g":
3855
+ return x._format("%G").slice(-2);
3856
+ case "a":
3857
+ case "%p":
3858
+ return t("tt").toLowerCase();
3859
+ case "A":
3860
+ return t("tt").toUpperCase();
3861
+ case "u":
3862
+ return p(x.getMilliseconds(), 3);
3863
+ case "I":
3864
+ return (x.isDaylightSavingTime()) ? 1 : 0;
3865
+ case "O":
3866
+ return x.getUTCOffset();
3867
+ case "P":
3868
+ y = x.getUTCOffset();
3869
+ return y.substring(0, y.length - 2) + ":" + y.substring(y.length - 2);
3870
+ case "B":
3871
+ var now = new Date();
3872
+ return Math.floor(((now.getHours() * 3600) + (now.getMinutes() * 60) + now.getSeconds() + (now.getTimezoneOffset() + 60) * 60) / 86.4);
3873
+ case "c":
3874
+ return x.toISOString().replace(/\"/g, "");
3875
+ case "U":
3876
+ return $D.strtotime("now");
3877
+ case "%c":
3878
+ return t("d") + " " + t("t");
3879
+ case "%C":
3880
+ return Math.floor(x.getFullYear() / 100 + 1);
3881
+ }
3882
+ },
3883
+ shouldOverrideDefaults: function (m) {
3884
+ switch (m) {
3885
+ case "%e":
3886
+ return true;
3887
+ default:
3888
+ return false;
3889
+ }
3890
+ },
3891
+ parse: function (m, context) {
3892
+ var formatString, c = context || new Date();
3893
+ formatString = normalizer.substitutes(m);
3894
+ if (formatString) {
3895
+ return formatString;
3896
+ }
3897
+ formatString = normalizer.interpreted(m, c);
3898
+
3899
+ if (formatString) {
3900
+ return formatString;
3901
+ } else {
3902
+ return m;
3903
+ }
3904
+ }
3905
+ };
3906
+
3907
+ $D.normalizeFormat = function (format, context) {
3908
+ return format.replace(/(%|\\)?.|%%/g, function(t){
3909
+ return normalizer.parse(t, context);
3910
+ });
3911
+ };
3912
+ /**
3913
+ * Format a local Unix timestamp according to locale settings
3914
+ *
3915
+ * Example:
3916
+ * Date.strftime("%m/%d/%y", new Date()); // "04/13/08"
3917
+ * Date.strftime("c", "2008-04-13T17:52:03Z"); // "04/13/08"
3918
+ *
3919
+ * @param {String} A format string consisting of one or more format spcifiers [Optional].
3920
+ * @param {Number|String} The number representing the number of seconds that have elapsed since January 1, 1970 (local time).
3921
+ * @return {String} A string representation of the current Date object.
3922
+ */
3923
+ $D.strftime = function (format, time) {
3924
+ var d = Date.parse(time);
3925
+ return d._format(format);
3926
+ };
3927
+ /**
3928
+ * Parse any textual datetime description into a Unix timestamp.
3929
+ * A Unix timestamp is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT).
3930
+ *
3931
+ * Example:
3932
+ * Date.strtotime("04/13/08"); // 1208044800
3933
+ * Date.strtotime("1970-01-01T00:00:00Z"); // 0
3934
+ *
3935
+ * @param {String} A format string consisting of one or more format spcifiers [Optional].
3936
+ * @param {Object} A string or date object.
3937
+ * @return {String} A string representation of the current Date object.
3938
+ */
3939
+ $D.strtotime = function (time) {
3940
+ var d = $D.parse(time);
3941
+ return Math.round($D.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()) / 1000);
3942
+ };
3943
+ /**
3944
+ * Converts the value of the current Date object to its equivalent string representation using a PHP/Unix style of date format specifiers.
3945
+ * Format Specifiers
3946
+ * Format Description Example
3947
+ * ------ --------------------------------------------------------------------------- -----------------------
3948
+ * %a abbreviated weekday name according to the current localed "Mon" through "Sun"
3949
+ * %A full weekday name according to the current localed "Sunday" through "Saturday"
3950
+ * %b abbreviated month name according to the current localed "Jan" through "Dec"
3951
+ * %B full month name according to the current locale "January" through "December"
3952
+ * %c preferred date and time representation for the current locale "4/13/2008 12:33 PM"
3953
+ * %C century number (the year divided by 100 and truncated to an integer) "00" to "99"
3954
+ * %d day of the month as a decimal number "01" to "31"
3955
+ * %D same as %m/%d/%y "04/13/08"
3956
+ * %e day of the month as a decimal number, a single digit is preceded by a space "1" to "31"
3957
+ * %g like %G, but without the century "08"
3958
+ * %G The 4-digit year corresponding to the ISO week number (see %V). "2008"
3959
+ * This has the same format and value as %Y, except that if the ISO week number
3960
+ * belongs to the previous or next year, that year is used instead.
3961
+ * %h same as %b "Jan" through "Dec"
3962
+ * %H hour as a decimal number using a 24-hour clock. "00" to "23"
3963
+ * %I hour as a decimal number using a 12-hour clock. "01" to "12"
3964
+ * %j day of the year as a decimal number. "001" to "366"
3965
+ * %m month as a decimal number. "01" to "12"
3966
+ * %M minute as a decimal number. "00" to "59"
3967
+ * %n newline character "\n"
3968
+ * %p either "am" or "pm" according to the given time value, or the "am" or "pm"
3969
+ * corresponding strings for the current locale.
3970
+ * %r time in a.m. and p.m. notation "8:44 PM"
3971
+ * %R time in 24 hour notation "20:44"
3972
+ * %S second as a decimal number "00" to "59"
3973
+ * %t tab character "\t"
3974
+ * %T current time, equal to %H:%M:%S "12:49:11"
3975
+ * %u weekday as a decimal number ["1", "7"], with "1" representing Monday "1" to "7"
3976
+ * %U week number of the current year as a decimal number, starting with the "0" to ("52" or "53")
3977
+ * first Sunday as the first day of the first week
3978
+ * %V The ISO 8601:1988 week number of the current year as a decimal number, "00" to ("52" or "53")
3979
+ * range 01 to 53, where week 1 is the first week that has at least 4 days
3980
+ * in the current year, and with Monday as the first day of the week.
3981
+ * (Use %G or %g for the year component that corresponds to the week number
3982
+ * for the specified timestamp.)
3983
+ * %W week number of the current year as a decimal number, starting with the "00" to ("52" or "53")
3984
+ * first Monday as the first day of the first week
3985
+ * %w day of the week as a decimal, Sunday being "0" "0" to "6"
3986
+ * %x preferred date representation for the current locale without the time "4/13/2008"
3987
+ * %X preferred time representation for the current locale without the date "12:53:05"
3988
+ * %y year as a decimal number without a century "00" "99"
3989
+ * %Y year as a decimal number including the century "2008"
3990
+ * %Z time zone or name or abbreviation "UTC", "EST", "PST"
3991
+ * %z same as %Z
3992
+ * %% a literal "%" characters "%"
3993
+ * d Day of the month, 2 digits with leading zeros "01" to "31"
3994
+ * D A textual representation of a day, three letters "Mon" through "Sun"
3995
+ * j Day of the month without leading zeros "1" to "31"
3996
+ * l A full textual representation of the day of the week (lowercase "L") "Sunday" through "Saturday"
3997
+ * N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) "1" (for Monday) through "7" (for Sunday)
3998
+ * S English ordinal suffix for the day of the month, 2 characters "st", "nd", "rd" or "th". Works well with j
3999
+ * w Numeric representation of the day of the week "0" (for Sunday) through "6" (for Saturday)
4000
+ * z The day of the year (starting from "0") "0" through "365"
4001
+ * W ISO-8601 week number of year, weeks starting on Monday "00" to ("52" or "53")
4002
+ * F A full textual representation of a month, such as January or March "January" through "December"
4003
+ * m Numeric representation of a month, with leading zeros "01" through "12"
4004
+ * M A short textual representation of a month, three letters "Jan" through "Dec"
4005
+ * n Numeric representation of a month, without leading zeros "1" through "12"
4006
+ * t Number of days in the given month "28" through "31"
4007
+ * L Whether it's a leap year "1" if it is a leap year, "0" otherwise
4008
+ * o ISO-8601 year number. This has the same value as Y, except that if the "2008"
4009
+ * ISO week number (W) belongs to the previous or next year, that year
4010
+ * is used instead.
4011
+ * Y A full numeric representation of a year, 4 digits "2008"
4012
+ * y A two digit representation of a year "08"
4013
+ * a Lowercase Ante meridiem and Post meridiem "am" or "pm"
4014
+ * A Uppercase Ante meridiem and Post meridiem "AM" or "PM"
4015
+ * B Swatch Internet time "000" through "999"
4016
+ * g 12-hour format of an hour without leading zeros "1" through "12"
4017
+ * G 24-hour format of an hour without leading zeros "0" through "23"
4018
+ * h 12-hour format of an hour with leading zeros "01" through "12"
4019
+ * H 24-hour format of an hour with leading zeros "00" through "23"
4020
+ * i Minutes with leading zeros "00" to "59"
4021
+ * s Seconds, with leading zeros "00" through "59"
4022
+ * u Milliseconds "54321"
4023
+ * e Timezone identifier "UTC", "EST", "PST"
4024
+ * I Whether or not the date is in daylight saving time (uppercase i) "1" if Daylight Saving Time, "0" otherwise
4025
+ * O Difference to Greenwich time (GMT) in hours "+0200", "-0600"
4026
+ * P Difference to Greenwich time (GMT) with colon between hours and minutes "+02:00", "-06:00"
4027
+ * T Timezone abbreviation "UTC", "EST", "PST"
4028
+ * Z Timezone offset in seconds. The offset for timezones west of UTC is "-43200" through "50400"
4029
+ * always negative, and for those east of UTC is always positive.
4030
+ * c ISO 8601 date "2004-02-12T15:19:21+00:00"
4031
+ * r RFC 2822 formatted date "Thu, 21 Dec 2000 16:01:07 +0200"
4032
+ * U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) "0"
4033
+ * @param {String} A format string consisting of one or more format spcifiers [Optional].
4034
+ * @return {String} A string representation of the current Date object.
4035
+ */
4036
+ var formatReplace = function (context) {
4037
+ return function (m) {
4038
+ var formatString, override = false;
4039
+ if (m.charAt(0) === "\\" || m.substring(0, 2) === "%%") {
4040
+ return m.replace("\\", "").replace("%%", "%");
4041
+ }
4042
+
4043
+ override = normalizer.shouldOverrideDefaults(m);
4044
+ formatString = $D.normalizeFormat(m, context);
4045
+ if (formatString) {
4046
+ return context.toString(formatString, override);
4047
+ }
4048
+ };
4049
+ };
4050
+ $P._format = function (format) {
4051
+ var formatter = formatReplace(this);
4052
+ if (!format) {
4053
+ return this._toString();
4054
+ } else {
4055
+ return format.replace(/(%|\\)?.|%%/g, formatter);
4056
+ }
4057
+ };
4058
+
4059
+ if (!$P.format) {
4060
+ $P.format = $P._format;
4061
+ }
4062
+ }());
4063
+ (function () {
4064
+ "use strict";
4065
+ var gFn = function (attr) {
4066
+ return function () {
4067
+ return this[attr];
4068
+ };
4069
+ };
4070
+
4071
+ var sFn = function (attr) {
4072
+ return function (val) {
4073
+ this[attr] = val;
4074
+ return this;
4075
+ };
4076
+ };
4077
+ var attrs = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
4078
+ var addSetFuncs = function (context, attrs) {
4079
+ for (var i = 0; i < attrs.length ; i++) {
4080
+ var $a = attrs[i], $b = $a.slice(0, 1).toUpperCase() + $a.slice(1);
4081
+ context.prototype[$a] = 0;
4082
+ context.prototype["get" + $b] = gFn($a);
4083
+ context.prototype["set" + $b] = sFn($a);
4084
+ }
4085
+ };
4086
+ /**
4087
+ * new TimeSpan(milliseconds);
4088
+ * new TimeSpan(days, hours, minutes, seconds);
4089
+ * new TimeSpan(days, hours, minutes, seconds, milliseconds);
4090
+ */
4091
+ var TimeSpan = function (days, hours, minutes, seconds, milliseconds) {
4092
+ if (arguments.length === 1 && typeof days === "number") {
4093
+ var orient = (days < 0) ? -1 : +1;
4094
+ var millsLeft = Math.abs(days);
4095
+ this.setDays(Math.floor(millsLeft / 86400000) * orient);
4096
+ millsLeft = millsLeft % 86400000;
4097
+ this.setHours(Math.floor(millsLeft / 3600000) * orient);
4098
+ millsLeft = millsLeft % 3600000;
4099
+ this.setMinutes(Math.floor(millsLeft / 60000) * orient);
4100
+ millsLeft = millsLeft % 60000;
4101
+ this.setSeconds(Math.floor(millsLeft / 1000) * orient);
4102
+ millsLeft = millsLeft % 1000;
4103
+ this.setMilliseconds(millsLeft * orient);
4104
+ } else {
4105
+ this.set(days, hours, minutes, seconds, milliseconds);
4106
+ }
4107
+
4108
+ this.getTotalMilliseconds = function () {
4109
+ return (this.getDays() * 86400000) +
4110
+ (this.getHours() * 3600000) +
4111
+ (this.getMinutes() * 60000) +
4112
+ (this.getSeconds() * 1000);
4113
+ };
4114
+
4115
+ this.compareTo = function (time) {
4116
+ var t1 = new Date(1970, 1, 1, this.getHours(), this.getMinutes(), this.getSeconds()), t2;
4117
+ if (time === null) {
4118
+ t2 = new Date(1970, 1, 1, 0, 0, 0);
4119
+ }
4120
+ else {
4121
+ t2 = new Date(1970, 1, 1, time.getHours(), time.getMinutes(), time.getSeconds());
4122
+ }
4123
+ return (t1 < t2) ? -1 : (t1 > t2) ? 1 : 0;
4124
+ };
4125
+
4126
+ this.equals = function (time) {
4127
+ return (this.compareTo(time) === 0);
4128
+ };
4129
+
4130
+ this.add = function (time) {
4131
+ return (time === null) ? this : this.addSeconds(time.getTotalMilliseconds() / 1000);
4132
+ };
4133
+
4134
+ this.subtract = function (time) {
4135
+ return (time === null) ? this : this.addSeconds(-time.getTotalMilliseconds() / 1000);
4136
+ };
4137
+
4138
+ this.addDays = function (n) {
4139
+ return new TimeSpan(this.getTotalMilliseconds() + (n * 86400000));
4140
+ };
4141
+
4142
+ this.addHours = function (n) {
4143
+ return new TimeSpan(this.getTotalMilliseconds() + (n * 3600000));
4144
+ };
4145
+
4146
+ this.addMinutes = function (n) {
4147
+ return new TimeSpan(this.getTotalMilliseconds() + (n * 60000));
4148
+ };
4149
+
4150
+ this.addSeconds = function (n) {
4151
+ return new TimeSpan(this.getTotalMilliseconds() + (n * 1000));
4152
+ };
4153
+
4154
+ this.addMilliseconds = function (n) {
4155
+ return new TimeSpan(this.getTotalMilliseconds() + n);
4156
+ };
4157
+
4158
+ this.get12HourHour = function () {
4159
+ return (this.getHours() > 12) ? this.getHours() - 12 : (this.getHours() === 0) ? 12 : this.getHours();
4160
+ };
4161
+
4162
+ this.getDesignator = function () {
4163
+ return (this.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
4164
+ };
4165
+
4166
+ this.toString = function (format) {
4167
+ this._toString = function () {
4168
+ if (this.getDays() !== null && this.getDays() > 0) {
4169
+ return this.getDays() + "." + this.getHours() + ":" + this.p(this.getMinutes()) + ":" + this.p(this.getSeconds());
4170
+ } else {
4171
+ return this.getHours() + ":" + this.p(this.getMinutes()) + ":" + this.p(this.getSeconds());
4172
+ }
4173
+ };
4174
+
4175
+ this.p = function (s) {
4176
+ return (s.toString().length < 2) ? "0" + s : s;
4177
+ };
4178
+
4179
+ var me = this;
4180
+
4181
+ return format ? format.replace(/dd?|HH?|hh?|mm?|ss?|tt?/g,
4182
+ function (format) {
4183
+ switch (format) {
4184
+ case "d":
4185
+ return me.getDays();
4186
+ case "dd":
4187
+ return me.p(me.getDays());
4188
+ case "H":
4189
+ return me.getHours();
4190
+ case "HH":
4191
+ return me.p(me.getHours());
4192
+ case "h":
4193
+ return me.get12HourHour();
4194
+ case "hh":
4195
+ return me.p(me.get12HourHour());
4196
+ case "m":
4197
+ return me.getMinutes();
4198
+ case "mm":
4199
+ return me.p(me.getMinutes());
4200
+ case "s":
4201
+ return me.getSeconds();
4202
+ case "ss":
4203
+ return me.p(me.getSeconds());
4204
+ case "t":
4205
+ return ((me.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator).substring(0, 1);
4206
+ case "tt":
4207
+ return (me.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
4208
+ }
4209
+ }
4210
+ ) : this._toString();
4211
+ };
4212
+ return this;
4213
+ };
4214
+ addSetFuncs(TimeSpan, attrs.slice(2));
4215
+ TimeSpan.prototype.set = function (days, hours, minutes, seconds, milliseconds){
4216
+ this.setDays(days || this.getDays());
4217
+ this.setHours(hours || this.getHours());
4218
+ this.setMinutes(minutes || this.getMinutes());
4219
+ this.setSeconds(seconds || this.getSeconds());
4220
+ this.setMilliseconds(milliseconds || this.getMilliseconds());
4221
+ };
4222
+
4223
+
4224
+ /**
4225
+ * Gets the time of day for this date instances.
4226
+ * @return {TimeSpan} TimeSpan
4227
+ */
4228
+ Date.prototype.getTimeOfDay = function () {
4229
+ return new TimeSpan(0, this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds());
4230
+ };
4231
+
4232
+ Date.TimeSpan = TimeSpan;
4233
+
4234
+ if (typeof window !== "undefined" ) {
4235
+ // keeping API compatible for v1.x
4236
+ window.TimeSpan = TimeSpan;
4237
+ }
4238
+ }());
4239
+ (function () {
4240
+ "use strict";
4241
+ var attrs = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
4242
+ var gFn = function (attr) {
4243
+ return function () {
4244
+ return this[attr];
4245
+ };
4246
+ };
4247
+
4248
+ var sFn = function (attr) {
4249
+ return function (val) {
4250
+ this[attr] = val;
4251
+ return this;
4252
+ };
4253
+ };
4254
+ var addSetFuncs = function (context, attrs) {
4255
+ for (var i = 0; i < attrs.length ; i++) {
4256
+ var $a = attrs[i], $b = $a.slice(0, 1).toUpperCase() + $a.slice(1);
4257
+ context.prototype[$a] = 0;
4258
+ context.prototype["get" + $b] = gFn($a);
4259
+ context.prototype["set" + $b] = sFn($a);
4260
+ }
4261
+ };
4262
+
4263
+ var setMonthsAndYears = function (orient, d1, d2, context) {
4264
+ function inc() {
4265
+ d1.addMonths(-orient);
4266
+ context.months++;
4267
+ if (context.months === 12) {
4268
+ context.years++;
4269
+ context.months = 0;
4270
+ }
4271
+ }
4272
+ if (orient === +1) {
4273
+ while (d1 > d2) {
4274
+ inc();
4275
+ }
4276
+ } else {
4277
+ while (d1 < d2) {
4278
+ inc();
4279
+ }
4280
+ }
4281
+ context.months--;
4282
+ context.months *= orient;
4283
+ context.years *= orient;
4284
+ };
4285
+
4286
+ var adjustForDST = function(orient, startDate, endDate) {
4287
+ var hasDSTMismatch = (false === (startDate.isDaylightSavingTime() === endDate.isDaylightSavingTime()));
4288
+ if (hasDSTMismatch && orient === 1) {
4289
+ startDate.addHours(-1);
4290
+ } else if (hasDSTMismatch) {
4291
+ startDate.addHours(1);
4292
+ }
4293
+ };
4294
+ /**
4295
+ * TimePeriod(startDate, endDate);
4296
+ * TimePeriod(years, months, days, hours, minutes, seconds, milliseconds);
4297
+ */
4298
+ var TimePeriod = function (years, months, days, hours, minutes, seconds, milliseconds) {
4299
+ if (arguments.length === 7) {
4300
+ this.set(years, months, days, hours, minutes, seconds, milliseconds);
4301
+ } else if (arguments.length === 2 && arguments[0] instanceof Date && arguments[1] instanceof Date) {
4302
+ var startDate = arguments[0].clone();
4303
+ var endDate = arguments[1].clone();
4304
+ var orient = (startDate > endDate) ? +1 : -1;
4305
+ this.dates = {
4306
+ start: arguments[0].clone(),
4307
+ end: arguments[1].clone()
4308
+ };
4309
+
4310
+ setMonthsAndYears(orient, startDate, endDate, this);
4311
+ adjustForDST(orient, startDate, endDate);
4312
+ // // TODO - adjust for DST
4313
+ var diff = endDate - startDate;
4314
+ if (diff !== 0) {
4315
+ var ts = new TimeSpan(diff);
4316
+ this.set(this.years, this.months, ts.getDays(), ts.getHours(), ts.getMinutes(), ts.getSeconds(), ts.getMilliseconds());
4317
+ }
4318
+ }
4319
+ return this;
4320
+ };
4321
+ // create all the set functions.
4322
+ addSetFuncs(TimePeriod, attrs);
4323
+ TimePeriod.prototype.set = function (years, months, days, hours, minutes, seconds, milliseconds){
4324
+ this.setYears(years || this.getYears());
4325
+ this.setMonths(months || this.getMonths());
4326
+ this.setDays(days || this.getDays());
4327
+ this.setHours(hours || this.getHours());
4328
+ this.setMinutes(minutes || this.getMinutes());
4329
+ this.setSeconds(seconds || this.getSeconds());
4330
+ this.setMilliseconds(milliseconds || this.getMilliseconds());
4331
+ };
4332
+
4333
+ Date.TimePeriod = TimePeriod;
4334
+
4335
+ if (typeof window !== "undefined") {
4336
+ // keeping API compatible for v1.x
4337
+ window.TimePeriod = TimePeriod;
4338
+ }
4339
+ }());