const kMillisecondsPerDay = 1000 * 60 * 60 * 24;
export function daysBetween(a, b) {
console.assert(a instanceof Date, a);
console.assert(b instanceof Date, b);
return Math.ceil((b.getTime() - a.getTime()) / kMillisecondsPerDay);
}
export function fromCalendarDateString(string) {
console.assert(typeof string === "string", string);
console.assert(string.length === 8, string);
let year = parseInt(string.substring(0, 4));
console.assert(!isNaN(year), string);
let month = parseInt(string.substring(4, 6)) - 1;
console.assert(!isNaN(month), string);
let day = parseInt(string.substring(6, 8));
console.assert(!isNaN(day), string);
return new Date(Date.UTC(year, month, day));
}
export function toCalendarDateString(date) {
console.assert(date instanceof Date, date);
return String(date.getUTCFullYear()) + String(date.getUTCMonth() + 1).padStart(2, "0") + String(date.getUTCDate()).padStart(2, "0");
}