utils.js
731 字节
"use strict";function i(e,n=2){let s=`${e}`;for(;s.length<n;)s=`0${s}`;return s}const t=1e3,r=60*t,a=60*r,u=24*a;function h(e){const n=Math.floor(e/u),s=Math.floor(e%u/a),o=Math.floor(e%a/r),c=Math.floor(e%r/t),l=Math.floor(e%t);return{days:n,hours:s,minutes:o,seconds:c,milliseconds:l}}function p(e,n){let{days:s,hours:o,minutes:c,seconds:l,milliseconds:d}=n;return e.indexOf("DD")===-1?o+=s*24:e=e.replace("DD",i(s)),e.indexOf("HH")===-1?c+=o*60:e=e.replace("HH",i(o)),e.indexOf("mm")===-1?l+=c*60:e=e.replace("mm",i(c)),e.indexOf("ss")===-1?d+=l*1e3:e=e.replace("ss",i(l)),e.replace("SSS",i(d,3))}function D(e,n){return Math.floor(e/1e3)===Math.floor(n/1e3)}exports.isSameSecond=D;exports.parseFormat=p;exports.parseTimeData=h;