@kong-ui-public/analytics-utilities 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var P=Object.defineProperty;var C=(e,t,r)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var l=(e,t,r)=>(C(e,typeof t!="symbol"?t+"":t,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var a=(e=>(e.MINUTELY="Minutely",e.HOURLY="Hourly",e.DAILY="Daily",e.WEEKLY="Weekly",e))(a||{}),s=(e=>(e.FIFTEEN_MIN="15m",e.ONE_HOUR="1h",e.SIX_HOUR="6h",e.TWELVE_HOUR="12h",e.ONE_DAY="24h",e.SEVEN_DAY="7d",e.THIRTY_DAY="30d",e.CURRENT_WEEK="current_week",e.CURRENT_MONTH="current_month",e.CURRENT_QUARTER="current_quarter",e.PREVIOUS_WEEK="previous_week",e.PREVIOUS_MONTH="previous_month",e.PREVIOUS_QUARTER="previous_quarter",e))(s||{}),U=(e=>(e.DOUGHNUT="Doughnut",e.HORIZONTAL_BAR="HorizontalBar",e.VERTICAL_BAR="VerticalBar",e.TIMESERIES_LINE="Line",e.TIMESERIES_BAR="TimeSeriesBar",e))(U||{});const p={[a.MINUTELY]:60*1e3,[a.HOURLY]:60*60*1e3,[a.DAILY]:60*60*24*1e3,[a.WEEKLY]:60*60*24*7*1e3};function V(e,t){return e.map(r=>({value:r,label:t.t(`configuration.vitals.reports.granularity.${r}`)}))}function G(e,t){return e?{duration:e,type:"duration",origin:t}:null}function F(e){return e&&Object.values(a).find(r=>e<=p[r])||null}function H(e,t,r){const n=p[r],i=n>=p[a.DAILY]?t.getTimezoneOffset()*60*1e3:0;return new Date(e((t.getTime()-i)/n)*n+i)}function S(e,t){return H(Math.floor,e,t)}function N(e,t){return H(Math.ceil,e,t)}function E(e){"@babel/helpers - typeof";return E=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(e)}function f(e){if(e===null||e===!0||e===!1)return NaN;var t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function u(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function y(e){u(1,arguments);var t=Object.prototype.toString.call(e);return e instanceof Date||E(e)==="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function I(e,t){u(2,arguments);var r=y(e),n=f(t);return isNaN(n)?new Date(NaN):(n&&r.setDate(r.getDate()+n),r)}function Q(e,t){u(2,arguments);var r=y(e),n=f(t);if(isNaN(n))return new Date(NaN);if(!n)return r;var i=r.getDate(),o=new Date(r.getTime());o.setMonth(r.getMonth()+n+1,0);var d=o.getDate();return i>=d?o:(r.setFullYear(o.getFullYear(),o.getMonth(),i),r)}var z={};function B(){return z}function O(e,t){var r,n,i,o,d,h,D,w;u(1,arguments);var v=B(),T=f((r=(n=(i=(o=t==null?void 0:t.weekStartsOn)!==null&&o!==void 0?o:t==null||(d=t.locale)===null||d===void 0||(h=d.options)===null||h===void 0?void 0:h.weekStartsOn)!==null&&i!==void 0?i:v.weekStartsOn)!==null&&n!==void 0?n:(D=v.locale)===null||D===void 0||(w=D.options)===null||w===void 0?void 0:w.weekStartsOn)!==null&&r!==void 0?r:0);if(!(T>=0&&T<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var c=y(e),R=c.getDay(),L=(R<T?7:0)+R-T;return c.setDate(c.getDate()-L),c.setHours(0,0,0,0),c}function Y(e){u(1,arguments);var t=y(e);return t.setHours(0,0,0,0),t}var $=60,j=3600;function g(e){u(1,arguments);var t=y(e);return t.setDate(1),t.setHours(0,0,0,0),t}function X(e){u(1,arguments);var t=y(e),r=t.getFullYear(),n=t.getMonth(),i=new Date(0);return i.setFullYear(r,n+1,0),i.setHours(0,0,0,0),i.getDate()}function _(e){u(1,arguments);var t=y(e),r=t.getTime();return r}function k(e){return u(1,arguments),Math.floor(_(e)/1e3)}function q(e){return u(1,arguments),Math.floor(e*j)}function Z(e,t){u(2,arguments);var r=f(t);return I(e,-r)}function J(e){u(1,arguments);var t=e/$;return Math.floor(t)}function A(e,t){u(2,arguments);var r=f(t);return Q(e,-r)}function K(e,t){if(u(2,arguments),!t||E(t)!=="object")return new Date(NaN);var r=t.years?f(t.years):0,n=t.months?f(t.months):0,i=t.weeks?f(t.weeks):0,o=t.days?f(t.days):0,d=t.hours?f(t.hours):0,h=t.minutes?f(t.minutes):0,D=t.seconds?f(t.seconds):0,w=A(e,n+r*12),v=Z(w,o+i*7),T=h+d*60,c=D+T*60,R=c*1e3,L=new Date(v.getTime()-R);return L}class M{constructor(t){l(this,"timeframe");if(this.constructor===M)throw new Error("BaseQueryTime is not meant to be used directly.");this.timeframe=t}calculateStartDate(t,r,n=1){if(t)return new Date(this.endDate().getTime()-this.timeframe.timeframeLengthMs()*n);{const i=this.endDate(),o=S(this.timeframe.rawStart(),r),h=(i.getTime()-o.getTime())*(n-1);return S(new Date(this.timeframe.rawStart().getTime()-h),r)}}granularitySeconds(){return Math.floor(this.granularityMs()/1e3)}granularityDruid(){return G(this.granularityMs(),this.startDate().toISOString())}startSeconds(){return k(this.startDate())}endSeconds(){return k(this.endDate())}startMs(){return _(this.startDate())}endMs(){return _(this.endDate())}withinFreeTier(){return this.startDate()>=K(new Date,{days:1})}}class ee extends M{constructor(r,n){super(r);l(this,"granularity");n&&r.allowedGranularities().has(n)?this.granularity=n:this.granularity=r.defaultResponseGranularity}startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.granularity)}endDate(){return N(this.timeframe.rawEnd(),this.granularity)}granularityMs(){return p[this.granularity]}}class b extends M{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity)}endDate(){return N(this.timeframe.rawEnd(),this.timeframe.dataGranularity)}granularityMs(){return this.endDate().getTime()-this.startDate().getTime()}}class te extends b{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity,2)}granularityMs(){return this.endDate().getTime()-super.startDate().getTime()}}class m{constructor(t){l(this,"timeframeText");l(this,"key");l(this,"display");l(this,"timeframeLength");l(this,"allowedTiers");l(this,"defaultResponseGranularity");l(this,"dataGranularity");l(this,"isRelative");l(this,"_startCustom");l(this,"_endCustom");this.display=t.display,this.timeframeText=t.timeframeText,this.key=t.key,this.timeframeLength=t.timeframeLength,this.allowedTiers=t.allowedTiers,this.defaultResponseGranularity=t.defaultResponseGranularity,this.dataGranularity=t.dataGranularity,this.isRelative=t.isRelative,this._startCustom=t.startCustom,this._endCustom=t.endCustom}rawEnd(){return this._endCustom||new Date}rawStart(){return this._startCustom||new Date(this.rawEnd().getTime()-this.timeframeLengthMs())}timeframeLengthMs(){return this.timeframeLength()*1e3}maximumTimeframeLength(){return this.timeframeLength()}allowedGranularities(){const t=new Set,r=this.maximumTimeframeLength()/3600;return r<=6&&t.add(a.MINUTELY),r>=2&&r<=7*24&&t.add(a.HOURLY),r>=2*24&&t.add(a.DAILY),r>=2*24*14&&t.add(a.WEEKLY),t}}class re extends m{rawStart(){return O(new Date,{weekStartsOn:1})}maximumTimeframeLength(){return 60*60*24*7}}class ae extends m{rawStart(){return g(new Date)}maximumTimeframeLength(){return 60*60*24*31}}class ne extends m{rawEnd(){return O(new Date,{weekStartsOn:1})}rawStart(){return O(new Date().setDate(new Date().getDate()-7),{weekStartsOn:1})}}class se extends m{rawEnd(){return g(new Date)}rawStart(){return g(new Date().setMonth(new Date().getMonth()-1))}}const x=new Map([[s.FIFTEEN_MIN,new m({key:s.FIFTEEN_MIN,display:"Last 15 minutes",timeframeText:"15 minutes",timeframeLength:()=>60*15,defaultResponseGranularity:a.MINUTELY,dataGranularity:a.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.ONE_HOUR,new m({key:s.ONE_HOUR,display:"Last hour",timeframeText:"One hour",timeframeLength:()=>60*60*1,defaultResponseGranularity:a.MINUTELY,dataGranularity:a.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.SIX_HOUR,new m({key:s.SIX_HOUR,display:"Last 6 hours",timeframeText:"6 hours",timeframeLength:()=>60*60*6,defaultResponseGranularity:a.HOURLY,dataGranularity:a.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.TWELVE_HOUR,new m({key:s.TWELVE_HOUR,display:"Last 12 hours",timeframeText:"12 hours",timeframeLength:()=>60*60*12,defaultResponseGranularity:a.HOURLY,dataGranularity:a.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.ONE_DAY,new m({key:s.ONE_DAY,display:"Last 24 hours",timeframeText:"24 hours",timeframeLength:()=>60*60*24,defaultResponseGranularity:a.HOURLY,dataGranularity:a.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.SEVEN_DAY,new m({key:s.SEVEN_DAY,display:"Last 7 days",timeframeText:"7 days",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[s.THIRTY_DAY,new m({key:s.THIRTY_DAY,display:"Last 30 days",timeframeText:"30 days",timeframeLength:()=>60*60*24*30,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[s.CURRENT_WEEK,new re({key:s.CURRENT_WEEK,display:"This week",timeframeText:"Week",timeframeLength:()=>{const e=O(new Date,{weekStartsOn:1});return(Y(I(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[s.CURRENT_MONTH,new ae({key:s.CURRENT_MONTH,display:"This month",timeframeText:"Month",timeframeLength:()=>{const e=g(new Date);return(Y(I(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[s.PREVIOUS_WEEK,new ne({key:s.PREVIOUS_WEEK,display:"Previous week",timeframeText:"Week",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[s.PREVIOUS_MONTH,new se({key:s.PREVIOUS_MONTH,display:"Previous month",timeframeText:"Month",timeframeLength:()=>{let e=0;const t=g(new Date),r=g(A(new Date,1));return t.getTimezoneOffset()!==r.getTimezoneOffset()&&(e=W(t,r)),60*60*24*X(new Date().setMonth(new Date().getMonth()-1))+q(e)},defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})]]);function ie(e){const t=new Date(e.start),r=new Date(e.end),n=(r.getTime()-t.getTime())/1e3;return e.timePeriodsKey&&x.get(e.timePeriodsKey)||new m({key:"custom",timeframeText:"custom",display:"custom",startCustom:t,endCustom:r,timeframeLength:()=>n,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["free","plus","enterprise"]})}function ue(e){return{...e.key!=="custom"&&{timePeriodsKey:e.key},start:e.rawStart(),end:e.rawEnd()}}function oe(e){return{key:e.key,display:e.display,timeframeText:e.timeframeText,timeframeLength:()=>e.key,start:()=>e.rawStart(),end:()=>e.rawEnd()}}function W(e,t){return J(e.getTimezoneOffset()-t.getTimezoneOffset())}exports.ChartTypes=U;exports.DeltaQueryTime=te;exports.Granularities=p;exports.GranularityKeys=a;exports.TimePeriods=x;exports.Timeframe=m;exports.TimeframeKeys=s;exports.TimeseriesQueryTime=ee;exports.UnaryQueryTime=b;exports.ceilToNearestTimeGrain=N;exports.datePickerSelectionToTimeframe=ie;exports.dstOffsetHours=W;exports.floorToNearestTimeGrain=S;exports.granularitiesToOptions=V;exports.granularityMsToQuery=G;exports.msToGranularity=F;exports.timeframeToDatepickerSelection=ue;exports.timeframeToDatepickerTimeperiod=oe;
1
+ "use strict";var P=Object.defineProperty;var C=(e,t,r)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var l=(e,t,r)=>(C(e,typeof t!="symbol"?t+"":t,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var a=(e=>(e.MINUTELY="Minutely",e.HOURLY="Hourly",e.DAILY="Daily",e.WEEKLY="Weekly",e))(a||{}),s=(e=>(e.FIFTEEN_MIN="15m",e.ONE_HOUR="1h",e.SIX_HOUR="6h",e.TWELVE_HOUR="12h",e.ONE_DAY="24h",e.SEVEN_DAY="7d",e.THIRTY_DAY="30d",e.CURRENT_WEEK="current_week",e.CURRENT_MONTH="current_month",e.CURRENT_QUARTER="current_quarter",e.PREVIOUS_WEEK="previous_week",e.PREVIOUS_MONTH="previous_month",e.PREVIOUS_QUARTER="previous_quarter",e))(s||{}),G=(e=>(e.DOUGHNUT="Doughnut",e.HORIZONTAL_BAR="HorizontalBar",e.VERTICAL_BAR="VerticalBar",e.TIMESERIES_LINE="Line",e.TIMESERIES_BAR="TimeSeriesBar",e))(G||{});const p={[a.MINUTELY]:60*1e3,[a.HOURLY]:60*60*1e3,[a.DAILY]:60*60*24*1e3,[a.WEEKLY]:60*60*24*7*1e3};function V(e,t){return e.map(r=>({value:r,label:t.t(`configuration.vitals.reports.granularity.${r}`)}))}function H(e,t){return e?{duration:e,type:"duration",origin:t}:null}function F(e){return e&&Object.values(a).find(r=>e<=p[r])||null}function A(e,t,r){const n=p[r],i=n>=p[a.DAILY]?t.getTimezoneOffset()*60*1e3:0;return new Date(e((t.getTime()-i)/n)*n+i)}function S(e,t){return A(Math.floor,e,t)}function N(e,t){return A(Math.ceil,e,t)}function E(e){"@babel/helpers - typeof";return E=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(e)}function f(e){if(e===null||e===!0||e===!1)return NaN;var t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function u(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function y(e){u(1,arguments);var t=Object.prototype.toString.call(e);return e instanceof Date||E(e)==="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[object String]")&&typeof console<"u"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function I(e,t){u(2,arguments);var r=y(e),n=f(t);return isNaN(n)?new Date(NaN):(n&&r.setDate(r.getDate()+n),r)}function Q(e,t){u(2,arguments);var r=y(e),n=f(t);if(isNaN(n))return new Date(NaN);if(!n)return r;var i=r.getDate(),o=new Date(r.getTime());o.setMonth(r.getMonth()+n+1,0);var d=o.getDate();return i>=d?o:(r.setFullYear(o.getFullYear(),o.getMonth(),i),r)}var z={};function B(){return z}function O(e,t){var r,n,i,o,d,h,D,w;u(1,arguments);var v=B(),T=f((r=(n=(i=(o=t==null?void 0:t.weekStartsOn)!==null&&o!==void 0?o:t==null||(d=t.locale)===null||d===void 0||(h=d.options)===null||h===void 0?void 0:h.weekStartsOn)!==null&&i!==void 0?i:v.weekStartsOn)!==null&&n!==void 0?n:(D=v.locale)===null||D===void 0||(w=D.options)===null||w===void 0?void 0:w.weekStartsOn)!==null&&r!==void 0?r:0);if(!(T>=0&&T<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var c=y(e),R=c.getDay(),M=(R<T?7:0)+R-T;return c.setDate(c.getDate()-M),c.setHours(0,0,0,0),c}function k(e){u(1,arguments);var t=y(e);return t.setHours(0,0,0,0),t}var $=60,j=3600;function g(e){u(1,arguments);var t=y(e);return t.setDate(1),t.setHours(0,0,0,0),t}function X(e){u(1,arguments);var t=y(e),r=t.getFullYear(),n=t.getMonth(),i=new Date(0);return i.setFullYear(r,n+1,0),i.setHours(0,0,0,0),i.getDate()}function _(e){u(1,arguments);var t=y(e),r=t.getTime();return r}function U(e){return u(1,arguments),Math.floor(_(e)/1e3)}function q(e){return u(1,arguments),Math.floor(e*j)}function Z(e,t){u(2,arguments);var r=f(t);return I(e,-r)}function J(e){u(1,arguments);var t=e/$;return Math.floor(t)}function Y(e,t){u(2,arguments);var r=f(t);return Q(e,-r)}function K(e,t){if(u(2,arguments),!t||E(t)!=="object")return new Date(NaN);var r=t.years?f(t.years):0,n=t.months?f(t.months):0,i=t.weeks?f(t.weeks):0,o=t.days?f(t.days):0,d=t.hours?f(t.hours):0,h=t.minutes?f(t.minutes):0,D=t.seconds?f(t.seconds):0,w=Y(e,n+r*12),v=Z(w,o+i*7),T=h+d*60,c=D+T*60,R=c*1e3,M=new Date(v.getTime()-R);return M}class L{constructor(t){l(this,"timeframe");if(this.constructor===L)throw new Error("BaseQueryTime is not meant to be used directly.");this.timeframe=t}calculateStartDate(t,r,n=1){if(t)return new Date(this.endDate().getTime()-this.timeframe.timeframeLengthMs()*n);{const i=this.endDate(),o=S(this.timeframe.rawStart(),r),h=(i.getTime()-o.getTime())*(n-1);return S(new Date(this.timeframe.rawStart().getTime()-h),r)}}granularitySeconds(){return Math.floor(this.granularityMs()/1e3)}granularityDruid(){return H(this.granularityMs(),this.startDate().toISOString())}startSeconds(){return U(this.startDate())}endSeconds(){return U(this.endDate())}startMs(){return _(this.startDate())}endMs(){return _(this.endDate())}withinFreeTier(){return this.startDate()>=K(new Date,{days:1})}}class ee extends L{constructor(r,n){super(r);l(this,"granularity");n&&r.allowedGranularities().has(n)?this.granularity=n:this.granularity=r.defaultResponseGranularity}startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.granularity)}endDate(){return N(this.timeframe.rawEnd(),this.granularity)}granularityMs(){return p[this.granularity]}}class b extends L{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity)}endDate(){return N(this.timeframe.rawEnd(),this.timeframe.dataGranularity)}granularityMs(){return this.endDate().getTime()-this.startDate().getTime()}}class te extends b{startDate(){return this.calculateStartDate(this.timeframe.isRelative,this.timeframe.dataGranularity,2)}granularityMs(){return this.endDate().getTime()-super.startDate().getTime()}}class m{constructor(t){l(this,"timeframeText");l(this,"key");l(this,"display");l(this,"timeframeLength");l(this,"allowedTiers");l(this,"defaultResponseGranularity");l(this,"dataGranularity");l(this,"isRelative");l(this,"_startCustom");l(this,"_endCustom");this.display=t.display,this.timeframeText=t.timeframeText,this.key=t.key,this.timeframeLength=t.timeframeLength,this.allowedTiers=t.allowedTiers,this.defaultResponseGranularity=t.defaultResponseGranularity,this.dataGranularity=t.dataGranularity,this.isRelative=t.isRelative,this._startCustom=t.startCustom,this._endCustom=t.endCustom}rawEnd(){return this._endCustom||new Date}rawStart(){return this._startCustom||new Date(this.rawEnd().getTime()-this.timeframeLengthMs())}timeframeLengthMs(){return this.timeframeLength()*1e3}maximumTimeframeLength(){return this.timeframeLength()}allowedGranularities(){const t=new Set,r=this.maximumTimeframeLength()/3600;return r<=6&&t.add(a.MINUTELY),r>=2&&r<=7*24&&t.add(a.HOURLY),r>=2*24&&t.add(a.DAILY),r>=2*24*14&&t.add(a.WEEKLY),t}}class re extends m{rawStart(){return O(new Date,{weekStartsOn:1})}maximumTimeframeLength(){return 60*60*24*7}}class ae extends m{rawStart(){return g(new Date)}maximumTimeframeLength(){return 60*60*24*31}}class ne extends m{rawEnd(){return O(new Date,{weekStartsOn:1})}rawStart(){return O(new Date().setDate(new Date().getDate()-7),{weekStartsOn:1})}}class se extends m{rawEnd(){return g(new Date)}rawStart(){return g(Y(new Date,1))}}const x=new Map([[s.FIFTEEN_MIN,new m({key:s.FIFTEEN_MIN,display:"Last 15 minutes",timeframeText:"15 minutes",timeframeLength:()=>60*15,defaultResponseGranularity:a.MINUTELY,dataGranularity:a.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.ONE_HOUR,new m({key:s.ONE_HOUR,display:"Last hour",timeframeText:"One hour",timeframeLength:()=>60*60*1,defaultResponseGranularity:a.MINUTELY,dataGranularity:a.MINUTELY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.SIX_HOUR,new m({key:s.SIX_HOUR,display:"Last 6 hours",timeframeText:"6 hours",timeframeLength:()=>60*60*6,defaultResponseGranularity:a.HOURLY,dataGranularity:a.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.TWELVE_HOUR,new m({key:s.TWELVE_HOUR,display:"Last 12 hours",timeframeText:"12 hours",timeframeLength:()=>60*60*12,defaultResponseGranularity:a.HOURLY,dataGranularity:a.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.ONE_DAY,new m({key:s.ONE_DAY,display:"Last 24 hours",timeframeText:"24 hours",timeframeLength:()=>60*60*24,defaultResponseGranularity:a.HOURLY,dataGranularity:a.HOURLY,isRelative:!0,allowedTiers:["free","trial","plus","enterprise"]})],[s.SEVEN_DAY,new m({key:s.SEVEN_DAY,display:"Last 7 days",timeframeText:"7 days",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[s.THIRTY_DAY,new m({key:s.THIRTY_DAY,display:"Last 30 days",timeframeText:"30 days",timeframeLength:()=>60*60*24*30,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!0,allowedTiers:["trial","plus","enterprise"]})],[s.CURRENT_WEEK,new re({key:s.CURRENT_WEEK,display:"This week",timeframeText:"Week",timeframeLength:()=>{const e=O(new Date,{weekStartsOn:1});return(k(I(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[s.CURRENT_MONTH,new ae({key:s.CURRENT_MONTH,display:"This month",timeframeText:"Month",timeframeLength:()=>{const e=g(new Date);return(k(I(new Date,1)).getTime()-e.getTime())/1e3},defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[s.PREVIOUS_WEEK,new ne({key:s.PREVIOUS_WEEK,display:"Previous week",timeframeText:"Week",timeframeLength:()=>60*60*24*7,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})],[s.PREVIOUS_MONTH,new se({key:s.PREVIOUS_MONTH,display:"Previous month",timeframeText:"Month",timeframeLength:()=>{let e=0;const t=g(new Date),r=g(Y(new Date,1));return t.getTimezoneOffset()!==r.getTimezoneOffset()&&(e=W(t,r)),60*60*24*X(new Date().setMonth(new Date().getMonth()-1))+q(e)},defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["plus","enterprise"]})]]);function ie(e){const t=new Date(e.start),r=new Date(e.end),n=(r.getTime()-t.getTime())/1e3;return e.timePeriodsKey&&x.get(e.timePeriodsKey)||new m({key:"custom",timeframeText:"custom",display:"custom",startCustom:t,endCustom:r,timeframeLength:()=>n,defaultResponseGranularity:a.DAILY,dataGranularity:a.DAILY,isRelative:!1,allowedTiers:["free","plus","enterprise"]})}function ue(e){return{...e.key!=="custom"&&{timePeriodsKey:e.key},start:e.rawStart(),end:e.rawEnd()}}function oe(e){return{key:e.key,display:e.display,timeframeText:e.timeframeText,timeframeLength:()=>e.key,start:()=>e.rawStart(),end:()=>e.rawEnd()}}function W(e,t){return J(e.getTimezoneOffset()-t.getTimezoneOffset())}exports.ChartTypes=G;exports.DeltaQueryTime=te;exports.Granularities=p;exports.GranularityKeys=a;exports.TimePeriods=x;exports.Timeframe=m;exports.TimeframeKeys=s;exports.TimeseriesQueryTime=ee;exports.UnaryQueryTime=b;exports.ceilToNearestTimeGrain=N;exports.datePickerSelectionToTimeframe=ie;exports.dstOffsetHours=W;exports.floorToNearestTimeGrain=S;exports.granularitiesToOptions=V;exports.granularityMsToQuery=H;exports.msToGranularity=F;exports.timeframeToDatepickerSelection=ue;exports.timeframeToDatepickerTimeperiod=oe;
2
2
  //# sourceMappingURL=vitals-utilities.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitals-utilities.cjs","sources":["../src/types/granularity-keys.ts","../src/types/timeframe-keys.ts","../src/types/chart-types.ts","../src/granularity.ts","../../../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/esm/typeof.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/toInteger/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/requiredArgs/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/toDate/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addDays/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addMonths/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/defaultOptions/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfWeek/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfDay/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/constants/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfMonth/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/getDaysInMonth/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/getTime/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/getUnixTime/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/hoursToSeconds/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/subDays/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/minutesToHours/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/subMonths/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/sub/index.js","../src/queryTime.ts","../src/timeframes.ts"],"sourcesContent":["/* eslint-disable no-unused-vars */\nexport enum GranularityKeys {\n MINUTELY = 'Minutely',\n HOURLY = 'Hourly',\n DAILY = 'Daily',\n WEEKLY = 'Weekly'\n}\n","/* eslint-disable no-unused-vars */\nexport enum TimeframeKeys {\n FIFTEEN_MIN = '15m',\n ONE_HOUR = '1h',\n SIX_HOUR = '6h',\n TWELVE_HOUR = '12h',\n ONE_DAY = '24h',\n SEVEN_DAY = '7d',\n THIRTY_DAY = '30d',\n CURRENT_WEEK = 'current_week',\n CURRENT_MONTH = 'current_month',\n CURRENT_QUARTER = 'current_quarter',\n PREVIOUS_WEEK = 'previous_week',\n PREVIOUS_MONTH = 'previous_month',\n PREVIOUS_QUARTER = 'previous_quarter'\n}\n","/* eslint-disable no-unused-vars */\nexport enum ChartTypes {\n DOUGHNUT = 'Doughnut',\n HORIZONTAL_BAR = 'HorizontalBar',\n VERTICAL_BAR = 'VerticalBar',\n TIMESERIES_LINE = 'Line',\n TIMESERIES_BAR = 'TimeSeriesBar'\n}\n","import { DruidGranularity, GranularityKeys } from './types'\n\n// Units are milliseconds, which are what Druid expects.\nexport const Granularities = {\n [GranularityKeys.MINUTELY]: 60 * 1000,\n [GranularityKeys.HOURLY]: 60 * 60 * 1000,\n [GranularityKeys.DAILY]: 60 * 60 * 24 * 1000,\n [GranularityKeys.WEEKLY]: 60 * 60 * 24 * 7 * 1000,\n}\n\nexport function granularitiesToOptions(\n values: GranularityKeys[],\n i18n: { t: (v: string) => string },\n) {\n return values.map((v) => ({\n value: v,\n label: i18n.t(`configuration.vitals.reports.granularity.${v}`),\n }))\n}\n\nexport function granularityMsToQuery(\n granularity: number | null,\n origin?: string,\n): DruidGranularity | null {\n if (granularity) {\n return {\n duration: granularity,\n type: 'duration',\n origin,\n }\n }\n\n return null\n}\n\nexport function msToGranularity(ms?: number): GranularityKeys | null {\n if (!ms) {\n return null\n }\n\n // Note that this folds weird granularity values into known values.\n const key = Object.values(GranularityKeys).find((k) => ms <= Granularities[k])\n\n return key || null\n}\n\nfunction toNearestTimeGrain(\n op: (x: number) => number,\n date: Date,\n granularity: GranularityKeys,\n): Date {\n // Days and weeks need special handling because naively trying to `ceil` or `floor` them results in a date ending\n // in midnight UTC, whereas as of now we want dates ending in midnight local time.\n // Note: right now we treat daily and weekly granularities the same way, because it's OK to request an\n // incomplete week (i.e., if it's currently Monday at noon, it's OK to request data up to Tuesday midnight for the current week).\n // Druid will just limit its query range accordingly.\n const granularityMs = Granularities[granularity]\n const tzOffsetMs =\n granularityMs >= Granularities[GranularityKeys.DAILY] ? date.getTimezoneOffset() * 60 * 1000 : 0\n\n return new Date(op((date.getTime() - tzOffsetMs) / granularityMs) * granularityMs + tzOffsetMs)\n}\n\nexport function floorToNearestTimeGrain(date: Date, granularity: GranularityKeys): Date {\n return toNearestTimeGrain(Math.floor, date, granularity)\n}\n\nexport function ceilToNearestTimeGrain(date: Date, granularity: GranularityKeys): Date {\n return toNearestTimeGrain(Math.ceil, date, granularity)\n}\n","export default function _typeof(obj) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) {\n return typeof obj;\n } : function (obj) {\n return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n }, _typeof(obj);\n}","export default function toInteger(dirtyNumber) {\n if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {\n return NaN;\n }\n var number = Number(dirtyNumber);\n if (isNaN(number)) {\n return number;\n }\n return number < 0 ? Math.ceil(number) : Math.floor(number);\n}","export default function requiredArgs(required, args) {\n if (args.length < required) {\n throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');\n }\n}","import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name toDate\n * @category Common Helpers\n * @summary Convert the given argument to an instance of Date.\n *\n * @description\n * Convert the given argument to an instance of Date.\n *\n * If the argument is an instance of Date, the function returns its clone.\n *\n * If the argument is a number, it is treated as a timestamp.\n *\n * If the argument is none of the above, the function returns Invalid Date.\n *\n * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.\n *\n * @param {Date|Number} argument - the value to convert\n * @returns {Date} the parsed date in the local time zone\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Clone the date:\n * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))\n * //=> Tue Feb 11 2014 11:30:30\n *\n * @example\n * // Convert the timestamp to date:\n * const result = toDate(1392098430000)\n * //=> Tue Feb 11 2014 11:30:30\n */\nexport default function toDate(argument) {\n requiredArgs(1, arguments);\n var argStr = Object.prototype.toString.call(argument);\n\n // Clone the date\n if (argument instanceof Date || _typeof(argument) === 'object' && argStr === '[object Date]') {\n // Prevent the date to lose the milliseconds when passed to new Date() in IE10\n return new Date(argument.getTime());\n } else if (typeof argument === 'number' || argStr === '[object Number]') {\n return new Date(argument);\n } else {\n if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(\"Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments\");\n // eslint-disable-next-line no-console\n console.warn(new Error().stack);\n }\n return new Date(NaN);\n }\n}","import toInteger from \"../_lib/toInteger/index.js\";\nimport toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name addDays\n * @category Day Helpers\n * @summary Add the specified number of days to the given date.\n *\n * @description\n * Add the specified number of days to the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} - the new date with the days added\n * @throws {TypeError} - 2 arguments required\n *\n * @example\n * // Add 10 days to 1 September 2014:\n * const result = addDays(new Date(2014, 8, 1), 10)\n * //=> Thu Sep 11 2014 00:00:00\n */\nexport default function addDays(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var date = toDate(dirtyDate);\n var amount = toInteger(dirtyAmount);\n if (isNaN(amount)) {\n return new Date(NaN);\n }\n if (!amount) {\n // If 0 days, no-op to avoid changing times in the hour before end of DST\n return date;\n }\n date.setDate(date.getDate() + amount);\n return date;\n}","import toInteger from \"../_lib/toInteger/index.js\";\nimport toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name addMonths\n * @category Month Helpers\n * @summary Add the specified number of months to the given date.\n *\n * @description\n * Add the specified number of months to the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} the new date with the months added\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Add 5 months to 1 September 2014:\n * const result = addMonths(new Date(2014, 8, 1), 5)\n * //=> Sun Feb 01 2015 00:00:00\n */\nexport default function addMonths(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var date = toDate(dirtyDate);\n var amount = toInteger(dirtyAmount);\n if (isNaN(amount)) {\n return new Date(NaN);\n }\n if (!amount) {\n // If 0 months, no-op to avoid changing times in the hour before end of DST\n return date;\n }\n var dayOfMonth = date.getDate();\n\n // The JS Date object supports date math by accepting out-of-bounds values for\n // month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and\n // new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we\n // want except that dates will wrap around the end of a month, meaning that\n // new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So\n // we'll default to the end of the desired month by adding 1 to the desired\n // month and using a date of 0 to back up one day to the end of the desired\n // month.\n var endOfDesiredMonth = new Date(date.getTime());\n endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0);\n var daysInMonth = endOfDesiredMonth.getDate();\n if (dayOfMonth >= daysInMonth) {\n // If we're already at the end of the month, then this is the correct date\n // and we're done.\n return endOfDesiredMonth;\n } else {\n // Otherwise, we now know that setting the original day-of-month value won't\n // cause an overflow, so set the desired day-of-month. Note that we can't\n // just set the date of `endOfDesiredMonth` because that object may have had\n // its time changed in the unusual case where where a DST transition was on\n // the last day of the month and its local time was in the hour skipped or\n // repeated next to a DST transition. So we use `date` instead which is\n // guaranteed to still have the original time.\n date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);\n return date;\n }\n}","var defaultOptions = {};\nexport function getDefaultOptions() {\n return defaultOptions;\n}\nexport function setDefaultOptions(newOptions) {\n defaultOptions = newOptions;\n}","import toDate from \"../toDate/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { getDefaultOptions } from \"../_lib/defaultOptions/index.js\";\n/**\n * @name startOfWeek\n * @category Week Helpers\n * @summary Return the start of a week for the given date.\n *\n * @description\n * Return the start of a week for the given date.\n * The result will be in the local timezone.\n *\n * @param {Date|Number} date - the original date\n * @param {Object} [options] - an object with options.\n * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}\n * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)\n * @returns {Date} the start of a week\n * @throws {TypeError} 1 argument required\n * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6\n *\n * @example\n * // The start of a week for 2 September 2014 11:55:00:\n * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Sun Aug 31 2014 00:00:00\n *\n * @example\n * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:\n * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })\n * //=> Mon Sep 01 2014 00:00:00\n */\nexport default function startOfWeek(dirtyDate, options) {\n var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;\n requiredArgs(1, arguments);\n var defaultOptions = getDefaultOptions();\n var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);\n\n // Test if weekStartsOn is between 0 and 6 _and_ is not NaN\n if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {\n throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');\n }\n var date = toDate(dirtyDate);\n var day = date.getDay();\n var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;\n date.setDate(date.getDate() - diff);\n date.setHours(0, 0, 0, 0);\n return date;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name startOfDay\n * @category Day Helpers\n * @summary Return the start of a day for the given date.\n *\n * @description\n * Return the start of a day for the given date.\n * The result will be in the local timezone.\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the start of a day\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The start of a day for 2 September 2014 11:55:00:\n * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Tue Sep 02 2014 00:00:00\n */\nexport default function startOfDay(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n date.setHours(0, 0, 0, 0);\n return date;\n}","/**\n * Days in 1 week.\n *\n * @name daysInWeek\n * @constant\n * @type {number}\n * @default\n */\nexport var daysInWeek = 7;\n\n/**\n * Days in 1 year\n * One years equals 365.2425 days according to the formula:\n *\n * > Leap year occures every 4 years, except for years that are divisable by 100 and not divisable by 400.\n * > 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days\n *\n * @name daysInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var daysInYear = 365.2425;\n\n/**\n * Maximum allowed time.\n *\n * @name maxTime\n * @constant\n * @type {number}\n * @default\n */\nexport var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000;\n\n/**\n * Milliseconds in 1 minute\n *\n * @name millisecondsInMinute\n * @constant\n * @type {number}\n * @default\n */\nexport var millisecondsInMinute = 60000;\n\n/**\n * Milliseconds in 1 hour\n *\n * @name millisecondsInHour\n * @constant\n * @type {number}\n * @default\n */\nexport var millisecondsInHour = 3600000;\n\n/**\n * Milliseconds in 1 second\n *\n * @name millisecondsInSecond\n * @constant\n * @type {number}\n * @default\n */\nexport var millisecondsInSecond = 1000;\n\n/**\n * Minimum allowed time.\n *\n * @name minTime\n * @constant\n * @type {number}\n * @default\n */\nexport var minTime = -maxTime;\n\n/**\n * Minutes in 1 hour\n *\n * @name minutesInHour\n * @constant\n * @type {number}\n * @default\n */\nexport var minutesInHour = 60;\n\n/**\n * Months in 1 quarter\n *\n * @name monthsInQuarter\n * @constant\n * @type {number}\n * @default\n */\nexport var monthsInQuarter = 3;\n\n/**\n * Months in 1 year\n *\n * @name monthsInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var monthsInYear = 12;\n\n/**\n * Quarters in 1 year\n *\n * @name quartersInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var quartersInYear = 4;\n\n/**\n * Seconds in 1 hour\n *\n * @name secondsInHour\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInHour = 3600;\n\n/**\n * Seconds in 1 minute\n *\n * @name secondsInMinute\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInMinute = 60;\n\n/**\n * Seconds in 1 day\n *\n * @name secondsInDay\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInDay = secondsInHour * 24;\n\n/**\n * Seconds in 1 week\n *\n * @name secondsInWeek\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInWeek = secondsInDay * 7;\n\n/**\n * Seconds in 1 year\n *\n * @name secondsInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInYear = secondsInDay * daysInYear;\n\n/**\n * Seconds in 1 month\n *\n * @name secondsInMonth\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInMonth = secondsInYear / 12;\n\n/**\n * Seconds in 1 quarter\n *\n * @name secondsInQuarter\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInQuarter = secondsInMonth * 3;","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name startOfMonth\n * @category Month Helpers\n * @summary Return the start of a month for the given date.\n *\n * @description\n * Return the start of a month for the given date.\n * The result will be in the local timezone.\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the start of a month\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The start of a month for 2 September 2014 11:55:00:\n * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Mon Sep 01 2014 00:00:00\n */\nexport default function startOfMonth(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n date.setDate(1);\n date.setHours(0, 0, 0, 0);\n return date;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name getDaysInMonth\n * @category Month Helpers\n * @summary Get the number of days in a month of the given date.\n *\n * @description\n * Get the number of days in a month of the given date.\n *\n * @param {Date|Number} date - the given date\n * @returns {Number} the number of days in a month\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // How many days are in February 2000?\n * const result = getDaysInMonth(new Date(2000, 1))\n * //=> 29\n */\nexport default function getDaysInMonth(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n var year = date.getFullYear();\n var monthIndex = date.getMonth();\n var lastDayOfMonth = new Date(0);\n lastDayOfMonth.setFullYear(year, monthIndex + 1, 0);\n lastDayOfMonth.setHours(0, 0, 0, 0);\n return lastDayOfMonth.getDate();\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name getTime\n * @category Timestamp Helpers\n * @summary Get the milliseconds timestamp of the given date.\n *\n * @description\n * Get the milliseconds timestamp of the given date.\n *\n * @param {Date|Number} date - the given date\n * @returns {Number} the timestamp\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Get the timestamp of 29 February 2012 11:45:05.123:\n * const result = getTime(new Date(2012, 1, 29, 11, 45, 5, 123))\n * //=> 1330515905123\n */\nexport default function getTime(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n var timestamp = date.getTime();\n return timestamp;\n}","import getTime from \"../getTime/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name getUnixTime\n * @category Timestamp Helpers\n * @summary Get the seconds timestamp of the given date.\n *\n * @description\n * Get the seconds timestamp of the given date.\n *\n * @param {Date|Number} date - the given date\n * @returns {Number} the timestamp\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Get the timestamp of 29 February 2012 11:45:05 CET:\n * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))\n * //=> 1330512305\n */\nexport default function getUnixTime(dirtyDate) {\n requiredArgs(1, arguments);\n return Math.floor(getTime(dirtyDate) / 1000);\n}","import requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { secondsInHour } from \"../constants/index.js\";\n/**\n * @name hoursToSeconds\n * @category Conversion Helpers\n * @summary Convert hours to seconds.\n *\n * @description\n * Convert a number of hours to a full number of seconds.\n *\n * @param {number} hours - number of hours to be converted\n *\n * @returns {number} the number of hours converted in seconds\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Convert 2 hours to seconds:\n * const result = hoursToSeconds(2)\n * //=> 7200\n */\nexport default function hoursToSeconds(hours) {\n requiredArgs(1, arguments);\n return Math.floor(hours * secondsInHour);\n}","import addDays from \"../addDays/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\n/**\n * @name subDays\n * @category Day Helpers\n * @summary Subtract the specified number of days from the given date.\n *\n * @description\n * Subtract the specified number of days from the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} the new date with the days subtracted\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Subtract 10 days from 1 September 2014:\n * const result = subDays(new Date(2014, 8, 1), 10)\n * //=> Fri Aug 22 2014 00:00:00\n */\nexport default function subDays(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var amount = toInteger(dirtyAmount);\n return addDays(dirtyDate, -amount);\n}","import requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { minutesInHour } from \"../constants/index.js\";\n/**\n * @name minutesToHours\n * @category Conversion Helpers\n * @summary Convert minutes to hours.\n *\n * @description\n * Convert a number of minutes to a full number of hours.\n *\n * @param {number} minutes - number of minutes to be converted\n *\n * @returns {number} the number of minutes converted in hours\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Convert 140 minutes to hours:\n * const result = minutesToHours(120)\n * //=> 2\n *\n * @example\n * // It uses floor rounding:\n * const result = minutesToHours(179)\n * //=> 2\n */\nexport default function minutesToHours(minutes) {\n requiredArgs(1, arguments);\n var hours = minutes / minutesInHour;\n return Math.floor(hours);\n}","import toInteger from \"../_lib/toInteger/index.js\";\nimport addMonths from \"../addMonths/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name subMonths\n * @category Month Helpers\n * @summary Subtract the specified number of months from the given date.\n *\n * @description\n * Subtract the specified number of months from the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of months to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} the new date with the months subtracted\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Subtract 5 months from 1 February 2015:\n * const result = subMonths(new Date(2015, 1, 1), 5)\n * //=> Mon Sep 01 2014 00:00:00\n */\nexport default function subMonths(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var amount = toInteger(dirtyAmount);\n return addMonths(dirtyDate, -amount);\n}","import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport subDays from \"../subDays/index.js\";\nimport subMonths from \"../subMonths/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\n/**\n * @name sub\n * @category Common Helpers\n * @summary Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.\n *\n * @description\n * Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Duration} duration - the object with years, months, weeks, days, hours, minutes and seconds to be subtracted\n *\n * | Key | Description |\n * |---------|------------------------------------|\n * | years | Amount of years to be subtracted |\n * | months | Amount of months to be subtracted |\n * | weeks | Amount of weeks to be subtracted |\n * | days | Amount of days to be subtracted |\n * | hours | Amount of hours to be subtracted |\n * | minutes | Amount of minutes to be subtracted |\n * | seconds | Amount of seconds to be subtracted |\n *\n * All values default to 0\n *\n * @returns {Date} the new date with the seconds subtracted\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Subtract the following duration from 15 June 2017 15:29:20\n * const result = sub(new Date(2017, 5, 15, 15, 29, 20), {\n * years: 2,\n * months: 9,\n * weeks: 1,\n * days: 7,\n * hours: 5,\n * minutes: 9,\n * seconds: 30\n * })\n * //=> Mon Sep 1 2014 10:19:50\n */\nexport default function sub(date, duration) {\n requiredArgs(2, arguments);\n if (!duration || _typeof(duration) !== 'object') return new Date(NaN);\n var years = duration.years ? toInteger(duration.years) : 0;\n var months = duration.months ? toInteger(duration.months) : 0;\n var weeks = duration.weeks ? toInteger(duration.weeks) : 0;\n var days = duration.days ? toInteger(duration.days) : 0;\n var hours = duration.hours ? toInteger(duration.hours) : 0;\n var minutes = duration.minutes ? toInteger(duration.minutes) : 0;\n var seconds = duration.seconds ? toInteger(duration.seconds) : 0;\n\n // Subtract years and months\n var dateWithoutMonths = subMonths(date, months + years * 12);\n\n // Subtract weeks and days\n var dateWithoutDays = subDays(dateWithoutMonths, days + weeks * 7);\n\n // Subtract hours, minutes and seconds\n var minutestoSub = minutes + hours * 60;\n var secondstoSub = seconds + minutestoSub * 60;\n var mstoSub = secondstoSub * 1000;\n var finalDate = new Date(dateWithoutDays.getTime() - mstoSub);\n return finalDate;\n}","import { getTime, getUnixTime, sub } from 'date-fns'\n\nimport {\n ceilToNearestTimeGrain,\n floorToNearestTimeGrain,\n Granularities,\n granularityMsToQuery,\n} from './granularity'\nimport { DruidGranularity, GranularityKeys, QueryTime } from './types'\nimport { Timeframe } from './timeframes'\n\nabstract class BaseQueryTime implements QueryTime {\n protected readonly timeframe: Timeframe\n\n constructor(timeframe: Timeframe) {\n // This is basically an abstract class.\n if (this.constructor === BaseQueryTime) {\n throw new Error('BaseQueryTime is not meant to be used directly.')\n }\n\n this.timeframe = timeframe\n }\n\n abstract startDate(): Date\n\n abstract endDate(): Date\n\n abstract granularityMs(): number\n\n protected calculateStartDate(isRelative: boolean, granularity: GranularityKeys, periods = 1) {\n // `periods` is greater than 1 if we're doing a delta time query.\n if (isRelative) {\n return new Date(this.endDate().getTime() - this.timeframe.timeframeLengthMs() * periods)\n } else {\n // Custom timeframes need special handling since it's hard to calculate the timeframe length.\n // For example, a custom timeframe that starts on 1/1 and ends on 1/1 has a length of 1 day, not 0.\n const ceilEnd = this.endDate()\n const floorStart = floorToNearestTimeGrain(this.timeframe.rawStart(), granularity)\n const timeframeLengthMs = ceilEnd.getTime() - floorStart.getTime()\n const periodOffset = timeframeLengthMs * (periods - 1)\n\n return floorToNearestTimeGrain(\n new Date(this.timeframe.rawStart().getTime() - periodOffset),\n granularity,\n )\n }\n }\n\n granularitySeconds(): number {\n return Math.floor(this.granularityMs() / 1000)\n }\n\n granularityDruid(): DruidGranularity | null {\n return granularityMsToQuery(this.granularityMs(), this.startDate().toISOString())\n }\n\n // Return a UNIX timestamp suitable for use in the `start` query param.\n startSeconds(): number {\n return getUnixTime(this.startDate())\n }\n\n // Return a UNIX timestamp suitable for use in the `end` query param.\n endSeconds(): number {\n return getUnixTime(this.endDate())\n }\n\n // Return epoch time in milliseconds, suitable for use in the `startMs` query param.\n startMs(): number {\n return getTime(this.startDate())\n }\n\n // Return epoch time in milliseconds, suitable for use in the `endMs` query param.\n endMs(): number {\n return getTime(this.endDate())\n }\n\n // Return whether the timeframe's bounds are within the allotment for a free tier user.\n withinFreeTier(): boolean {\n return this.startDate() >= sub(new Date(), { days: 1 })\n }\n}\n\n// We expect to get back a number of values, depending on the selected timeframe and granularity.\nexport class TimeseriesQueryTime extends BaseQueryTime {\n private readonly granularity: GranularityKeys\n\n constructor(timeframe: Timeframe, granularity?: GranularityKeys) {\n super(timeframe)\n\n if (granularity && timeframe.allowedGranularities().has(granularity)) {\n this.granularity = granularity\n } else {\n this.granularity = timeframe.defaultResponseGranularity\n }\n }\n\n startDate(): Date {\n return this.calculateStartDate(this.timeframe.isRelative, this.granularity)\n }\n\n endDate(): Date {\n return ceilToNearestTimeGrain(this.timeframe.rawEnd(), this.granularity)\n }\n\n granularityMs(): number {\n return Granularities[this.granularity]\n }\n}\n\n// We expect to get back 1 value, such that we can just show a big number without any trend information.\nexport class UnaryQueryTime extends BaseQueryTime {\n startDate(): Date {\n return this.calculateStartDate(this.timeframe.isRelative, this.timeframe.dataGranularity)\n }\n\n endDate(): Date {\n return ceilToNearestTimeGrain(this.timeframe.rawEnd(), this.timeframe.dataGranularity)\n }\n\n granularityMs(): number {\n return this.endDate().getTime() - this.startDate().getTime()\n }\n}\n\n// We expect to get back 2 values, such that we can make a comparison between them.\n// Note that depending on the user's tier, they might not have permission to request double their current\n// timeframe to calculate a trend.\nexport class DeltaQueryTime extends UnaryQueryTime {\n startDate(): Date {\n return this.calculateStartDate(this.timeframe.isRelative, this.timeframe.dataGranularity, 2)\n }\n\n granularityMs(): number {\n // Note the `super` call -- the granularity for a DeltaQueryTime is the same as for an\n // equivalent UnaryQueryTime, despite the fact that the start time for a Delta query is earlier.\n return this.endDate().getTime() - super.startDate().getTime()\n }\n}\n","import {\n addDays,\n getDaysInMonth,\n hoursToSeconds,\n minutesToHours,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subMonths,\n} from 'date-fns'\n\nimport {\n DatePickerSelection,\n GranularityKeys,\n TimeframeKeys,\n TimeframeOptions,\n TimePeriod,\n} from './types'\n\nexport class Timeframe {\n readonly timeframeText: string\n\n readonly key: string\n\n readonly display: string\n\n readonly timeframeLength: () => number\n\n readonly allowedTiers: Array<string>\n\n // defaultResponseGranularity tracks which of the allowed granularities is picked for a given\n // timeframe if the user does not or cannot specify a granularity.\n readonly defaultResponseGranularity: GranularityKeys\n\n // dataGranularity tracks the granularity of the available data on the server for a specific timeframe.\n // As of writing, it's always the same as the default response granularity, but it may not always be.\n // It controls how timeframes are rounded to ensure complete time buckets from the server.\n readonly dataGranularity: GranularityKeys\n\n // isRelative impacts whether we take the `floor` or the `ceil` of the start time.\n // If the time range is relative, we want the ceil -- because we take the ceil of the\n // end time to make sure we're showing all the data we can for the last time bucket.\n // If the time range is absolute, we want the floor -- because otherwise we wouldn't be including\n // the first time bucket.\n readonly isRelative: boolean\n\n private _startCustom?: Date\n\n private _endCustom?: Date\n\n constructor(opts: TimeframeOptions) {\n this.display = opts.display\n this.timeframeText = opts.timeframeText\n this.key = opts.key\n this.timeframeLength = opts.timeframeLength\n this.allowedTiers = opts.allowedTiers\n this.defaultResponseGranularity = opts.defaultResponseGranularity\n this.dataGranularity = opts.dataGranularity\n this.isRelative = opts.isRelative\n this._startCustom = opts.startCustom\n this._endCustom = opts.endCustom\n }\n\n // rawEnd does not consider granularity and should not be used directly in queries.\n // Use `new QueryTime(timeframe, granularity?).queryEndSeconds()` instead.\n rawEnd(): Date {\n return this._endCustom || new Date()\n }\n\n // rawStart does not consider granularity and should not be used directly in queries.\n // Use `new QueryTime(timeframe, granularity?).queryStartSeconds()` instead.\n rawStart(): Date {\n return this._startCustom || new Date(this.rawEnd().getTime() - this.timeframeLengthMs())\n }\n\n timeframeLengthMs() {\n return this.timeframeLength() * 1000\n }\n\n maximumTimeframeLength() {\n // This is overriden in the variable-length subclasses.\n return this.timeframeLength()\n }\n\n allowedGranularities() {\n const allowedValues: Set<GranularityKeys> = new Set()\n const hours = this.maximumTimeframeLength() / 3600\n\n // Minutely is allowed for under 6 hours.\n if (hours <= 6) {\n allowedValues.add(GranularityKeys.MINUTELY)\n }\n\n // Hourly is allowed for 1 week and under, as long as it's more than just 1 hour.\n if (hours >= 2 && hours <= 7 * 24) {\n allowedValues.add(GranularityKeys.HOURLY)\n }\n\n // Daily is allowed for everything over 2 days.\n if (hours >= 2 * 24) {\n allowedValues.add(GranularityKeys.DAILY)\n }\n\n // Weekly is allowed for everything over 2 weeks.\n if (hours >= 2 * 24 * 14) {\n allowedValues.add(GranularityKeys.WEEKLY)\n }\n\n return allowedValues\n }\n}\n\nclass CurrentWeek extends Timeframe {\n rawStart(): Date {\n const thisMonday = startOfWeek(new Date(), { weekStartsOn: 1 })\n\n return thisMonday\n }\n\n maximumTimeframeLength() {\n return 60 * 60 * 24 * 7\n }\n}\n\nclass CurrentMonth extends Timeframe {\n rawStart(): Date {\n const firstOfTheMonth = startOfMonth(new Date())\n\n return firstOfTheMonth\n }\n\n maximumTimeframeLength() {\n return 60 * 60 * 24 * 31\n }\n}\n\nclass PreviousWeek extends Timeframe {\n rawEnd(): Date {\n const thisMonday = startOfWeek(new Date(), { weekStartsOn: 1 })\n\n return thisMonday\n }\n\n rawStart(): Date {\n const lastMonday = startOfWeek(new Date().setDate(new Date().getDate() - 7), {\n weekStartsOn: 1,\n })\n\n return lastMonday\n }\n}\n\nclass PreviousMonth extends Timeframe {\n rawEnd(): Date {\n const thisMonth = startOfMonth(new Date())\n\n return thisMonth\n }\n\n rawStart(): Date {\n const lastMonth = startOfMonth(new Date().setMonth(new Date().getMonth() - 1))\n\n return lastMonth\n }\n}\n\n// These TimePeriod definitions request a default granularity and can be adjusted\n//\n// Using <string, any> as a temp workaround for TimePeriods.get() potentially returning `undefined` lint issue.\n// This means we opt out of safety checks; similar to this workaround:\n// https://github.com/microsoft/TypeScript/issues/41045#issuecomment-706717682\n\nexport const TimePeriods = new Map<string, Timeframe>([\n [\n TimeframeKeys.FIFTEEN_MIN,\n new Timeframe({\n key: TimeframeKeys.FIFTEEN_MIN,\n display: 'Last 15 minutes',\n timeframeText: '15 minutes',\n timeframeLength: () => 60 * 15,\n defaultResponseGranularity: GranularityKeys.MINUTELY,\n dataGranularity: GranularityKeys.MINUTELY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.ONE_HOUR,\n new Timeframe({\n key: TimeframeKeys.ONE_HOUR,\n display: 'Last hour',\n timeframeText: 'One hour',\n timeframeLength: () => 60 * 60 * 1,\n defaultResponseGranularity: GranularityKeys.MINUTELY,\n dataGranularity: GranularityKeys.MINUTELY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.SIX_HOUR,\n new Timeframe({\n key: TimeframeKeys.SIX_HOUR,\n display: 'Last 6 hours',\n timeframeText: '6 hours',\n timeframeLength: () => 60 * 60 * 6,\n defaultResponseGranularity: GranularityKeys.HOURLY,\n dataGranularity: GranularityKeys.HOURLY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.TWELVE_HOUR,\n new Timeframe({\n key: TimeframeKeys.TWELVE_HOUR,\n display: 'Last 12 hours',\n timeframeText: '12 hours',\n timeframeLength: () => 60 * 60 * 12,\n defaultResponseGranularity: GranularityKeys.HOURLY,\n dataGranularity: GranularityKeys.HOURLY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.ONE_DAY,\n new Timeframe({\n key: TimeframeKeys.ONE_DAY,\n display: 'Last 24 hours',\n timeframeText: '24 hours',\n timeframeLength: () => 60 * 60 * 24,\n defaultResponseGranularity: GranularityKeys.HOURLY,\n dataGranularity: GranularityKeys.HOURLY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.SEVEN_DAY,\n new Timeframe({\n key: TimeframeKeys.SEVEN_DAY,\n display: 'Last 7 days',\n timeframeText: '7 days',\n timeframeLength: () => 60 * 60 * 24 * 7,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: true,\n allowedTiers: ['trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.THIRTY_DAY,\n new Timeframe({\n key: TimeframeKeys.THIRTY_DAY,\n display: 'Last 30 days',\n timeframeText: '30 days',\n timeframeLength: () => 60 * 60 * 24 * 30,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: true,\n allowedTiers: ['trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.CURRENT_WEEK,\n new CurrentWeek({\n key: TimeframeKeys.CURRENT_WEEK,\n display: 'This week',\n timeframeText: 'Week',\n timeframeLength: () => {\n // Monday -> now\n const prevMonday = startOfWeek(new Date(), { weekStartsOn: 1 })\n const end = startOfDay(addDays(new Date(), 1))\n\n return (end.getTime() - prevMonday.getTime()) / 1000\n },\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.CURRENT_MONTH,\n new CurrentMonth({\n key: TimeframeKeys.CURRENT_MONTH,\n display: 'This month',\n timeframeText: 'Month',\n timeframeLength: () => {\n // First of the month -> now\n const firstOfTheMonth = startOfMonth(new Date())\n const end = startOfDay(addDays(new Date(), 1))\n\n return (end.getTime() - firstOfTheMonth.getTime()) / 1000\n },\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.PREVIOUS_WEEK,\n new PreviousWeek({\n key: TimeframeKeys.PREVIOUS_WEEK,\n display: 'Previous week',\n timeframeText: 'Week',\n timeframeLength: () => 60 * 60 * 24 * 7,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.PREVIOUS_MONTH,\n new PreviousMonth({\n key: TimeframeKeys.PREVIOUS_MONTH,\n display: 'Previous month',\n timeframeText: 'Month',\n timeframeLength: () => {\n let offset = 0\n const end = startOfMonth(new Date())\n const start = startOfMonth(subMonths(new Date(), 1))\n if (end.getTimezoneOffset() !== start.getTimezoneOffset()) {\n offset = dstOffsetHours(end, start)\n }\n\n // Not all months have the same number of days.\n // Current month may be observing DST while previous is not\n // take this into account when calculating the timeframe length for previous month\n return (\n 60 * 60 * 24 * getDaysInMonth(new Date().setMonth(new Date().getMonth() - 1)) + hoursToSeconds(offset)\n )\n },\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n])\n\nexport function datePickerSelectionToTimeframe(datePickerSelection: DatePickerSelection): Timeframe {\n const start = new Date(datePickerSelection.start)\n const end = new Date(datePickerSelection.end)\n const timeframeLength = (end.getTime() - start.getTime()) / 1000\n\n const selectedTimePeriod =\n datePickerSelection.timePeriodsKey && TimePeriods.get(datePickerSelection.timePeriodsKey)\n\n // Note: for custom timeframes, the timeframeLength is approximate: due to rounding\n // based on granularity, the actual length will be slightly greater.\n\n return (\n selectedTimePeriod ||\n new Timeframe({\n key: 'custom',\n timeframeText: 'custom',\n display: 'custom',\n startCustom: start,\n endCustom: end,\n timeframeLength: () => timeframeLength,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['free', 'plus', 'enterprise'],\n })\n )\n}\n\nexport function timeframeToDatepickerSelection(timeframe: Timeframe): DatePickerSelection {\n // Only set `timePeriodsKey` if a relative time frame is chosen\n // Custom time ranges are denoted by the absence of this key\n return {\n ...(timeframe.key !== 'custom' && { timePeriodsKey: timeframe.key }),\n start: timeframe.rawStart(),\n end: timeframe.rawEnd(),\n }\n}\n\nexport function timeframeToDatepickerTimeperiod(timeframe: Timeframe): TimePeriod {\n // The datepicker needs `start` and `end` functions for its timeperiods.\n return {\n key: timeframe.key,\n display: timeframe.display,\n timeframeText: timeframe.timeframeText,\n timeframeLength: () => timeframe.key, // Used to generate test IDs for the Kongponent.\n start: () => timeframe.rawStart(),\n end: () => timeframe.rawEnd(),\n }\n}\n\nexport function dstOffsetHours(d1: Date, d2: Date): number {\n return minutesToHours(d1.getTimezoneOffset() - d2.getTimezoneOffset())\n}\n"],"names":["GranularityKeys","TimeframeKeys","ChartTypes","Granularities","granularitiesToOptions","values","i18n","v","granularityMsToQuery","granularity","origin","msToGranularity","ms","k","toNearestTimeGrain","op","date","granularityMs","tzOffsetMs","floorToNearestTimeGrain","ceilToNearestTimeGrain","_typeof","obj","toInteger","dirtyNumber","number","requiredArgs","required","args","toDate","argument","argStr","addDays","dirtyDate","dirtyAmount","amount","addMonths","dayOfMonth","endOfDesiredMonth","daysInMonth","defaultOptions","getDefaultOptions","startOfWeek","options","_ref","_ref2","_ref3","_options$weekStartsOn","_options$locale","_options$locale$optio","_defaultOptions$local","_defaultOptions$local2","weekStartsOn","day","diff","startOfDay","minutesInHour","secondsInHour","startOfMonth","getDaysInMonth","year","monthIndex","lastDayOfMonth","getTime","timestamp","getUnixTime","hoursToSeconds","hours","subDays","minutesToHours","minutes","subMonths","sub","duration","years","months","weeks","days","seconds","dateWithoutMonths","dateWithoutDays","minutestoSub","secondstoSub","mstoSub","finalDate","BaseQueryTime","timeframe","__publicField","isRelative","periods","ceilEnd","floorStart","periodOffset","TimeseriesQueryTime","UnaryQueryTime","DeltaQueryTime","Timeframe","opts","allowedValues","CurrentWeek","CurrentMonth","PreviousWeek","PreviousMonth","TimePeriods","prevMonday","firstOfTheMonth","offset","end","start","dstOffsetHours","datePickerSelectionToTimeframe","datePickerSelection","timeframeLength","timeframeToDatepickerSelection","timeframeToDatepickerTimeperiod","d1","d2"],"mappings":"wPACY,IAAAA,GAAAA,IACVA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAJCA,IAAAA,GAAA,CAAA,CAAA,ECAAC,GAAAA,IACVA,EAAA,YAAc,MACdA,EAAA,SAAW,KACXA,EAAA,SAAW,KACXA,EAAA,YAAc,MACdA,EAAA,QAAU,MACVA,EAAA,UAAY,KACZA,EAAA,WAAa,MACbA,EAAA,aAAe,eACf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,SAAS,EAC1B,IAAKA,EAAU,OAAO,CAAA,CAE1B,CAEO,SAAS4B,GAAgC5B,EAAkC,CAEzE,MAAA,CACL,IAAKA,EAAU,IACf,QAASA,EAAU,QACnB,cAAeA,EAAU,cACzB,gBAAiB,IAAMA,EAAU,IACjC,MAAO,IAAMA,EAAU,SAAS,EAChC,IAAK,IAAMA,EAAU,OAAO,CAAA,CAEhC,CAEgB,SAAAuB,EAAeM,EAAUC,EAAkB,CACzD,OAAO/C,EAAe8C,EAAG,kBAAsB,EAAAC,EAAG,mBAAmB,CACvE","x_google_ignoreList":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]}
1
+ {"version":3,"file":"vitals-utilities.cjs","sources":["../src/types/granularity-keys.ts","../src/types/timeframe-keys.ts","../src/types/chart-types.ts","../src/granularity.ts","../../../../node_modules/.pnpm/@babel+runtime@7.22.5/node_modules/@babel/runtime/helpers/esm/typeof.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/toInteger/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/requiredArgs/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/toDate/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addDays/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/addMonths/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/_lib/defaultOptions/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfWeek/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfDay/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/constants/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/startOfMonth/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/getDaysInMonth/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/getTime/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/getUnixTime/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/hoursToSeconds/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/subDays/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/minutesToHours/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/subMonths/index.js","../../../../node_modules/.pnpm/date-fns@2.30.0/node_modules/date-fns/esm/sub/index.js","../src/queryTime.ts","../src/timeframes.ts"],"sourcesContent":["/* eslint-disable no-unused-vars */\nexport enum GranularityKeys {\n MINUTELY = 'Minutely',\n HOURLY = 'Hourly',\n DAILY = 'Daily',\n WEEKLY = 'Weekly'\n}\n","/* eslint-disable no-unused-vars */\nexport enum TimeframeKeys {\n FIFTEEN_MIN = '15m',\n ONE_HOUR = '1h',\n SIX_HOUR = '6h',\n TWELVE_HOUR = '12h',\n ONE_DAY = '24h',\n SEVEN_DAY = '7d',\n THIRTY_DAY = '30d',\n CURRENT_WEEK = 'current_week',\n CURRENT_MONTH = 'current_month',\n CURRENT_QUARTER = 'current_quarter',\n PREVIOUS_WEEK = 'previous_week',\n PREVIOUS_MONTH = 'previous_month',\n PREVIOUS_QUARTER = 'previous_quarter'\n}\n","/* eslint-disable no-unused-vars */\nexport enum ChartTypes {\n DOUGHNUT = 'Doughnut',\n HORIZONTAL_BAR = 'HorizontalBar',\n VERTICAL_BAR = 'VerticalBar',\n TIMESERIES_LINE = 'Line',\n TIMESERIES_BAR = 'TimeSeriesBar'\n}\n","import { DruidGranularity, GranularityKeys } from './types'\n\n// Units are milliseconds, which are what Druid expects.\nexport const Granularities = {\n [GranularityKeys.MINUTELY]: 60 * 1000,\n [GranularityKeys.HOURLY]: 60 * 60 * 1000,\n [GranularityKeys.DAILY]: 60 * 60 * 24 * 1000,\n [GranularityKeys.WEEKLY]: 60 * 60 * 24 * 7 * 1000,\n}\n\nexport function granularitiesToOptions(\n values: GranularityKeys[],\n i18n: { t: (v: string) => string },\n) {\n return values.map((v) => ({\n value: v,\n label: i18n.t(`configuration.vitals.reports.granularity.${v}`),\n }))\n}\n\nexport function granularityMsToQuery(\n granularity: number | null,\n origin?: string,\n): DruidGranularity | null {\n if (granularity) {\n return {\n duration: granularity,\n type: 'duration',\n origin,\n }\n }\n\n return null\n}\n\nexport function msToGranularity(ms?: number): GranularityKeys | null {\n if (!ms) {\n return null\n }\n\n // Note that this folds weird granularity values into known values.\n const key = Object.values(GranularityKeys).find((k) => ms <= Granularities[k])\n\n return key || null\n}\n\nfunction toNearestTimeGrain(\n op: (x: number) => number,\n date: Date,\n granularity: GranularityKeys,\n): Date {\n // Days and weeks need special handling because naively trying to `ceil` or `floor` them results in a date ending\n // in midnight UTC, whereas as of now we want dates ending in midnight local time.\n // Note: right now we treat daily and weekly granularities the same way, because it's OK to request an\n // incomplete week (i.e., if it's currently Monday at noon, it's OK to request data up to Tuesday midnight for the current week).\n // Druid will just limit its query range accordingly.\n const granularityMs = Granularities[granularity]\n const tzOffsetMs =\n granularityMs >= Granularities[GranularityKeys.DAILY] ? date.getTimezoneOffset() * 60 * 1000 : 0\n\n return new Date(op((date.getTime() - tzOffsetMs) / granularityMs) * granularityMs + tzOffsetMs)\n}\n\nexport function floorToNearestTimeGrain(date: Date, granularity: GranularityKeys): Date {\n return toNearestTimeGrain(Math.floor, date, granularity)\n}\n\nexport function ceilToNearestTimeGrain(date: Date, granularity: GranularityKeys): Date {\n return toNearestTimeGrain(Math.ceil, date, granularity)\n}\n","export default function _typeof(obj) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) {\n return typeof obj;\n } : function (obj) {\n return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n }, _typeof(obj);\n}","export default function toInteger(dirtyNumber) {\n if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {\n return NaN;\n }\n var number = Number(dirtyNumber);\n if (isNaN(number)) {\n return number;\n }\n return number < 0 ? Math.ceil(number) : Math.floor(number);\n}","export default function requiredArgs(required, args) {\n if (args.length < required) {\n throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');\n }\n}","import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name toDate\n * @category Common Helpers\n * @summary Convert the given argument to an instance of Date.\n *\n * @description\n * Convert the given argument to an instance of Date.\n *\n * If the argument is an instance of Date, the function returns its clone.\n *\n * If the argument is a number, it is treated as a timestamp.\n *\n * If the argument is none of the above, the function returns Invalid Date.\n *\n * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.\n *\n * @param {Date|Number} argument - the value to convert\n * @returns {Date} the parsed date in the local time zone\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Clone the date:\n * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))\n * //=> Tue Feb 11 2014 11:30:30\n *\n * @example\n * // Convert the timestamp to date:\n * const result = toDate(1392098430000)\n * //=> Tue Feb 11 2014 11:30:30\n */\nexport default function toDate(argument) {\n requiredArgs(1, arguments);\n var argStr = Object.prototype.toString.call(argument);\n\n // Clone the date\n if (argument instanceof Date || _typeof(argument) === 'object' && argStr === '[object Date]') {\n // Prevent the date to lose the milliseconds when passed to new Date() in IE10\n return new Date(argument.getTime());\n } else if (typeof argument === 'number' || argStr === '[object Number]') {\n return new Date(argument);\n } else {\n if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(\"Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments\");\n // eslint-disable-next-line no-console\n console.warn(new Error().stack);\n }\n return new Date(NaN);\n }\n}","import toInteger from \"../_lib/toInteger/index.js\";\nimport toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name addDays\n * @category Day Helpers\n * @summary Add the specified number of days to the given date.\n *\n * @description\n * Add the specified number of days to the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} - the new date with the days added\n * @throws {TypeError} - 2 arguments required\n *\n * @example\n * // Add 10 days to 1 September 2014:\n * const result = addDays(new Date(2014, 8, 1), 10)\n * //=> Thu Sep 11 2014 00:00:00\n */\nexport default function addDays(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var date = toDate(dirtyDate);\n var amount = toInteger(dirtyAmount);\n if (isNaN(amount)) {\n return new Date(NaN);\n }\n if (!amount) {\n // If 0 days, no-op to avoid changing times in the hour before end of DST\n return date;\n }\n date.setDate(date.getDate() + amount);\n return date;\n}","import toInteger from \"../_lib/toInteger/index.js\";\nimport toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name addMonths\n * @category Month Helpers\n * @summary Add the specified number of months to the given date.\n *\n * @description\n * Add the specified number of months to the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of months to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} the new date with the months added\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Add 5 months to 1 September 2014:\n * const result = addMonths(new Date(2014, 8, 1), 5)\n * //=> Sun Feb 01 2015 00:00:00\n */\nexport default function addMonths(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var date = toDate(dirtyDate);\n var amount = toInteger(dirtyAmount);\n if (isNaN(amount)) {\n return new Date(NaN);\n }\n if (!amount) {\n // If 0 months, no-op to avoid changing times in the hour before end of DST\n return date;\n }\n var dayOfMonth = date.getDate();\n\n // The JS Date object supports date math by accepting out-of-bounds values for\n // month, day, etc. For example, new Date(2020, 0, 0) returns 31 Dec 2019 and\n // new Date(2020, 13, 1) returns 1 Feb 2021. This is *almost* the behavior we\n // want except that dates will wrap around the end of a month, meaning that\n // new Date(2020, 13, 31) will return 3 Mar 2021 not 28 Feb 2021 as desired. So\n // we'll default to the end of the desired month by adding 1 to the desired\n // month and using a date of 0 to back up one day to the end of the desired\n // month.\n var endOfDesiredMonth = new Date(date.getTime());\n endOfDesiredMonth.setMonth(date.getMonth() + amount + 1, 0);\n var daysInMonth = endOfDesiredMonth.getDate();\n if (dayOfMonth >= daysInMonth) {\n // If we're already at the end of the month, then this is the correct date\n // and we're done.\n return endOfDesiredMonth;\n } else {\n // Otherwise, we now know that setting the original day-of-month value won't\n // cause an overflow, so set the desired day-of-month. Note that we can't\n // just set the date of `endOfDesiredMonth` because that object may have had\n // its time changed in the unusual case where where a DST transition was on\n // the last day of the month and its local time was in the hour skipped or\n // repeated next to a DST transition. So we use `date` instead which is\n // guaranteed to still have the original time.\n date.setFullYear(endOfDesiredMonth.getFullYear(), endOfDesiredMonth.getMonth(), dayOfMonth);\n return date;\n }\n}","var defaultOptions = {};\nexport function getDefaultOptions() {\n return defaultOptions;\n}\nexport function setDefaultOptions(newOptions) {\n defaultOptions = newOptions;\n}","import toDate from \"../toDate/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { getDefaultOptions } from \"../_lib/defaultOptions/index.js\";\n/**\n * @name startOfWeek\n * @category Week Helpers\n * @summary Return the start of a week for the given date.\n *\n * @description\n * Return the start of a week for the given date.\n * The result will be in the local timezone.\n *\n * @param {Date|Number} date - the original date\n * @param {Object} [options] - an object with options.\n * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}\n * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)\n * @returns {Date} the start of a week\n * @throws {TypeError} 1 argument required\n * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6\n *\n * @example\n * // The start of a week for 2 September 2014 11:55:00:\n * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Sun Aug 31 2014 00:00:00\n *\n * @example\n * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:\n * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })\n * //=> Mon Sep 01 2014 00:00:00\n */\nexport default function startOfWeek(dirtyDate, options) {\n var _ref, _ref2, _ref3, _options$weekStartsOn, _options$locale, _options$locale$optio, _defaultOptions$local, _defaultOptions$local2;\n requiredArgs(1, arguments);\n var defaultOptions = getDefaultOptions();\n var weekStartsOn = toInteger((_ref = (_ref2 = (_ref3 = (_options$weekStartsOn = options === null || options === void 0 ? void 0 : options.weekStartsOn) !== null && _options$weekStartsOn !== void 0 ? _options$weekStartsOn : options === null || options === void 0 ? void 0 : (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : (_options$locale$optio = _options$locale.options) === null || _options$locale$optio === void 0 ? void 0 : _options$locale$optio.weekStartsOn) !== null && _ref3 !== void 0 ? _ref3 : defaultOptions.weekStartsOn) !== null && _ref2 !== void 0 ? _ref2 : (_defaultOptions$local = defaultOptions.locale) === null || _defaultOptions$local === void 0 ? void 0 : (_defaultOptions$local2 = _defaultOptions$local.options) === null || _defaultOptions$local2 === void 0 ? void 0 : _defaultOptions$local2.weekStartsOn) !== null && _ref !== void 0 ? _ref : 0);\n\n // Test if weekStartsOn is between 0 and 6 _and_ is not NaN\n if (!(weekStartsOn >= 0 && weekStartsOn <= 6)) {\n throw new RangeError('weekStartsOn must be between 0 and 6 inclusively');\n }\n var date = toDate(dirtyDate);\n var day = date.getDay();\n var diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;\n date.setDate(date.getDate() - diff);\n date.setHours(0, 0, 0, 0);\n return date;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name startOfDay\n * @category Day Helpers\n * @summary Return the start of a day for the given date.\n *\n * @description\n * Return the start of a day for the given date.\n * The result will be in the local timezone.\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the start of a day\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The start of a day for 2 September 2014 11:55:00:\n * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Tue Sep 02 2014 00:00:00\n */\nexport default function startOfDay(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n date.setHours(0, 0, 0, 0);\n return date;\n}","/**\n * Days in 1 week.\n *\n * @name daysInWeek\n * @constant\n * @type {number}\n * @default\n */\nexport var daysInWeek = 7;\n\n/**\n * Days in 1 year\n * One years equals 365.2425 days according to the formula:\n *\n * > Leap year occures every 4 years, except for years that are divisable by 100 and not divisable by 400.\n * > 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days\n *\n * @name daysInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var daysInYear = 365.2425;\n\n/**\n * Maximum allowed time.\n *\n * @name maxTime\n * @constant\n * @type {number}\n * @default\n */\nexport var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1000;\n\n/**\n * Milliseconds in 1 minute\n *\n * @name millisecondsInMinute\n * @constant\n * @type {number}\n * @default\n */\nexport var millisecondsInMinute = 60000;\n\n/**\n * Milliseconds in 1 hour\n *\n * @name millisecondsInHour\n * @constant\n * @type {number}\n * @default\n */\nexport var millisecondsInHour = 3600000;\n\n/**\n * Milliseconds in 1 second\n *\n * @name millisecondsInSecond\n * @constant\n * @type {number}\n * @default\n */\nexport var millisecondsInSecond = 1000;\n\n/**\n * Minimum allowed time.\n *\n * @name minTime\n * @constant\n * @type {number}\n * @default\n */\nexport var minTime = -maxTime;\n\n/**\n * Minutes in 1 hour\n *\n * @name minutesInHour\n * @constant\n * @type {number}\n * @default\n */\nexport var minutesInHour = 60;\n\n/**\n * Months in 1 quarter\n *\n * @name monthsInQuarter\n * @constant\n * @type {number}\n * @default\n */\nexport var monthsInQuarter = 3;\n\n/**\n * Months in 1 year\n *\n * @name monthsInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var monthsInYear = 12;\n\n/**\n * Quarters in 1 year\n *\n * @name quartersInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var quartersInYear = 4;\n\n/**\n * Seconds in 1 hour\n *\n * @name secondsInHour\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInHour = 3600;\n\n/**\n * Seconds in 1 minute\n *\n * @name secondsInMinute\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInMinute = 60;\n\n/**\n * Seconds in 1 day\n *\n * @name secondsInDay\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInDay = secondsInHour * 24;\n\n/**\n * Seconds in 1 week\n *\n * @name secondsInWeek\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInWeek = secondsInDay * 7;\n\n/**\n * Seconds in 1 year\n *\n * @name secondsInYear\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInYear = secondsInDay * daysInYear;\n\n/**\n * Seconds in 1 month\n *\n * @name secondsInMonth\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInMonth = secondsInYear / 12;\n\n/**\n * Seconds in 1 quarter\n *\n * @name secondsInQuarter\n * @constant\n * @type {number}\n * @default\n */\nexport var secondsInQuarter = secondsInMonth * 3;","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name startOfMonth\n * @category Month Helpers\n * @summary Return the start of a month for the given date.\n *\n * @description\n * Return the start of a month for the given date.\n * The result will be in the local timezone.\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the start of a month\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The start of a month for 2 September 2014 11:55:00:\n * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Mon Sep 01 2014 00:00:00\n */\nexport default function startOfMonth(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n date.setDate(1);\n date.setHours(0, 0, 0, 0);\n return date;\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name getDaysInMonth\n * @category Month Helpers\n * @summary Get the number of days in a month of the given date.\n *\n * @description\n * Get the number of days in a month of the given date.\n *\n * @param {Date|Number} date - the given date\n * @returns {Number} the number of days in a month\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // How many days are in February 2000?\n * const result = getDaysInMonth(new Date(2000, 1))\n * //=> 29\n */\nexport default function getDaysInMonth(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n var year = date.getFullYear();\n var monthIndex = date.getMonth();\n var lastDayOfMonth = new Date(0);\n lastDayOfMonth.setFullYear(year, monthIndex + 1, 0);\n lastDayOfMonth.setHours(0, 0, 0, 0);\n return lastDayOfMonth.getDate();\n}","import toDate from \"../toDate/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name getTime\n * @category Timestamp Helpers\n * @summary Get the milliseconds timestamp of the given date.\n *\n * @description\n * Get the milliseconds timestamp of the given date.\n *\n * @param {Date|Number} date - the given date\n * @returns {Number} the timestamp\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Get the timestamp of 29 February 2012 11:45:05.123:\n * const result = getTime(new Date(2012, 1, 29, 11, 45, 5, 123))\n * //=> 1330515905123\n */\nexport default function getTime(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n var timestamp = date.getTime();\n return timestamp;\n}","import getTime from \"../getTime/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name getUnixTime\n * @category Timestamp Helpers\n * @summary Get the seconds timestamp of the given date.\n *\n * @description\n * Get the seconds timestamp of the given date.\n *\n * @param {Date|Number} date - the given date\n * @returns {Number} the timestamp\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Get the timestamp of 29 February 2012 11:45:05 CET:\n * const result = getUnixTime(new Date(2012, 1, 29, 11, 45, 5))\n * //=> 1330512305\n */\nexport default function getUnixTime(dirtyDate) {\n requiredArgs(1, arguments);\n return Math.floor(getTime(dirtyDate) / 1000);\n}","import requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { secondsInHour } from \"../constants/index.js\";\n/**\n * @name hoursToSeconds\n * @category Conversion Helpers\n * @summary Convert hours to seconds.\n *\n * @description\n * Convert a number of hours to a full number of seconds.\n *\n * @param {number} hours - number of hours to be converted\n *\n * @returns {number} the number of hours converted in seconds\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Convert 2 hours to seconds:\n * const result = hoursToSeconds(2)\n * //=> 7200\n */\nexport default function hoursToSeconds(hours) {\n requiredArgs(1, arguments);\n return Math.floor(hours * secondsInHour);\n}","import addDays from \"../addDays/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\n/**\n * @name subDays\n * @category Day Helpers\n * @summary Subtract the specified number of days from the given date.\n *\n * @description\n * Subtract the specified number of days from the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} the new date with the days subtracted\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Subtract 10 days from 1 September 2014:\n * const result = subDays(new Date(2014, 8, 1), 10)\n * //=> Fri Aug 22 2014 00:00:00\n */\nexport default function subDays(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var amount = toInteger(dirtyAmount);\n return addDays(dirtyDate, -amount);\n}","import requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport { minutesInHour } from \"../constants/index.js\";\n/**\n * @name minutesToHours\n * @category Conversion Helpers\n * @summary Convert minutes to hours.\n *\n * @description\n * Convert a number of minutes to a full number of hours.\n *\n * @param {number} minutes - number of minutes to be converted\n *\n * @returns {number} the number of minutes converted in hours\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // Convert 140 minutes to hours:\n * const result = minutesToHours(120)\n * //=> 2\n *\n * @example\n * // It uses floor rounding:\n * const result = minutesToHours(179)\n * //=> 2\n */\nexport default function minutesToHours(minutes) {\n requiredArgs(1, arguments);\n var hours = minutes / minutesInHour;\n return Math.floor(hours);\n}","import toInteger from \"../_lib/toInteger/index.js\";\nimport addMonths from \"../addMonths/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\n/**\n * @name subMonths\n * @category Month Helpers\n * @summary Subtract the specified number of months from the given date.\n *\n * @description\n * Subtract the specified number of months from the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Number} amount - the amount of months to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.\n * @returns {Date} the new date with the months subtracted\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Subtract 5 months from 1 February 2015:\n * const result = subMonths(new Date(2015, 1, 1), 5)\n * //=> Mon Sep 01 2014 00:00:00\n */\nexport default function subMonths(dirtyDate, dirtyAmount) {\n requiredArgs(2, arguments);\n var amount = toInteger(dirtyAmount);\n return addMonths(dirtyDate, -amount);\n}","import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport subDays from \"../subDays/index.js\";\nimport subMonths from \"../subMonths/index.js\";\nimport requiredArgs from \"../_lib/requiredArgs/index.js\";\nimport toInteger from \"../_lib/toInteger/index.js\";\n/**\n * @name sub\n * @category Common Helpers\n * @summary Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.\n *\n * @description\n * Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.\n *\n * @param {Date|Number} date - the date to be changed\n * @param {Duration} duration - the object with years, months, weeks, days, hours, minutes and seconds to be subtracted\n *\n * | Key | Description |\n * |---------|------------------------------------|\n * | years | Amount of years to be subtracted |\n * | months | Amount of months to be subtracted |\n * | weeks | Amount of weeks to be subtracted |\n * | days | Amount of days to be subtracted |\n * | hours | Amount of hours to be subtracted |\n * | minutes | Amount of minutes to be subtracted |\n * | seconds | Amount of seconds to be subtracted |\n *\n * All values default to 0\n *\n * @returns {Date} the new date with the seconds subtracted\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // Subtract the following duration from 15 June 2017 15:29:20\n * const result = sub(new Date(2017, 5, 15, 15, 29, 20), {\n * years: 2,\n * months: 9,\n * weeks: 1,\n * days: 7,\n * hours: 5,\n * minutes: 9,\n * seconds: 30\n * })\n * //=> Mon Sep 1 2014 10:19:50\n */\nexport default function sub(date, duration) {\n requiredArgs(2, arguments);\n if (!duration || _typeof(duration) !== 'object') return new Date(NaN);\n var years = duration.years ? toInteger(duration.years) : 0;\n var months = duration.months ? toInteger(duration.months) : 0;\n var weeks = duration.weeks ? toInteger(duration.weeks) : 0;\n var days = duration.days ? toInteger(duration.days) : 0;\n var hours = duration.hours ? toInteger(duration.hours) : 0;\n var minutes = duration.minutes ? toInteger(duration.minutes) : 0;\n var seconds = duration.seconds ? toInteger(duration.seconds) : 0;\n\n // Subtract years and months\n var dateWithoutMonths = subMonths(date, months + years * 12);\n\n // Subtract weeks and days\n var dateWithoutDays = subDays(dateWithoutMonths, days + weeks * 7);\n\n // Subtract hours, minutes and seconds\n var minutestoSub = minutes + hours * 60;\n var secondstoSub = seconds + minutestoSub * 60;\n var mstoSub = secondstoSub * 1000;\n var finalDate = new Date(dateWithoutDays.getTime() - mstoSub);\n return finalDate;\n}","import { getTime, getUnixTime, sub } from 'date-fns'\n\nimport {\n ceilToNearestTimeGrain,\n floorToNearestTimeGrain,\n Granularities,\n granularityMsToQuery,\n} from './granularity'\nimport { DruidGranularity, GranularityKeys, QueryTime } from './types'\nimport { Timeframe } from './timeframes'\n\nabstract class BaseQueryTime implements QueryTime {\n protected readonly timeframe: Timeframe\n\n constructor(timeframe: Timeframe) {\n // This is basically an abstract class.\n if (this.constructor === BaseQueryTime) {\n throw new Error('BaseQueryTime is not meant to be used directly.')\n }\n\n this.timeframe = timeframe\n }\n\n abstract startDate(): Date\n\n abstract endDate(): Date\n\n abstract granularityMs(): number\n\n protected calculateStartDate(isRelative: boolean, granularity: GranularityKeys, periods = 1) {\n // `periods` is greater than 1 if we're doing a delta time query.\n if (isRelative) {\n return new Date(this.endDate().getTime() - this.timeframe.timeframeLengthMs() * periods)\n } else {\n // Custom timeframes need special handling since it's hard to calculate the timeframe length.\n // For example, a custom timeframe that starts on 1/1 and ends on 1/1 has a length of 1 day, not 0.\n const ceilEnd = this.endDate()\n const floorStart = floorToNearestTimeGrain(this.timeframe.rawStart(), granularity)\n const timeframeLengthMs = ceilEnd.getTime() - floorStart.getTime()\n const periodOffset = timeframeLengthMs * (periods - 1)\n\n return floorToNearestTimeGrain(\n new Date(this.timeframe.rawStart().getTime() - periodOffset),\n granularity,\n )\n }\n }\n\n granularitySeconds(): number {\n return Math.floor(this.granularityMs() / 1000)\n }\n\n granularityDruid(): DruidGranularity | null {\n return granularityMsToQuery(this.granularityMs(), this.startDate().toISOString())\n }\n\n // Return a UNIX timestamp suitable for use in the `start` query param.\n startSeconds(): number {\n return getUnixTime(this.startDate())\n }\n\n // Return a UNIX timestamp suitable for use in the `end` query param.\n endSeconds(): number {\n return getUnixTime(this.endDate())\n }\n\n // Return epoch time in milliseconds, suitable for use in the `startMs` query param.\n startMs(): number {\n return getTime(this.startDate())\n }\n\n // Return epoch time in milliseconds, suitable for use in the `endMs` query param.\n endMs(): number {\n return getTime(this.endDate())\n }\n\n // Return whether the timeframe's bounds are within the allotment for a free tier user.\n withinFreeTier(): boolean {\n return this.startDate() >= sub(new Date(), { days: 1 })\n }\n}\n\n// We expect to get back a number of values, depending on the selected timeframe and granularity.\nexport class TimeseriesQueryTime extends BaseQueryTime {\n private readonly granularity: GranularityKeys\n\n constructor(timeframe: Timeframe, granularity?: GranularityKeys) {\n super(timeframe)\n\n if (granularity && timeframe.allowedGranularities().has(granularity)) {\n this.granularity = granularity\n } else {\n this.granularity = timeframe.defaultResponseGranularity\n }\n }\n\n startDate(): Date {\n return this.calculateStartDate(this.timeframe.isRelative, this.granularity)\n }\n\n endDate(): Date {\n return ceilToNearestTimeGrain(this.timeframe.rawEnd(), this.granularity)\n }\n\n granularityMs(): number {\n return Granularities[this.granularity]\n }\n}\n\n// We expect to get back 1 value, such that we can just show a big number without any trend information.\nexport class UnaryQueryTime extends BaseQueryTime {\n startDate(): Date {\n return this.calculateStartDate(this.timeframe.isRelative, this.timeframe.dataGranularity)\n }\n\n endDate(): Date {\n return ceilToNearestTimeGrain(this.timeframe.rawEnd(), this.timeframe.dataGranularity)\n }\n\n granularityMs(): number {\n return this.endDate().getTime() - this.startDate().getTime()\n }\n}\n\n// We expect to get back 2 values, such that we can make a comparison between them.\n// Note that depending on the user's tier, they might not have permission to request double their current\n// timeframe to calculate a trend.\nexport class DeltaQueryTime extends UnaryQueryTime {\n startDate(): Date {\n return this.calculateStartDate(this.timeframe.isRelative, this.timeframe.dataGranularity, 2)\n }\n\n granularityMs(): number {\n // Note the `super` call -- the granularity for a DeltaQueryTime is the same as for an\n // equivalent UnaryQueryTime, despite the fact that the start time for a Delta query is earlier.\n return this.endDate().getTime() - super.startDate().getTime()\n }\n}\n","import {\n addDays,\n getDaysInMonth,\n hoursToSeconds,\n minutesToHours,\n startOfDay,\n startOfMonth,\n startOfWeek,\n subMonths,\n} from 'date-fns'\n\nimport {\n DatePickerSelection,\n GranularityKeys,\n TimeframeKeys,\n TimeframeOptions,\n TimePeriod,\n} from './types'\n\nexport class Timeframe {\n readonly timeframeText: string\n\n readonly key: string\n\n readonly display: string\n\n readonly timeframeLength: () => number\n\n readonly allowedTiers: Array<string>\n\n // defaultResponseGranularity tracks which of the allowed granularities is picked for a given\n // timeframe if the user does not or cannot specify a granularity.\n readonly defaultResponseGranularity: GranularityKeys\n\n // dataGranularity tracks the granularity of the available data on the server for a specific timeframe.\n // As of writing, it's always the same as the default response granularity, but it may not always be.\n // It controls how timeframes are rounded to ensure complete time buckets from the server.\n readonly dataGranularity: GranularityKeys\n\n // isRelative impacts whether we take the `floor` or the `ceil` of the start time.\n // If the time range is relative, we want the ceil -- because we take the ceil of the\n // end time to make sure we're showing all the data we can for the last time bucket.\n // If the time range is absolute, we want the floor -- because otherwise we wouldn't be including\n // the first time bucket.\n readonly isRelative: boolean\n\n private _startCustom?: Date\n\n private _endCustom?: Date\n\n constructor(opts: TimeframeOptions) {\n this.display = opts.display\n this.timeframeText = opts.timeframeText\n this.key = opts.key\n this.timeframeLength = opts.timeframeLength\n this.allowedTiers = opts.allowedTiers\n this.defaultResponseGranularity = opts.defaultResponseGranularity\n this.dataGranularity = opts.dataGranularity\n this.isRelative = opts.isRelative\n this._startCustom = opts.startCustom\n this._endCustom = opts.endCustom\n }\n\n // rawEnd does not consider granularity and should not be used directly in queries.\n // Use `new QueryTime(timeframe, granularity?).queryEndSeconds()` instead.\n rawEnd(): Date {\n return this._endCustom || new Date()\n }\n\n // rawStart does not consider granularity and should not be used directly in queries.\n // Use `new QueryTime(timeframe, granularity?).queryStartSeconds()` instead.\n rawStart(): Date {\n return this._startCustom || new Date(this.rawEnd().getTime() - this.timeframeLengthMs())\n }\n\n timeframeLengthMs() {\n return this.timeframeLength() * 1000\n }\n\n maximumTimeframeLength() {\n // This is overriden in the variable-length subclasses.\n return this.timeframeLength()\n }\n\n allowedGranularities() {\n const allowedValues: Set<GranularityKeys> = new Set()\n const hours = this.maximumTimeframeLength() / 3600\n\n // Minutely is allowed for under 6 hours.\n if (hours <= 6) {\n allowedValues.add(GranularityKeys.MINUTELY)\n }\n\n // Hourly is allowed for 1 week and under, as long as it's more than just 1 hour.\n if (hours >= 2 && hours <= 7 * 24) {\n allowedValues.add(GranularityKeys.HOURLY)\n }\n\n // Daily is allowed for everything over 2 days.\n if (hours >= 2 * 24) {\n allowedValues.add(GranularityKeys.DAILY)\n }\n\n // Weekly is allowed for everything over 2 weeks.\n if (hours >= 2 * 24 * 14) {\n allowedValues.add(GranularityKeys.WEEKLY)\n }\n\n return allowedValues\n }\n}\n\nclass CurrentWeek extends Timeframe {\n rawStart(): Date {\n const thisMonday = startOfWeek(new Date(), { weekStartsOn: 1 })\n\n return thisMonday\n }\n\n maximumTimeframeLength() {\n return 60 * 60 * 24 * 7\n }\n}\n\nclass CurrentMonth extends Timeframe {\n rawStart(): Date {\n const firstOfTheMonth = startOfMonth(new Date())\n\n return firstOfTheMonth\n }\n\n maximumTimeframeLength() {\n return 60 * 60 * 24 * 31\n }\n}\n\nclass PreviousWeek extends Timeframe {\n rawEnd(): Date {\n const thisMonday = startOfWeek(new Date(), { weekStartsOn: 1 })\n\n return thisMonday\n }\n\n rawStart(): Date {\n const lastMonday = startOfWeek(new Date().setDate(new Date().getDate() - 7), {\n weekStartsOn: 1,\n })\n\n return lastMonday\n }\n}\n\nclass PreviousMonth extends Timeframe {\n rawEnd(): Date {\n const thisMonth = startOfMonth(new Date())\n\n return thisMonth\n }\n\n rawStart(): Date {\n const lastMonth = startOfMonth(subMonths(new Date(), 1))\n\n return lastMonth\n }\n}\n\n// These TimePeriod definitions request a default granularity and can be adjusted\n//\n// Using <string, any> as a temp workaround for TimePeriods.get() potentially returning `undefined` lint issue.\n// This means we opt out of safety checks; similar to this workaround:\n// https://github.com/microsoft/TypeScript/issues/41045#issuecomment-706717682\n\nexport const TimePeriods = new Map<string, Timeframe>([\n [\n TimeframeKeys.FIFTEEN_MIN,\n new Timeframe({\n key: TimeframeKeys.FIFTEEN_MIN,\n display: 'Last 15 minutes',\n timeframeText: '15 minutes',\n timeframeLength: () => 60 * 15,\n defaultResponseGranularity: GranularityKeys.MINUTELY,\n dataGranularity: GranularityKeys.MINUTELY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.ONE_HOUR,\n new Timeframe({\n key: TimeframeKeys.ONE_HOUR,\n display: 'Last hour',\n timeframeText: 'One hour',\n timeframeLength: () => 60 * 60 * 1,\n defaultResponseGranularity: GranularityKeys.MINUTELY,\n dataGranularity: GranularityKeys.MINUTELY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.SIX_HOUR,\n new Timeframe({\n key: TimeframeKeys.SIX_HOUR,\n display: 'Last 6 hours',\n timeframeText: '6 hours',\n timeframeLength: () => 60 * 60 * 6,\n defaultResponseGranularity: GranularityKeys.HOURLY,\n dataGranularity: GranularityKeys.HOURLY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.TWELVE_HOUR,\n new Timeframe({\n key: TimeframeKeys.TWELVE_HOUR,\n display: 'Last 12 hours',\n timeframeText: '12 hours',\n timeframeLength: () => 60 * 60 * 12,\n defaultResponseGranularity: GranularityKeys.HOURLY,\n dataGranularity: GranularityKeys.HOURLY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.ONE_DAY,\n new Timeframe({\n key: TimeframeKeys.ONE_DAY,\n display: 'Last 24 hours',\n timeframeText: '24 hours',\n timeframeLength: () => 60 * 60 * 24,\n defaultResponseGranularity: GranularityKeys.HOURLY,\n dataGranularity: GranularityKeys.HOURLY,\n isRelative: true,\n allowedTiers: ['free', 'trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.SEVEN_DAY,\n new Timeframe({\n key: TimeframeKeys.SEVEN_DAY,\n display: 'Last 7 days',\n timeframeText: '7 days',\n timeframeLength: () => 60 * 60 * 24 * 7,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: true,\n allowedTiers: ['trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.THIRTY_DAY,\n new Timeframe({\n key: TimeframeKeys.THIRTY_DAY,\n display: 'Last 30 days',\n timeframeText: '30 days',\n timeframeLength: () => 60 * 60 * 24 * 30,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: true,\n allowedTiers: ['trial', 'plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.CURRENT_WEEK,\n new CurrentWeek({\n key: TimeframeKeys.CURRENT_WEEK,\n display: 'This week',\n timeframeText: 'Week',\n timeframeLength: () => {\n // Monday -> now\n const prevMonday = startOfWeek(new Date(), { weekStartsOn: 1 })\n const end = startOfDay(addDays(new Date(), 1))\n\n return (end.getTime() - prevMonday.getTime()) / 1000\n },\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.CURRENT_MONTH,\n new CurrentMonth({\n key: TimeframeKeys.CURRENT_MONTH,\n display: 'This month',\n timeframeText: 'Month',\n timeframeLength: () => {\n // First of the month -> now\n const firstOfTheMonth = startOfMonth(new Date())\n const end = startOfDay(addDays(new Date(), 1))\n\n return (end.getTime() - firstOfTheMonth.getTime()) / 1000\n },\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.PREVIOUS_WEEK,\n new PreviousWeek({\n key: TimeframeKeys.PREVIOUS_WEEK,\n display: 'Previous week',\n timeframeText: 'Week',\n timeframeLength: () => 60 * 60 * 24 * 7,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n [\n TimeframeKeys.PREVIOUS_MONTH,\n new PreviousMonth({\n key: TimeframeKeys.PREVIOUS_MONTH,\n display: 'Previous month',\n timeframeText: 'Month',\n timeframeLength: () => {\n let offset = 0\n const end = startOfMonth(new Date())\n const start = startOfMonth(subMonths(new Date(), 1))\n if (end.getTimezoneOffset() !== start.getTimezoneOffset()) {\n offset = dstOffsetHours(end, start)\n }\n\n // Not all months have the same number of days.\n // Current month may be observing DST while previous is not\n // take this into account when calculating the timeframe length for previous month\n return (\n 60 * 60 * 24 * getDaysInMonth(new Date().setMonth(new Date().getMonth() - 1)) + hoursToSeconds(offset)\n )\n },\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['plus', 'enterprise'],\n }),\n ],\n])\n\nexport function datePickerSelectionToTimeframe(datePickerSelection: DatePickerSelection): Timeframe {\n const start = new Date(datePickerSelection.start)\n const end = new Date(datePickerSelection.end)\n const timeframeLength = (end.getTime() - start.getTime()) / 1000\n\n const selectedTimePeriod =\n datePickerSelection.timePeriodsKey && TimePeriods.get(datePickerSelection.timePeriodsKey)\n\n // Note: for custom timeframes, the timeframeLength is approximate: due to rounding\n // based on granularity, the actual length will be slightly greater.\n\n return (\n selectedTimePeriod ||\n new Timeframe({\n key: 'custom',\n timeframeText: 'custom',\n display: 'custom',\n startCustom: start,\n endCustom: end,\n timeframeLength: () => timeframeLength,\n defaultResponseGranularity: GranularityKeys.DAILY,\n dataGranularity: GranularityKeys.DAILY,\n isRelative: false,\n allowedTiers: ['free', 'plus', 'enterprise'],\n })\n )\n}\n\nexport function timeframeToDatepickerSelection(timeframe: Timeframe): DatePickerSelection {\n // Only set `timePeriodsKey` if a relative time frame is chosen\n // Custom time ranges are denoted by the absence of this key\n return {\n ...(timeframe.key !== 'custom' && { timePeriodsKey: timeframe.key }),\n start: timeframe.rawStart(),\n end: timeframe.rawEnd(),\n }\n}\n\nexport function timeframeToDatepickerTimeperiod(timeframe: Timeframe): TimePeriod {\n // The datepicker needs `start` and `end` functions for its timeperiods.\n return {\n key: timeframe.key,\n display: timeframe.display,\n timeframeText: timeframe.timeframeText,\n timeframeLength: () => timeframe.key, // Used to generate test IDs for the Kongponent.\n start: () => timeframe.rawStart(),\n end: () => timeframe.rawEnd(),\n }\n}\n\nexport function dstOffsetHours(d1: Date, d2: Date): number {\n return minutesToHours(d1.getTimezoneOffset() - d2.getTimezoneOffset())\n}\n"],"names":["GranularityKeys","TimeframeKeys","ChartTypes","Granularities","granularitiesToOptions","values","i18n","v","granularityMsToQuery","granularity","origin","msToGranularity","ms","k","toNearestTimeGrain","op","date","granularityMs","tzOffsetMs","floorToNearestTimeGrain","ceilToNearestTimeGrain","_typeof","obj","toInteger","dirtyNumber","number","requiredArgs","required","args","toDate","argument","argStr","addDays","dirtyDate","dirtyAmount","amount","addMonths","dayOfMonth","endOfDesiredMonth","daysInMonth","defaultOptions","getDefaultOptions","startOfWeek","options","_ref","_ref2","_ref3","_options$weekStartsOn","_options$locale","_options$locale$optio","_defaultOptions$local","_defaultOptions$local2","weekStartsOn","day","diff","startOfDay","minutesInHour","secondsInHour","startOfMonth","getDaysInMonth","year","monthIndex","lastDayOfMonth","getTime","timestamp","getUnixTime","hoursToSeconds","hours","subDays","minutesToHours","minutes","subMonths","sub","duration","years","months","weeks","days","seconds","dateWithoutMonths","dateWithoutDays","minutestoSub","secondstoSub","mstoSub","finalDate","BaseQueryTime","timeframe","__publicField","isRelative","periods","ceilEnd","floorStart","periodOffset","TimeseriesQueryTime","UnaryQueryTime","DeltaQueryTime","Timeframe","opts","allowedValues","CurrentWeek","CurrentMonth","PreviousWeek","PreviousMonth","TimePeriods","prevMonday","firstOfTheMonth","offset","end","start","dstOffsetHours","datePickerSelectionToTimeframe","datePickerSelection","timeframeLength","timeframeToDatepickerSelection","timeframeToDatepickerTimeperiod","d1","d2"],"mappings":"wPACY,IAAAA,GAAAA,IACVA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAJCA,IAAAA,GAAA,CAAA,CAAA,ECAAC,GAAAA,IACVA,EAAA,YAAc,MACdA,EAAA,SAAW,KACXA,EAAA,SAAW,KACXA,EAAA,YAAc,MACdA,EAAA,QAAU,MACVA,EAAA,UAAY,K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AAU,SAAS,EAC1B,IAAKA,EAAU,OAAO,CAAA,CAE1B,CAEO,SAAS4B,GAAgC5B,EAAkC,CAEzE,MAAA,CACL,IAAKA,EAAU,IACf,QAASA,EAAU,QACnB,cAAeA,EAAU,cACzB,gBAAiB,IAAMA,EAAU,IACjC,MAAO,IAAMA,EAAU,SAAS,EAChC,IAAK,IAAMA,EAAU,OAAO,CAAA,CAEhC,CAEgB,SAAAuB,EAAeM,EAAUC,EAAkB,CACzD,OAAO/C,EAAe8C,EAAG,kBAAsB,EAAAC,EAAG,mBAAmB,CACvE","x_google_ignoreList":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]}
@@ -24,15 +24,15 @@ function b(e, t) {
24
24
  function ne(e) {
25
25
  return e && Object.values(a).find((r) => e <= R[r]) || null;
26
26
  }
27
- function k(e, t, r) {
27
+ function U(e, t, r) {
28
28
  const n = R[r], i = n >= R[a.DAILY] ? t.getTimezoneOffset() * 60 * 1e3 : 0;
29
29
  return new Date(e((t.getTime() - i) / n) * n + i);
30
30
  }
31
- function _(e, t) {
32
- return k(Math.floor, e, t);
31
+ function N(e, t) {
32
+ return U(Math.floor, e, t);
33
33
  }
34
- function U(e, t) {
35
- return k(Math.ceil, e, t);
34
+ function G(e, t) {
35
+ return U(Math.ceil, e, t);
36
36
  }
37
37
  function E(e) {
38
38
  "@babel/helpers - typeof";
@@ -87,7 +87,7 @@ function L(e, t) {
87
87
  var c = y(e), p = c.getDay(), M = (p < T ? 7 : 0) + p - T;
88
88
  return c.setDate(c.getDate() - M), c.setHours(0, 0, 0, 0), c;
89
89
  }
90
- function N(e) {
90
+ function Y(e) {
91
91
  u(1, arguments);
92
92
  var t = y(e);
93
93
  return t.setHours(0, 0, 0, 0), t;
@@ -108,7 +108,7 @@ function I(e) {
108
108
  var t = y(e), r = t.getTime();
109
109
  return r;
110
110
  }
111
- function Y(e) {
111
+ function k(e) {
112
112
  return u(1, arguments), Math.floor(I(e) / 1e3);
113
113
  }
114
114
  function B(e) {
@@ -124,7 +124,7 @@ function $(e) {
124
124
  var t = e / V;
125
125
  return Math.floor(t);
126
126
  }
127
- function G(e, t) {
127
+ function _(e, t) {
128
128
  u(2, arguments);
129
129
  var r = m(t);
130
130
  return W(e, -r);
@@ -132,7 +132,7 @@ function G(e, t) {
132
132
  function j(e, t) {
133
133
  if (u(2, arguments), !t || E(t) !== "object")
134
134
  return /* @__PURE__ */ new Date(NaN);
135
- var r = t.years ? m(t.years) : 0, n = t.months ? m(t.months) : 0, i = t.weeks ? m(t.weeks) : 0, o = t.days ? m(t.days) : 0, f = t.hours ? m(t.hours) : 0, h = t.minutes ? m(t.minutes) : 0, w = t.seconds ? m(t.seconds) : 0, D = G(e, n + r * 12), v = Q(D, o + i * 7), T = h + f * 60, c = w + T * 60, p = c * 1e3, M = new Date(v.getTime() - p);
135
+ var r = t.years ? m(t.years) : 0, n = t.months ? m(t.months) : 0, i = t.weeks ? m(t.weeks) : 0, o = t.days ? m(t.days) : 0, f = t.hours ? m(t.hours) : 0, h = t.minutes ? m(t.minutes) : 0, w = t.seconds ? m(t.seconds) : 0, D = _(e, n + r * 12), v = Q(D, o + i * 7), T = h + f * 60, c = w + T * 60, p = c * 1e3, M = new Date(v.getTime() - p);
136
136
  return M;
137
137
  }
138
138
  class O {
@@ -146,8 +146,8 @@ class O {
146
146
  if (t)
147
147
  return new Date(this.endDate().getTime() - this.timeframe.timeframeLengthMs() * n);
148
148
  {
149
- const i = this.endDate(), o = _(this.timeframe.rawStart(), r), h = (i.getTime() - o.getTime()) * (n - 1);
150
- return _(
149
+ const i = this.endDate(), o = N(this.timeframe.rawStart(), r), h = (i.getTime() - o.getTime()) * (n - 1);
150
+ return N(
151
151
  new Date(this.timeframe.rawStart().getTime() - h),
152
152
  r
153
153
  );
@@ -161,11 +161,11 @@ class O {
161
161
  }
162
162
  // Return a UNIX timestamp suitable for use in the `start` query param.
163
163
  startSeconds() {
164
- return Y(this.startDate());
164
+ return k(this.startDate());
165
165
  }
166
166
  // Return a UNIX timestamp suitable for use in the `end` query param.
167
167
  endSeconds() {
168
- return Y(this.endDate());
168
+ return k(this.endDate());
169
169
  }
170
170
  // Return epoch time in milliseconds, suitable for use in the `startMs` query param.
171
171
  startMs() {
@@ -190,7 +190,7 @@ class se extends O {
190
190
  return this.calculateStartDate(this.timeframe.isRelative, this.granularity);
191
191
  }
192
192
  endDate() {
193
- return U(this.timeframe.rawEnd(), this.granularity);
193
+ return G(this.timeframe.rawEnd(), this.granularity);
194
194
  }
195
195
  granularityMs() {
196
196
  return R[this.granularity];
@@ -201,7 +201,7 @@ class X extends O {
201
201
  return this.calculateStartDate(this.timeframe.isRelative, this.timeframe.dataGranularity);
202
202
  }
203
203
  endDate() {
204
- return U(this.timeframe.rawEnd(), this.timeframe.dataGranularity);
204
+ return G(this.timeframe.rawEnd(), this.timeframe.dataGranularity);
205
205
  }
206
206
  granularityMs() {
207
207
  return this.endDate().getTime() - this.startDate().getTime();
@@ -291,7 +291,7 @@ class K extends d {
291
291
  return g(/* @__PURE__ */ new Date());
292
292
  }
293
293
  rawStart() {
294
- return g((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 1));
294
+ return g(_(/* @__PURE__ */ new Date(), 1));
295
295
  }
296
296
  }
297
297
  const ee = /* @__PURE__ */ new Map([
@@ -394,7 +394,7 @@ const ee = /* @__PURE__ */ new Map([
394
394
  timeframeText: "Week",
395
395
  timeframeLength: () => {
396
396
  const e = L(/* @__PURE__ */ new Date(), { weekStartsOn: 1 });
397
- return (N(S(/* @__PURE__ */ new Date(), 1)).getTime() - e.getTime()) / 1e3;
397
+ return (Y(S(/* @__PURE__ */ new Date(), 1)).getTime() - e.getTime()) / 1e3;
398
398
  },
399
399
  defaultResponseGranularity: a.DAILY,
400
400
  dataGranularity: a.DAILY,
@@ -410,7 +410,7 @@ const ee = /* @__PURE__ */ new Map([
410
410
  timeframeText: "Month",
411
411
  timeframeLength: () => {
412
412
  const e = g(/* @__PURE__ */ new Date());
413
- return (N(S(/* @__PURE__ */ new Date(), 1)).getTime() - e.getTime()) / 1e3;
413
+ return (Y(S(/* @__PURE__ */ new Date(), 1)).getTime() - e.getTime()) / 1e3;
414
414
  },
415
415
  defaultResponseGranularity: a.DAILY,
416
416
  dataGranularity: a.DAILY,
@@ -439,7 +439,7 @@ const ee = /* @__PURE__ */ new Map([
439
439
  timeframeText: "Month",
440
440
  timeframeLength: () => {
441
441
  let e = 0;
442
- const t = g(/* @__PURE__ */ new Date()), r = g(G(/* @__PURE__ */ new Date(), 1));
442
+ const t = g(/* @__PURE__ */ new Date()), r = g(_(/* @__PURE__ */ new Date(), 1));
443
443
  return t.getTimezoneOffset() !== r.getTimezoneOffset() && (e = te(t, r)), 60 * 60 * 24 * z((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 1)) + B(e);
444
444
  },
445
445
  defaultResponseGranularity: a.DAILY,
@@ -495,10 +495,10 @@ export {
495
495
  s as TimeframeKeys,
496
496
  se as TimeseriesQueryTime,
497
497
  X as UnaryQueryTime,
498
- U as ceilToNearestTimeGrain,
498
+ G as ceilToNearestTimeGrain,
499
499
  ue as datePickerSelectionToTimeframe,
500
500
  te as dstOffsetHours,
501
- _ as floorToNearestTimeGrain,
501
+ N as floorToNearestTimeGrain,
502
502
  ae as granularitiesToOptions,
503
503
  b as granularityMsToQuery,
504
504
  ne as msToGranularity,