@base-framework/base 2.6.1 → 2.6.2

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 (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +9 -4
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
@@ -1,525 +0,0 @@
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
- })();