47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
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;
|
|
}
|
|
|
|
/** 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 };
|