UNPKG

@stdlib/array-datespace

Version:

Generate an array of linearly spaced dates.

6 lines (5 loc) 1.68 kB
"use strict";var l=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var b=l(function(L,v){ var q=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-integer/dist'),D=require('@stdlib/assert-is-string/dist').isPrimitive,w=require('@stdlib/assert-is-object/dist'),o=require('@stdlib/error-tools-fmtprodmsg/dist'),E=require('@stdlib/math-base-special-floor/dist'),T=require('@stdlib/math-base-special-round/dist'),O=require('@stdlib/math-base-special-ceil/dist'),S=/^\d{10}$|^\d{13}$/,g=["floor","ceil","round"];function c(r,e){var n;if(n=typeof r,n==="string"){if(r=Date.parse(r),r!==r)throw new Error(o('00b2R',e.toLowerCase()));r=new Date(r)}if(n==="number"){if(!S.test(r))throw new Error(o('00b2S',e.toLowerCase()));r.toString().length===10&&(r*=1e3),r=new Date(r)}if(!(r instanceof Date))throw new TypeError(o('00b2T',e));return r}function x(r,e,n,h){var i,t,m,s,u,f,a,p,d;if(t=100,m=!0,i={round:"floor"},r=c(r,"Start"),e=c(e,"Stop"),arguments.length>2){if(arguments.length===3?w(n)?i=n:(t=n,m=!1):(i=h,t=n),t===0)return[];if(!y(t)||t<0)throw new TypeError(o('00b2U',t));if(m){if(!w(i))throw new TypeError(o('00b2V',i));if(q(i,"round")){if(!D(i.round))throw new TypeError(o('00b2W',"round",i.round));if(g.indexOf(i.round)===-1)throw new Error(o('00b4S',"round",g.join('", "'),i.round))}}}switch(i.round){case"round":f=T;break;case"ceil":f=O;break;case"floor":default:f=E;break}for(u=t-1,p=(e.getTime()-r.getTime())/u,s=new Array(t),a=r,s[0]=a,a=a.getTime(),d=1;d<u;d++)a+=p,s[d]=new Date(f(a));return s[u]=e,s}v.exports=x });var j=b();module.exports=j; /** @license Apache-2.0 */ //# sourceMappingURL=index.js.map