corebasic 1.0.165 → 1.0.166
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.
- package/libs/utils.js +26 -0
- package/package.json +1 -1
package/libs/utils.js
CHANGED
|
@@ -167,6 +167,32 @@ export function sum(array) { // Eg: sum([10,20,undefined, NaN, 40])
|
|
|
167
167
|
return res;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
export function validityToMillisecs(start, validity) { // start is in ms
|
|
171
|
+
const now = new Date(start)
|
|
172
|
+
|
|
173
|
+
let count = parseIntValue(validity.split(' ')[0])
|
|
174
|
+
let period = validity.split(' ')[1].toLowerCase()
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
const timeline = {
|
|
178
|
+
year: _ => now.setYear(now.getFullYear() + count),
|
|
179
|
+
years: _ => now.setYear(now.getFullYear() + count),
|
|
180
|
+
month: _ => now.setMonth(now.getMonth() + count),
|
|
181
|
+
months: _ => now.setMonth(now.getMonth() + count),
|
|
182
|
+
day: _ => now.setDate(now.getDate() + count),
|
|
183
|
+
days: _ => now.setDate(now.getDate() + count),
|
|
184
|
+
week: _ => now.setDate(now.getDate() + (count * 7)),
|
|
185
|
+
weeks: _ => now.setDate(now.getDate() + (count * 7)),
|
|
186
|
+
hour: _ => now.setHours(now.getHours() + count),
|
|
187
|
+
hours: _ => now.setHours(now.getHours() + count),
|
|
188
|
+
minute: _ => now.setMinutes(now.getMinutes() + count),
|
|
189
|
+
minutes: _ => now.setMinutes(now.getMinutes() + count),
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
timeline[period]()
|
|
193
|
+
|
|
194
|
+
return now.getTime()
|
|
195
|
+
}
|
|
170
196
|
|
|
171
197
|
// ----------------
|
|
172
198
|
// JSON
|