2022-03-17 12:54:49 +01:00
|
|
|
import {IList} from "./interfaces/IList";
|
|
|
|
|
|
|
|
const isAllLoadedLocally = function(pages: IList[]) {
|
|
|
|
for (const i in pages) {
|
|
|
|
const page = pages[i];
|
|
|
|
if (localStorage.getItem(page.id + "title") === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-21 16:53:22 +01:00
|
|
|
/** CALENDAR **/
|
|
|
|
// returns a new date shifted a certain number of days (can be negative)
|
|
|
|
const shiftDate = function(date, numDays) {
|
|
|
|
const newDate = new Date(date);
|
|
|
|
newDate.setDate(newDate.getDate() + numDays);
|
|
|
|
return newDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
const getBeginningTimeForDate = function(date: Date): Date {
|
|
|
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
|
|
}
|
|
|
|
|
|
|
|
// obj can be a parseable string, a millisecond timestamp, or a Date object
|
|
|
|
const convertToDate = function(obj): Date {
|
|
|
|
return obj instanceof Date ? obj : new Date(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
const dateNDaysAgo = function(numDaysAgo) {
|
|
|
|
return shiftDate(new Date(), -numDaysAgo);
|
|
|
|
}
|
|
|
|
|
|
|
|
const getRange = function(count) {
|
|
|
|
const arr: number[] = [];
|
|
|
|
for (let idx = 0; idx < count; idx += 1) {
|
|
|
|
arr.push(idx);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** END CALENDAR **/
|
|
|
|
|
|
|
|
|
|
|
|
export { isAllLoadedLocally, shiftDate, getBeginningTimeForDate, convertToDate, dateNDaysAgo, getRange };
|