@base-framework/base 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/base.min.js +1 -0
  2. package/es5/base.js +2968 -0
  3. package/es5/modules/ajax.js +663 -0
  4. package/es5/modules/animation.js +188 -0
  5. package/es5/modules/animations.js +1080 -0
  6. package/es5/modules/atom.js +65 -0
  7. package/es5/modules/component.js +1310 -0
  8. package/es5/modules/data-binder.js +1131 -0
  9. package/es5/modules/data.js +1808 -0
  10. package/es5/modules/date.js +525 -0
  11. package/es5/modules/form-validator.js +324 -0
  12. package/es5/modules/history.js +126 -0
  13. package/es5/modules/html-builder.js +461 -0
  14. package/es5/modules/layout.js +1679 -0
  15. package/es5/modules/mouse.js +124 -0
  16. package/es5/modules/nav-link.js +123 -0
  17. package/es5/modules/olderversions/animations-ease.js +1095 -0
  18. package/es5/modules/olderversions/animations-update.js +1048 -0
  19. package/es5/modules/olderversions/base-animations.js +636 -0
  20. package/es5/modules/olderversions/base-component-class.js +100 -0
  21. package/es5/modules/olderversions/base-data-binder-1.js +407 -0
  22. package/es5/modules/olderversions/base-data-binder-class.js +358 -0
  23. package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  24. package/es5/modules/olderversions/base-mode-1.js +777 -0
  25. package/es5/modules/olderversions/base-model-class.js +585 -0
  26. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  27. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  28. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  29. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  30. package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  31. package/es5/modules/olderversions/data-tracker.js +187 -0
  32. package/es5/modules/olderversions/event-update.js +666 -0
  33. package/es5/modules/olderversions/nav-link.js +119 -0
  34. package/es5/modules/olderversions/router-with-templates-1.js +785 -0
  35. package/es5/modules/olderversions/router-with-templates.js +701 -0
  36. package/es5/modules/prototypes/ajax.js +657 -0
  37. package/es5/modules/prototypes/atom.js +65 -0
  38. package/es5/modules/prototypes/component.js +972 -0
  39. package/es5/modules/prototypes/data-binder.js +1089 -0
  40. package/es5/modules/prototypes/data.js +1290 -0
  41. package/es5/modules/prototypes/html-builder.js +414 -0
  42. package/es5/modules/prototypes/layout.js +879 -0
  43. package/es5/modules/router.js +1680 -0
  44. package/es5/modules/state.js +274 -0
  45. package/es6/.jshintrc +3 -0
  46. package/es6/base.js +41 -0
  47. package/es6/core.js +1 -0
  48. package/es6/data-tracker.js +351 -0
  49. package/es6/events.js +602 -0
  50. package/es6/legacy/es5/base.js +2968 -0
  51. package/es6/legacy/es5/modules/ajax.js +663 -0
  52. package/es6/legacy/es5/modules/animation.js +188 -0
  53. package/es6/legacy/es5/modules/animations.js +1080 -0
  54. package/es6/legacy/es5/modules/atom.js +65 -0
  55. package/es6/legacy/es5/modules/component.js +1310 -0
  56. package/es6/legacy/es5/modules/data-binder.js +1131 -0
  57. package/es6/legacy/es5/modules/data.js +1808 -0
  58. package/es6/legacy/es5/modules/date.js +525 -0
  59. package/es6/legacy/es5/modules/form-validator.js +324 -0
  60. package/es6/legacy/es5/modules/history.js +126 -0
  61. package/es6/legacy/es5/modules/html-builder.js +461 -0
  62. package/es6/legacy/es5/modules/layout.js +1679 -0
  63. package/es6/legacy/es5/modules/mouse.js +124 -0
  64. package/es6/legacy/es5/modules/nav-link.js +123 -0
  65. package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  66. package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  67. package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
  68. package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  69. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  70. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  71. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  72. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  73. package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  74. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  75. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  76. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  77. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  78. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  79. package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  80. package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
  81. package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
  82. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  83. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  84. package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
  85. package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
  86. package/es6/legacy/es5/modules/prototypes/component.js +972 -0
  87. package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  88. package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
  89. package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
  90. package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
  91. package/es6/legacy/es5/modules/router.js +1680 -0
  92. package/es6/legacy/es5/modules/state.js +274 -0
  93. package/es6/main.js +1331 -0
  94. package/es6/modules/ajax/ajax.js +514 -0
  95. package/es6/modules/animation/animation.js +236 -0
  96. package/es6/modules/animations/animation-controller.js +231 -0
  97. package/es6/modules/animations/animation.js +64 -0
  98. package/es6/modules/animations/attr-movement.js +66 -0
  99. package/es6/modules/animations/css-movement.js +170 -0
  100. package/es6/modules/animations/movement.js +131 -0
  101. package/es6/modules/animations/value.js +187 -0
  102. package/es6/modules/atom/atom.js +54 -0
  103. package/es6/modules/component/component.js +230 -0
  104. package/es6/modules/component/event-helper.js +119 -0
  105. package/es6/modules/component/jot.js +144 -0
  106. package/es6/modules/component/state-helper.js +262 -0
  107. package/es6/modules/component/unit.js +551 -0
  108. package/es6/modules/data/attrs.js +40 -0
  109. package/es6/modules/data/basic-data.js +500 -0
  110. package/es6/modules/data/data-utils.js +29 -0
  111. package/es6/modules/data/data.js +3 -0
  112. package/es6/modules/data/deep-data.js +541 -0
  113. package/es6/modules/data/model-service.js +528 -0
  114. package/es6/modules/data/model.js +133 -0
  115. package/es6/modules/data/simple-data.js +33 -0
  116. package/es6/modules/data-binder/connection-tracker.js +113 -0
  117. package/es6/modules/data-binder/connection.js +16 -0
  118. package/es6/modules/data-binder/data-binder.js +352 -0
  119. package/es6/modules/data-binder/data-pub-sub.js +141 -0
  120. package/es6/modules/data-binder/data-source.js +56 -0
  121. package/es6/modules/data-binder/element-source.js +219 -0
  122. package/es6/modules/data-binder/one-way-connection.js +46 -0
  123. package/es6/modules/data-binder/one-way-source.js +43 -0
  124. package/es6/modules/data-binder/source.js +36 -0
  125. package/es6/modules/data-binder/two-way-connection.js +75 -0
  126. package/es6/modules/data-binder/two-way-source.js +41 -0
  127. package/es6/modules/date/date.js +544 -0
  128. package/es6/modules/history/history.js +89 -0
  129. package/es6/modules/html-builder/html-builder.js +434 -0
  130. package/es6/modules/import/import.js +390 -0
  131. package/es6/modules/layout/layout-builder.js +1269 -0
  132. package/es6/modules/layout/layout-parser.js +134 -0
  133. package/es6/modules/layout/watcher-helper.js +282 -0
  134. package/es6/modules/mouse/mouse.js +114 -0
  135. package/es6/modules/router/component-helper.js +163 -0
  136. package/es6/modules/router/history-controller.js +216 -0
  137. package/es6/modules/router/nav-link.js +124 -0
  138. package/es6/modules/router/route.js +401 -0
  139. package/es6/modules/router/router.js +789 -0
  140. package/es6/modules/router/utils.js +31 -0
  141. package/es6/modules/state/state-target.js +91 -0
  142. package/es6/modules/state/state.js +171 -0
  143. package/es6/package-lock.json +13 -0
  144. package/es6/package.json +28 -0
  145. package/es6/shared/objects.js +99 -0
  146. package/legacy/es5/base.js +2968 -0
  147. package/legacy/es5/modules/ajax.js +663 -0
  148. package/legacy/es5/modules/animation.js +188 -0
  149. package/legacy/es5/modules/animations.js +1080 -0
  150. package/legacy/es5/modules/atom.js +65 -0
  151. package/legacy/es5/modules/component.js +1310 -0
  152. package/legacy/es5/modules/data-binder.js +1131 -0
  153. package/legacy/es5/modules/data.js +1808 -0
  154. package/legacy/es5/modules/date.js +525 -0
  155. package/legacy/es5/modules/form-validator.js +324 -0
  156. package/legacy/es5/modules/history.js +126 -0
  157. package/legacy/es5/modules/html-builder.js +461 -0
  158. package/legacy/es5/modules/layout.js +1679 -0
  159. package/legacy/es5/modules/mouse.js +124 -0
  160. package/legacy/es5/modules/nav-link.js +123 -0
  161. package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  162. package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  163. package/legacy/es5/modules/olderversions/base-animations.js +636 -0
  164. package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  165. package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  166. package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  167. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  168. package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  169. package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  170. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  171. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  172. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  173. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  174. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  175. package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  176. package/legacy/es5/modules/olderversions/event-update.js +666 -0
  177. package/legacy/es5/modules/olderversions/nav-link.js +119 -0
  178. package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  179. package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  180. package/legacy/es5/modules/prototypes/ajax.js +657 -0
  181. package/legacy/es5/modules/prototypes/atom.js +65 -0
  182. package/legacy/es5/modules/prototypes/component.js +972 -0
  183. package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  184. package/legacy/es5/modules/prototypes/data.js +1290 -0
  185. package/legacy/es5/modules/prototypes/html-builder.js +414 -0
  186. package/legacy/es5/modules/prototypes/layout.js +879 -0
  187. package/legacy/es5/modules/router.js +1680 -0
  188. package/legacy/es5/modules/state.js +274 -0
  189. package/package.json +8 -3
  190. package/update +16 -0
@@ -0,0 +1,525 @@
1
+ /* base framework module */
2
+ /*
3
+ date and time
4
+ */
5
+ (function()
6
+ {
7
+ "use strict";
8
+
9
+ /**
10
+ * This will add date functions to the base framework.
11
+ *
12
+ */
13
+ base.extend.date = {
14
+
15
+ /**
16
+ * @member {array} monthName
17
+ */
18
+ monthNames: ["January","February","March","April","May","June","July","August","September","October","November","December"],
19
+
20
+ /**
21
+ * @member {array} dayNames
22
+ */
23
+ dayNames: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
24
+
25
+ /**
26
+ * This will get the day name.
27
+ *
28
+ * @param {int} [day]
29
+ * @param {boolean} [shortenName=false]
30
+ * @return {string}
31
+ */
32
+ getDayName: function(day, shortenName)
33
+ {
34
+ day = (typeof day !== 'undefined')? day : new Date().getDate();
35
+
36
+ var dayName = false;
37
+ var days = this.dayNames;
38
+ if(day < days.length)
39
+ {
40
+ /* we want to check to shorten name */
41
+ dayName = (shortenName)? days[day].substring(0, 3) : days[day];
42
+ }
43
+ return dayName;
44
+ },
45
+
46
+ /**
47
+ * This will convert month to js.
48
+ *
49
+ * @param {int} month
50
+ * @return {int}
51
+ */
52
+ convertJsMonth: function(month)
53
+ {
54
+ return this.padNumber(month + 1);
55
+ },
56
+
57
+ /**
58
+ * This will add leading zero to number less than 10.
59
+ *
60
+ * @param {int} number
61
+ * @return {string}
62
+ */
63
+ padNumber: function(number)
64
+ {
65
+ return (number <= 9)? '0' + number : String(number);
66
+ },
67
+
68
+ createDate: function(dateString)
69
+ {
70
+ if(typeof dateString !== 'string')
71
+ {
72
+ return new Date();
73
+ }
74
+
75
+ if(typeof dateString === 'string' && dateString.indexOf('-') > -1)
76
+ {
77
+ dateString = dateString.replace(/\s/, 'T'); //For safari
78
+ dateString = (dateString.indexOf(':') > -1)? dateString : dateString + "T00:00:00";
79
+ }
80
+ return new Date(dateString);
81
+ },
82
+
83
+ format: function(format, dateString)
84
+ {
85
+ var date = this.createDate(dateString);
86
+ switch(format)
87
+ {
88
+ case 'sql':
89
+ dateString = date.getFullYear() + '-' + this.convertJsMonth(date.getMonth()) + '-' + this.padNumber(date.getDate());
90
+ break;
91
+ default:
92
+ dateString = this.convertJsMonth(date.getMonth()) + '/' + this.padNumber(date.getDate()) + '/' + date.getFullYear();
93
+ break;
94
+
95
+ }
96
+ return dateString;
97
+ },
98
+
99
+ formatTime: function(dateString, format)
100
+ {
101
+ if(!dateString)
102
+ {
103
+ return '';
104
+ }
105
+
106
+ var date = this.createDate(dateString);
107
+
108
+ if(format === 12)
109
+ {
110
+ return date.getHours() + ':' + this.padNumber(date.getMinutes()) + '-' + this.padNumber(date.getSeconds());
111
+ }
112
+
113
+ var hours = date.getHours(),
114
+ meridian = 'AM';
115
+
116
+ if(hours > 12)
117
+ {
118
+ meridian = 'PM';
119
+ hours = hours - 12;
120
+ }
121
+ return (hours + ':' + this.padNumber(date.getMinutes()) + ' ' + meridian);
122
+ },
123
+
124
+ /**
125
+ * This will check for leap year.
126
+ *
127
+ * @param {int} year
128
+ * @return {boolean}
129
+ */
130
+ leapYear: function(year)
131
+ {
132
+ var leapYear = false;
133
+
134
+ if((year % 400 === 0) || (year % 100 !== 0 && year % 4 === 0))
135
+ {
136
+ leapYear = true;
137
+ }
138
+ return leapYear;
139
+ },
140
+
141
+ /**
142
+ * This will get a month name.
143
+ *
144
+ * @param {int} [month]
145
+ * @param {boolean} [shortenName]
146
+ * @return {string}
147
+ */
148
+ getMonthName: function(month, shortenName)
149
+ {
150
+ month = (typeof month !== 'undefined')? month : new Date().getMonth();
151
+
152
+ var monthName = false;
153
+ var months = this.monthNames;
154
+ if(month < months.length)
155
+ {
156
+ /* we want to check to shorten name */
157
+ monthName = (shortenName)? months[month].substring(0, 3) : months[month];
158
+ }
159
+ return monthName;
160
+ },
161
+
162
+ /**
163
+ * This will return the month length.
164
+ *
165
+ * @param {int} [month]
166
+ * @param {int} [year]
167
+ * @return {int}
168
+ */
169
+ getMonthLength: function(month, year)
170
+ {
171
+ /* we want to check to use params or use
172
+ default */
173
+ var date = new Date();
174
+ month = (typeof month !== 'undefined')? month : date.getMonth();
175
+ year = (typeof year !== 'undefined')? year : date.getFullYear();
176
+
177
+ /* we need to get the month lengths for
178
+ the year */
179
+ var yearMonthLengths = this.getMonthsLength(year);
180
+
181
+ /* we can select the month length from
182
+ the yearMonthLengths array */
183
+ var monthLength = yearMonthLengths[month];
184
+ return monthLength;
185
+ },
186
+
187
+ /**
188
+ * This will get the length of all the months.
189
+ *
190
+ * @param {int} year
191
+ * @return {array}
192
+ */
193
+ getMonthsLength: function(year)
194
+ {
195
+ year = (typeof year !== 'undefined')? year : new Date().getFullYear();
196
+
197
+ /* we needto check if the year is a leap year */
198
+ var isLeapYear = this.leapYear(year);
199
+ var days = (isLeapYear === true)?
200
+ [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
201
+ :
202
+ [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
203
+
204
+ return days;
205
+ },
206
+
207
+ /**
208
+ * This will get the milliseconds from a date until now.
209
+ *
210
+ * @param {string} date
211
+ * @return {int}
212
+ */
213
+ getDiffFromNow: function(date)
214
+ {
215
+ date = date.replace(/\s/, 'T') //For safari
216
+ date = new Date(date);
217
+
218
+ var now = new Date(),
219
+ timeDiff = now.getTime() - date.getTime();
220
+ return timeDiff;
221
+ },
222
+
223
+ /**
224
+ * This will get the age from a date until now.
225
+ *
226
+ * @param {string} date
227
+ * @return {(string|int)}
228
+ */
229
+ getAge: function(date)
230
+ {
231
+ var milliseconds = this.getDiffFromNow(date);
232
+
233
+ var age = '';
234
+ switch(true)
235
+ {
236
+ case milliseconds < 86400000:
237
+ age = '1 day';
238
+ break;
239
+ case milliseconds < 604800000:
240
+ var days = this.toDays(milliseconds);
241
+ age = (days) + ' days';
242
+ break;
243
+ case milliseconds < 1209600000:
244
+ age = '1 week';
245
+ break;
246
+ case milliseconds < 2592000000:
247
+ var days = this.toDays(milliseconds),
248
+ weeks = Math.floor(days / 7);
249
+ age = weeks + ' weeks';
250
+ break;
251
+ case milliseconds < 5184000000:
252
+ age = '1 month';
253
+ break;
254
+ case milliseconds < 31104000000:
255
+ var months = this.toMonths(milliseconds);
256
+ age = months + ' months';
257
+ break;
258
+ default:
259
+ var years = this.toYears(milliseconds);
260
+ age = years;
261
+ }
262
+
263
+ return age;
264
+ },
265
+
266
+ /**
267
+ * This will get the timeframe for a date.
268
+ *
269
+ * @param {string} date
270
+ * @return {string}
271
+ */
272
+ getTimeFrame: function(date)
273
+ {
274
+ var timeDiff = this.getDiffFromNow(date);
275
+ return this.convertToEstimate(timeDiff);
276
+ },
277
+
278
+ /**
279
+ * This will get the timeframe from milliseconds.
280
+ *
281
+ * @param {int} milliseconds
282
+ * @return {string}
283
+ */
284
+ convertToEstimate: function(milliseconds)
285
+ {
286
+ var timeFrame = '';
287
+
288
+ if(milliseconds <= 0)
289
+ {
290
+ switch(true)
291
+ {
292
+ case milliseconds < -63072000000:
293
+ var years = this.toYears(Math.abs(milliseconds));
294
+ timeFrame = 'in ' + years + ' years';
295
+ break;
296
+ case milliseconds < -31536000000:
297
+ timeFrame = 'in a year';
298
+ break;
299
+ case milliseconds < -5184000000:
300
+ var months = this.toMonths(Math.abs(milliseconds));
301
+ timeFrame = 'in ' + months + ' months';
302
+ break;
303
+ case milliseconds < -2592000000:
304
+ timeFrame = 'in a month';
305
+ break;
306
+ case milliseconds < -1209600000:
307
+ var days = this.toDays(Math.abs(milliseconds)),
308
+ weeks = Math.floor(days / 7);
309
+ timeFrame = 'in ' + weeks + ' weeks';
310
+ break;
311
+ case milliseconds < -604800000:
312
+ timeFrame = 'in a week';
313
+ break;
314
+ case milliseconds < -172800000:
315
+ var days = this.toDays(Math.abs(milliseconds));
316
+ timeFrame = 'in ' + (days) + ' days';
317
+ break;
318
+ case milliseconds < -86400000:
319
+ timeFrame = 'in a day';
320
+ break;
321
+ case milliseconds < -7200000:
322
+ var hours = this.toHours(Math.abs(milliseconds));
323
+ timeFrame = 'in ' + hours + ' hours';
324
+ break;
325
+ case milliseconds <= -3600000:
326
+ timeFrame = 'in an hour';
327
+ break;
328
+ case milliseconds < -120000:
329
+ var minutes = this.toMinutes(Math.abs(milliseconds));
330
+ timeFrame = 'in ' + minutes + ' minutes';
331
+ break;
332
+ case milliseconds < -60000:
333
+ timeFrame = 'in a minute';
334
+ break;
335
+ case milliseconds < -2000:
336
+ var seconds = this.toSeconds(Math.abs(milliseconds));
337
+ timeFrame = 'in ' + seconds + ' seconds';
338
+ break;
339
+ case milliseconds < -1:
340
+ timeFrame = 'in 1 second';
341
+ break;
342
+ default:
343
+ timeFrame = 'now';
344
+ }
345
+ }
346
+ else
347
+ {
348
+ switch(true)
349
+ {
350
+ case milliseconds < 1000:
351
+ timeFrame = '1 second ago';
352
+ break;
353
+ case milliseconds < 60000:
354
+ var seconds = this.toSeconds(milliseconds);
355
+ timeFrame = seconds + ' seconds ago';
356
+ break;
357
+ case milliseconds < 120000:
358
+ timeFrame = '1 minute ago';
359
+ break;
360
+ case milliseconds < 3600000:
361
+ var minutes = this.toMinutes(milliseconds);
362
+ timeFrame = minutes + ' minutes ago';
363
+ break;
364
+ case milliseconds < 7200000:
365
+ timeFrame = '1 hour ago';
366
+ break;
367
+ case milliseconds < 86400000:
368
+ var hours = this.toHours(milliseconds);
369
+ timeFrame = hours + ' hours ago';
370
+ break;
371
+ case milliseconds < 172800000:
372
+ timeFrame = 'yesterday';
373
+ break;
374
+ case milliseconds < 604800000:
375
+ var days = this.toDays(milliseconds);
376
+ timeFrame = (days) + ' days ago';
377
+ break;
378
+ case milliseconds < 1209600000:
379
+ timeFrame = 'a week ago';
380
+ break;
381
+ case milliseconds < 2592000000:
382
+ var days = this.toDays(milliseconds),
383
+ weeks = Math.floor(days / 7);
384
+ timeFrame = weeks + ' weeks ago';
385
+ break;
386
+ case milliseconds < 5184000000:
387
+ timeFrame = 'a month ago';
388
+ break;
389
+ case milliseconds < 31536000000:
390
+ var months = this.toMonths(milliseconds);
391
+ timeFrame = months + ' months ago';
392
+ break;
393
+ case milliseconds < 63072000000:
394
+ timeFrame = 'a year ago';
395
+ break;
396
+ default:
397
+ var years = this.toYears(milliseconds);
398
+ timeFrame = years + ' years ago';
399
+ }
400
+ }
401
+
402
+ return timeFrame;
403
+ },
404
+
405
+ /**
406
+ * This will convert to years.
407
+ *
408
+ * @param {int} milliseconds
409
+ * @return {int}
410
+ */
411
+ toYears: function(milliseconds)
412
+ {
413
+ if(typeof milliseconds !== 'number')
414
+ {
415
+ return false;
416
+ }
417
+
418
+ return Math.floor(milliseconds / (1000 * 60 * 60 * 24 * 365.26));
419
+ },
420
+
421
+ /**
422
+ * This will convert to months.
423
+ *
424
+ * @param {int} milliseconds
425
+ * @return {int}
426
+ */
427
+ toMonths: function(milliseconds)
428
+ {
429
+ if(typeof milliseconds === 'number')
430
+ {
431
+ return Math.floor(milliseconds / (1000 * 60 * 60 * 24 * 30));
432
+ }
433
+ return false;
434
+ },
435
+
436
+ /**
437
+ * This will convert to days.
438
+ *
439
+ * @param {int} milliseconds
440
+ * @return {int}
441
+ */
442
+ toDays: function(milliseconds)
443
+ {
444
+ if(typeof milliseconds !== 'number')
445
+ {
446
+ return false;
447
+ }
448
+
449
+ return Math.floor(milliseconds / (60 * 60 * 1000 * 24) * 1);
450
+ },
451
+
452
+ /**
453
+ * This will convert to hours.
454
+ *
455
+ * @param {int} milliseconds
456
+ * @return {int}
457
+ */
458
+ toHours: function(milliseconds)
459
+ {
460
+ if(typeof milliseconds !== 'number')
461
+ {
462
+ return false;
463
+ }
464
+
465
+ return Math.floor((milliseconds % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
466
+ },
467
+
468
+ /**
469
+ * This will convert to minutes.
470
+ *
471
+ * @param {int} milliseconds
472
+ * @return {int}
473
+ */
474
+ toMinutes: function(milliseconds)
475
+ {
476
+ if(typeof milliseconds !== 'number')
477
+ {
478
+ return false;
479
+ }
480
+
481
+ return Math.floor(((milliseconds % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
482
+ },
483
+
484
+ /**
485
+ * This will convert to seconds.
486
+ *
487
+ * @param {int} milliseconds
488
+ * @return {int}
489
+ */
490
+ toSeconds: function(milliseconds)
491
+ {
492
+ if(typeof milliseconds !== 'number')
493
+ {
494
+ return false;
495
+ }
496
+
497
+ return Math.floor((((milliseconds % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
498
+ },
499
+
500
+ /**
501
+ * This will get the difference between two dates.
502
+ *
503
+ * @param {string} startDate
504
+ * @param {string} endDate
505
+ * @return {object}
506
+ */
507
+ getDifference: function(startDate, endDate)
508
+ {
509
+ /* we want to convert the dates to objects */
510
+ var start = new Date(startDate),
511
+ end = new Date(endDate);
512
+
513
+ /* we want to subtract the start time from the end */
514
+ var difference = (end.getTime() - start.getTime());
515
+
516
+ return {
517
+ years: this.toYears(difference),
518
+ days: this.toDays(difference),
519
+ hours: this.toHours(difference),
520
+ minutes: this.toMinutes(difference),
521
+ seconds: this.toSeconds(difference)
522
+ };
523
+ }
524
+ };
525
+ })();