plexpy/data/interfaces/default/js/moment-duration-format.min.js
2020-10-10 09:49:29 -07:00

11 lines
14 KiB
JavaScript

/*! Moment Duration Format v2.2.2
* https://github.com/jsmreese/moment-duration-format
* Date: 2018-02-16
*
* Duration format plugin function for the Moment.js library
* http://momentjs.com/
*
* Copyright 2018 John Madhavan-Reese
* Released under the MIT license
*/
!function(e,t){if("function"==typeof define&&define.amd)define(["moment"],t);else if("object"==typeof exports)try{module.exports=t(require("moment"))}catch(e){module.exports=t}e&&(e.momentDurationFormatSetup=e.moment?t(e.moment):t)}(this,function(e){var t=!1,n=!1,i=!1,r=!1,a="escape years months weeks days hours minutes seconds milliseconds general".split(" "),u=[{type:"seconds",targets:[{type:"minutes",value:60},{type:"hours",value:3600},{type:"days",value:86400},{type:"weeks",value:604800},{type:"months",value:2678400},{type:"years",value:31536e3}]},{type:"minutes",targets:[{type:"hours",value:60},{type:"days",value:1440},{type:"weeks",value:10080},{type:"months",value:44640},{type:"years",value:525600}]},{type:"hours",targets:[{type:"days",value:24},{type:"weeks",value:168},{type:"months",value:744},{type:"years",value:8760}]},{type:"days",targets:[{type:"weeks",value:7},{type:"months",value:31},{type:"years",value:365}]},{type:"months",targets:[{type:"years",value:12}]}];function o(e,t){return!(t.length>e.length)&&-1!==e.indexOf(t)}function l(e){for(var t="";e;)t+="0",e-=1;return t}function s(e,t){var n=e+"+"+d(D(t).sort(),function(e){return e+":"+t[e]}).join(",");return s.cache[n]||(s.cache[n]=Intl.NumberFormat(e,t)),s.cache[n]}function c(e,t,a){var u,o,m,f=t.useToLocaleString,p=t.useGrouping,g=p&&t.grouping.slice(),h=t.maximumSignificantDigits,y=t.minimumIntegerDigits||1,d=t.fractionDigits||0,v=t.groupingSeparator,w=t.decimalSeparator;if(f&&a){var S={minimumIntegerDigits:y,useGrouping:p};if(d&&(S.maximumFractionDigits=d,S.minimumFractionDigits=d),h&&e>0&&(S.maximumSignificantDigits=h),i){var V;if(!r)(V=x({},t)).useGrouping=!1,V.decimalSeparator=".",e=parseFloat(c(e,V),10);return s(a,S).format(e)}return n||((V=x({},t)).useGrouping=!1,V.decimalSeparator=".",e=parseFloat(c(e,V),10)),e.toLocaleString(a,S)}var _=(h?e.toPrecision(h+1):e.toFixed(d+1)).split("e");m=_[1]||"",o=(_=_[0].split("."))[1]||"";var D=(u=_[0]||"").length,b=o.length,M=D+b,L=u+o;(h&&M===h+1||!h&&b===d+1)&&((L=function(e){for(var t=e.split("").reverse(),n=0,i=!0;i&&n<t.length;)n?"9"===t[n]?t[n]="0":(t[n]=(parseInt(t[n],10)+1).toString(),i=!1):(parseInt(t[n],10)<5&&(i=!1),t[n]="0"),n+=1;return i&&t.push("1"),t.reverse().join("")}(L)).length===M+1&&(D+=1),b&&(L=L.slice(0,-1)),u=L.slice(0,D),o=L.slice(D)),h&&(o=o.replace(/0*$/,""));var k=parseInt(m,10);k>0?o.length<=k?(u+=o+=l(k-o.length),o=""):(u+=o.slice(0,k),o=o.slice(k)):k<0&&(o=l(Math.abs(k)-u.length)+u+o,u="0"),h||((o=o.slice(0,d)).length<d&&(o+=l(d-o.length)),u.length<y&&(u=l(y-u.length)+u));var T,F="";if(p)for(_=u;_.length;)g.length&&(T=g.shift()),F&&(F=v+F),F=_.slice(-T)+F,_=_.slice(0,-T);else F=u;return o&&(F=F+w+o),F}function m(e,t){return e.label.length>t.label.length?-1:e.label.length<t.label.length?1:0}s.cache={};var f={durationLabelsStandard:{S:"millisecond",SS:"milliseconds",s:"second",ss:"seconds",m:"minute",mm:"minutes",h:"hour",hh:"hours",d:"day",dd:"days",w:"week",ww:"weeks",M:"month",MM:"months",y:"year",yy:"years"},durationLabelsShort:{S:"msec",SS:"msecs",s:"sec",ss:"secs",m:"min",mm:"mins",h:"hr",hh:"hrs",d:"dy",dd:"dys",w:"wk",ww:"wks",M:"mo",MM:"mos",y:"yr",yy:"yrs"},durationTimeTemplates:{HMS:"h:mm:ss",HM:"h:mm",MS:"m:ss"},durationLabelTypes:[{type:"standard",string:"__"},{type:"short",string:"_"}],durationPluralKey:function(e,t,n){return 1===t&&null===n?e:e+e}};function p(e){return"[object Array]"===Object.prototype.toString.call(e)}function g(e){return"[object Object]"===Object.prototype.toString.call(e)}function h(e,t){var n,i=0,r=e&&e.length||0;for("function"!=typeof t&&(n=t,t=function(e){return e===n});i<r;){if(t(e[i]))return e[i];i+=1}}function y(e,t){var n=0,i=e.length;if(e&&i)for(;n<i;){if(!1===t(e[n],n))return;n+=1}}function d(e,t){var n=0,i=e.length,r=[];if(!e||!i)return r;for(;n<i;)r[n]=t(e[n],n),n+=1;return r}function v(e,t){return d(e,function(e){return e[t]})}function w(e){var t=[];return y(e,function(e){e&&t.push(e)}),t}function S(e){var t=[];return y(e,function(e){h(t,e)||t.push(e)}),t}function V(e,t){var n=[];return y(e,function(e){y(t,function(t){e===t&&n.push(e)})}),S(n)}function _(e,t){var n=[];return y(e,function(i,r){if(!t(i))return n=e.slice(r),!1}),n}function x(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}function D(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t}function b(e,t){var n=0,i=e.length;if(!e||!i)return!1;for(;n<i;){if(!0===t(e[n],n))return!0;n+=1}return!1}function M(e){return"3.6"===e(3.55,"en",{useGrouping:!1,minimumIntegerDigits:1,minimumFractionDigits:1,maximumFractionDigits:1})}function L(e){var t=!0;return!!(t=(t=(t=t&&"1"===e(1,"en",{minimumIntegerDigits:1}))&&"01"===e(1,"en",{minimumIntegerDigits:2}))&&"001"===e(1,"en",{minimumIntegerDigits:3}))&&(!!(t=(t=(t=(t=t&&"100"===e(99.99,"en",{maximumFractionDigits:0,minimumFractionDigits:0}))&&"100.0"===e(99.99,"en",{maximumFractionDigits:1,minimumFractionDigits:1}))&&"99.99"===e(99.99,"en",{maximumFractionDigits:2,minimumFractionDigits:2}))&&"99.990"===e(99.99,"en",{maximumFractionDigits:3,minimumFractionDigits:3}))&&(!!(t=(t=(t=(t=(t=t&&"100"===e(99.99,"en",{maximumSignificantDigits:1}))&&"100"===e(99.99,"en",{maximumSignificantDigits:2}))&&"100"===e(99.99,"en",{maximumSignificantDigits:3}))&&"99.99"===e(99.99,"en",{maximumSignificantDigits:4}))&&"99.99"===e(99.99,"en",{maximumSignificantDigits:5}))&&!!(t=(t=t&&"1,000"===e(1e3,"en",{useGrouping:!0}))&&"1000"===e(1e3,"en",{useGrouping:!1}))))}function k(){var e,t=[].slice.call(arguments),n={};if(y(t,function(t,i){if(!i){if(!p(t))throw"Expected array as the first argument to durationsFormat.";e=t}"string"!=typeof t&&"function"!=typeof t?"number"!=typeof t?g(t)&&x(n,t):n.precision=t:n.template=t}),!e||!e.length)return[];n.returnMomentTypes=!0;var i,r=d(e,function(e){return e.format(n)}),u=V(a,S(v((i=[],y(r,function(e){i=i.concat(e)}),i),"type"))),o=n.largest;return o&&(u=u.slice(0,o)),n.returnMomentTypes=!1,n.outputTypes=u,d(e,function(e){return e.format(n)})}function T(){var n=[].slice.call(arguments),r=x({},this.format.defaults),l=this.asMilliseconds(),s=this.asMonths();"function"==typeof this.isValid&&!1===this.isValid()&&(l=0,s=0);var M=l<0,L=e.duration(Math.abs(l),"milliseconds"),k=e.duration(Math.abs(s),"months");y(n,function(e){"string"!=typeof e&&"function"!=typeof e?"number"!=typeof e?g(e)&&x(r,e):r.precision=e:r.template=e});var T={years:"y",months:"M",weeks:"w",days:"d",hours:"h",minutes:"m",seconds:"s",milliseconds:"S"},F={escape:/\[(.+?)\]/,years:/\*?[Yy]+/,months:/\*?M+/,weeks:/\*?[Ww]+/,days:/\*?[Dd]+/,hours:/\*?[Hh]+/,minutes:/\*?m+/,seconds:/\*?s+/,milliseconds:/\*?S+/,general:/.+?/};r.types=a;var I=function(e){return h(a,function(t){return F[t].test(e)})},j=new RegExp(d(a,function(e){return F[e].source}).join("|"),"g");r.duration=this;var G="function"==typeof r.template?r.template.apply(r):r.template,E=r.outputTypes,P=r.returnMomentTypes,O=r.largest,H=[];E||(p(r.stopTrim)&&(r.stopTrim=r.stopTrim.join("")),r.stopTrim&&y(r.stopTrim.match(j),function(e){var t=I(e);"escape"!==t&&"general"!==t&&H.push(t)}));var N=e.localeData();N||(N={}),y(D(f),function(e){"function"!=typeof f[e]?N["_"+e]||(N["_"+e]=f[e]):N[e]||(N[e]=f[e])}),y(D(N._durationTimeTemplates),function(e){G=G.replace("_"+e+"_",N._durationTimeTemplates[e])});var $=r.userLocale||e.locale(),K=r.useLeftUnits,R=r.usePlural,U=r.precision,q=r.forceLength,A=r.useGrouping,C=r.trunc,W=r.useSignificantDigits&&U>0,Y=W?r.precision:0,z=Y,B=r.minValue,J=!1,Q=r.maxValue,X=!1,Z=r.useToLocaleString,ee=r.groupingSeparator,te=r.decimalSeparator,ne=r.grouping;Z=Z&&(t||i);var ie=r.trim;p(ie)&&(ie=ie.join(" ")),null===ie&&(O||Q||W)&&(ie="all"),null!==ie&&!0!==ie&&"left"!==ie&&"right"!==ie||(ie="large"),!1===ie&&(ie="");var re=function(e){return e.test(ie)},ae=/both/,ue=/^all|[^sm]all/,oe=O>0||b([/large/,ae,ue],re),le=b([/small/,ae,ue],re),se=b([/mid/,ue],re),ce=b([/final/,ue],re),me=d(G.match(j),function(e,t){var n=I(e);return"*"===e.slice(0,1)&&(e=e.slice(1),"escape"!==n&&"general"!==n&&H.push(n)),{index:t,length:e.length,text:"",token:"escape"===n?e.replace(F.escape,"$1"):e,type:"escape"===n||"general"===n?null:n}}),fe={index:0,length:0,token:"",text:"",type:null},pe=[];K&&me.reverse(),y(me,function(e){if(e.type)return(fe.type||fe.text)&&pe.push(fe),void(fe=e);K?fe.text=e.token+fe.text:fe.text+=e.token}),(fe.type||fe.text)&&pe.push(fe),K&&pe.reverse();var ge=V(a,S(w(v(pe,"type"))));if(!ge.length)return v(pe,"text").join("");ge=d(ge,function(e,t){var n,i=t+1===ge.length,a=!t;n="years"===e||"months"===e?k.as(e):L.as(e);var u=Math.floor(n),o=n-u,l=h(pe,function(t){return e===t.type});return a&&Q&&n>Q&&(X=!0),i&&B&&Math.abs(r.duration.as(e))<B&&(J=!0),a&&null===q&&l.length>1&&(q=!0),L.subtract(u,e),k.subtract(u,e),{rawValue:n,wholeValue:u,decimalValue:i?o:0,isSmallest:i,isLargest:a,type:e,tokenLength:l.length}});var he,ye=C?Math.floor:Math.round,de=function(e,t){var n=Math.pow(10,t);return ye(e*n)/n},ve=!1,we=!1,Se=function(e,t){var n={useGrouping:A,groupingSeparator:ee,decimalSeparator:te,grouping:ne,useToLocaleString:Z};return W&&(Y<=0?(e.rawValue=0,e.wholeValue=0,e.decimalValue=0):(n.maximumSignificantDigits=Y,e.significantDigits=Y)),X&&!we&&(e.isLargest?(e.wholeValue=Q,e.decimalValue=0):(e.wholeValue=0,e.decimalValue=0)),J&&!we&&(e.isSmallest?(e.wholeValue=B,e.decimalValue=0):(e.wholeValue=0,e.decimalValue=0)),e.isSmallest||e.significantDigits&&e.significantDigits-e.wholeValue.toString().length<=0?U<0?e.value=de(e.wholeValue,U):0===U?e.value=ye(e.wholeValue+e.decimalValue):W?(e.value=C?de(e.rawValue,Y-e.wholeValue.toString().length):e.rawValue,e.wholeValue&&(Y-=e.wholeValue.toString().length)):(n.fractionDigits=U,e.value=C?e.wholeValue+de(e.decimalValue,U):e.wholeValue+e.decimalValue):W&&e.wholeValue?(e.value=Math.round(de(e.wholeValue,e.significantDigits-e.wholeValue.toString().length)),Y-=e.wholeValue.toString().length):e.value=e.wholeValue,e.tokenLength>1&&(q||ve)&&(n.minimumIntegerDigits=e.tokenLength,we&&n.maximumSignificantDigits<e.tokenLength&&delete n.maximumSignificantDigits),!ve&&(e.value>0||""===ie||h(H,e.type)||h(E,e.type))&&(ve=!0),e.formattedValue=c(e.value,n,$),n.useGrouping=!1,n.decimalSeparator=".",e.formattedValueEn=c(e.value,n,"en"),2===e.tokenLength&&"milliseconds"===e.type&&(e.formattedValueMS=c(e.value,{minimumIntegerDigits:3,useGrouping:!1},"en").slice(0,2)),e};if((ge=w(ge=d(ge,Se))).length>1){var Ve=function(e){return h(ge,function(t){return t.type===e})};y(u,function(e){var t=Ve(e.type);t&&y(e.targets,function(e){var n=Ve(e.type);n&&parseInt(t.formattedValueEn,10)===e.value&&(t.rawValue=0,t.wholeValue=0,t.decimalValue=0,n.rawValue+=1,n.wholeValue+=1,n.decimalValue=0,n.formattedValueEn=n.wholeValue.toString(),we=!0)})})}return we&&(ve=!1,Y=z,ge=w(ge=d(ge,Se))),!E||X&&!r.trim?(oe&&(ge=_(ge,function(e){return!e.isSmallest&&!e.wholeValue&&!h(H,e.type)})),O&&ge.length&&(ge=ge.slice(0,O)),le&&ge.length>1&&(he=function(e){return!e.wholeValue&&!h(H,e.type)&&!e.isLargest},ge=_(ge.slice().reverse(),he).reverse()),se&&(ge=w(ge=d(ge,function(e,t){return t>0&&t<ge.length-1&&!e.wholeValue?null:e}))),!ce||1!==ge.length||ge[0].wholeValue||!C&&ge[0].isSmallest&&ge[0].rawValue<B||(ge=[])):ge=w(ge=d(ge,function(e){return h(E,function(t){return e.type===t})?e:null})),P?ge:(y(pe,function(e){var t=T[e.type],n=h(ge,function(t){return t.type===e.type});if(t&&n){var i=n.formattedValueEn.split(".");i[0]=parseInt(i[0],10),i[1]?i[1]=parseFloat("0."+i[1],10):i[1]=null;var r=N.durationPluralKey(t,i[0],i[1]),a=function(e,t){var n=[];return y(D(t),function(i){if("_durationLabels"===i.slice(0,15)){var r=i.slice(15).toLowerCase();y(D(t[i]),function(a){a.slice(0,1)===e&&n.push({type:r,key:a,label:t[i][a]})})}}),n}(t,N),u=!1,l={};y(N._durationLabelTypes,function(t){var n=h(a,function(e){return e.type===t.type&&e.key===r});n&&(l[n.type]=n.label,o(e.text,t.string)&&(e.text=e.text.replace(t.string,n.label),u=!0))}),R&&!u&&(a.sort(m),y(a,function(t){return l[t.type]===t.label?!o(e.text,t.label)&&void 0:o(e.text,t.label)?(e.text=e.text.replace(t.label,l[t.type]),!1):void 0}))}}),(pe=d(pe,function(e){if(!e.type)return e.text;var t=h(ge,function(t){return t.type===e.type});if(!t)return"";var n="";return K&&(n+=e.text),(M&&X||!M&&J)&&(n+="< ",X=!1,J=!1),(M&&J||!M&&X)&&(n+="> ",X=!1,J=!1),M&&(t.value>0||""===ie||h(H,t.type)||h(E,t.type))&&(n+="-",M=!1),"milliseconds"===e.type&&t.formattedValueMS?n+=t.formattedValueMS:n+=t.formattedValue,K||(n+=e.text),n})).join("").replace(/(,| |:|\.)*$/,"").replace(/^(,| |:|\.)*/,""))}function F(){var e=this.duration,t=function(t){return e._data[t]},n=h(this.types,t),i=function(e,t){for(var n=e.length;n-=1;)if(t(e[n]))return e[n]}(this.types,t);switch(n){case"milliseconds":return"S __";case"seconds":case"minutes":return"*_MS_";case"hours":return"_HMS_";case"days":if(n===i)return"d __";case"weeks":return n===i?"w __":(null===this.trim&&(this.trim="both"),"w __, d __, h __");case"months":if(n===i)return"M __";case"years":return n===i?"y __":(null===this.trim&&(this.trim="both"),"y __, M __, d __");default:return null===this.trim&&(this.trim="both"),"y __, d __, h __, m __, s __"}}function I(e){if(!e)throw"Moment Duration Format init cannot find moment instance.";e.duration.format=k,e.duration.fn.format=T,e.duration.fn.format.defaults={trim:null,stopTrim:null,largest:null,maxValue:null,minValue:null,precision:0,trunc:!1,forceLength:null,userLocale:null,usePlural:!0,useLeftUnits:!1,useGrouping:!0,useSignificantDigits:!1,template:F,useToLocaleString:!0,groupingSeparator:",",decimalSeparator:".",grouping:[3]},e.updateLocale("en",f)}var j=function(e,t,n){return e.toLocaleString(t,n)};t=function(){try{(0).toLocaleString("i")}catch(e){return"RangeError"===e.name}return!1}()&&L(j),n=t&&M(j);var G=function(e,t,n){if("undefined"!=typeof window&&window&&window.Intl&&window.Intl.NumberFormat)return window.Intl.NumberFormat(t,n).format(e)};return i=L(G),r=i&&M(G),I(e),I});