qsu
Version:
qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.
1 lines • 650 B
JavaScript
import{dateToYYYYMMDD as t}from"./dateToYYYYMMDD.js";import{isValidDate as e}from"./isValidDate.js";export function createDateListFromRange(r,a){if(!e(t(r))||!e(t(a)))throw new Error("Either the start date or end date is an invalid date.");if(Math.floor((Date.parse(a.toString())-Date.parse(r.toString()))/864e5)<0)throw new Error("The start date is more recent than the end date.");const o=t(a),n=[];let i=r.getFullYear(),s=r.getMonth()+1,d=r.getDate(),h="";const f=(t,e,r)=>`${t}-${e<10?"0":""}${e}-${r<10?"0":""}${r}`;for(;o!==h;){/[0-9]{4}-12-31/g.test(h)&&(i+=1,s=1,d=1);const t=f(i,s,d);e(t)?(d+=1,n.push(t),h=t):(s+=1,d=1,h=f(i,s,d))}return n}