UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 8.94 kB
import TimeFormatter from'./time-formatter.js';import TimeParser,{utcDate}from'./time-parser.js';import{sunday as timeSunday,monday as timeMonday,thursday as timeThursday}from'../time-intervals/week.js';import{utcSunday,utcMonday,utcThursday}from'../time-intervals/utc/week.js';import timeDay from'../time-intervals/day.js';import timeYear from'../time-intervals/year.js';import utcDay from'../time-intervals/utc/day.js';import utcYear from'../time-intervals/utc/year.js';import enUS from'./locales/en-US.js';const numberRe=/^\s*\d+/,quarterRe=/^\s*Q\d+/,percentRe=/^%/,requoteRe=/[\\^$*+?|[\]().{}]/g,pad=(a,b,c)=>{const d=0>a?'-':'',e=(d?-a:a)+'',f=e.length,g=f<c?Array(c-f+1).join(b)+e:e;return d+g},requote=a=>a.replace(requoteRe,'\\$&'),formatRe=a=>new RegExp('^(?:'+a.map(requote).join('|')+')','i'),formatLookup=a=>{let b={},c=-1,d=a.length;for(;++c<d;)b[a[c].toLowerCase()]=c;return b},parseWeekdayNumberSunday=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+1));return d?(a.w=+d[0],c+d[0].length):-1},parseWeekdayNumberMonday=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+1));return d?(a.u=+d[0],c+d[0].length):-1},parseWeekNumberSunday=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.U=+d[0],c+d[0].length):-1},parseWeekNumberISO=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.V=+d[0],c+d[0].length):-1},parseWeekNumberMonday=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.W=+d[0],c+d[0].length):-1},parseQuarter=(a,b,c)=>{var d=quarterRe.exec(b.slice(c,c+2));return d?(a.m=3*(d[0][1]-1),c+d[0].length):-1},parseFullYear=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+4));return d?(a.y=+d[0],c+d[0].length):-1},parseYear=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.y=+d[0]+(68<+d[0]?1900:2e3),c+d[0].length):-1},parseZone=(a,b,c)=>{var d=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(b.slice(c,c+6));return d?(a.Z=d[1]?0:-(d[2]+(d[3]||'00')),c+d[0].length):-1},parseMonthNumber=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.m=d[0]-1,c+d[0].length):-1},parseDayOfMonth=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.d=+d[0],c+d[0].length):-1},parseDayOfYear=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+3));return d?(a.m=0,a.d=+d[0],c+d[0].length):-1},parseHour24=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.H=+d[0],c+d[0].length):-1},parseMinutes=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.M=+d[0],c+d[0].length):-1},parseSeconds=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+2));return d?(a.S=+d[0],c+d[0].length):-1},parseMilliseconds=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+3));return d?(a.L=+d[0],c+d[0].length):-1},parseMicroseconds=(a,b,c)=>{var d=numberRe.exec(b.slice(c,c+6));return d?(a.L=Math.floor(d[0]/1e3),c+d[0].length):-1},parseLiteralPercent=(a,b,c)=>{var d=percentRe.exec(b.slice(c,c+1));return d?c+d[0].length:-1},parseUnixTimestamp=(a,b,c)=>{var d=numberRe.exec(b.slice(c));return d?(a.Q=+d[0],c+d[0].length):-1},parseUnixTimestampSeconds=(a,b,c)=>{var d=numberRe.exec(b.slice(c));return d?(a.Q=1e3*+d[0],c+d[0].length):-1},formatDayOfMonth=(a,b)=>pad(a.getDate(),b,2),formatHour24=(a,b)=>pad(a.getHours(),b,2),formatHour12=(a,b)=>pad(a.getHours()%12||12,b,2),formatDayOfYear=(a,b)=>pad(1+timeDay.count(timeYear.floor(a),a),b,3),formatMilliseconds=(a,b)=>pad(a.getMilliseconds(),b,3),formatMicroseconds=(a,b)=>formatMilliseconds(a,b)+'000',formatMonthNumber=(a,b)=>pad(a.getMonth()+1,b,2),formatMinutes=(a,b)=>pad(a.getMinutes(),b,2),formatSeconds=(a,b)=>pad(a.getSeconds(),b,2),formatQuarter=a=>'Q'+Math.ceil((a.getMonth()+1)/3),formatWeekdayNumberMonday=a=>{var b=a.getDay();return 0===b?7:b},formatWeekNumberSunday=(a,b)=>pad(timeSunday.count(timeYear.floor(a),a),b,2),formatWeekNumberISO=(a,b)=>{var c=a.getDay();return a=4<=c||0===c?timeThursday.floor(a):timeThursday.ceil(a),pad(timeThursday.count(timeYear.floor(a),a)+(4===timeYear.floor(a).getDay()),b,2)},formatWeekdayNumberSunday=a=>a.getDay(),formatWeekNumberMonday=(a,b)=>pad(timeMonday.count(timeYear.floor(a),a),b,2),formatYear=(a,b)=>pad(a.getFullYear()%100,b,2),formatFullYear=(a,b)=>pad(a.getFullYear()%1e4,b,4),formatZone=a=>{var b=a.getTimezoneOffset();return(0<b?'-':(b*=-1,'+'))+pad(0|b/60,'0',2)+pad(b%60,'0',2)},formatUTCDayOfMonth=(a,b)=>pad(a.getUTCDate(),b,2),formatUTCHour24=(a,b)=>pad(a.getUTCHours(),b,2),formatUTCHour12=(a,b)=>pad(a.getUTCHours()%12||12,b,2),formatUTCDayOfYear=(a,b)=>pad(1+utcDay.count(utcYear.floor(a),a),b,3),formatUTCMilliseconds=(a,b)=>pad(a.getUTCMilliseconds(),b,3),formatUTCMicroseconds=(a,b)=>formatUTCMilliseconds(a,b)+'000',formatUTCMonthNumber=(a,b)=>pad(a.getUTCMonth()+1,b,2),formatUTCMinutes=(a,b)=>pad(a.getUTCMinutes(),b,2),formatUTCSeconds=(a,b)=>pad(a.getUTCSeconds(),b,2),formatUTCQuarter=a=>'Q'+Math.ceil((a.getUTCMonth()+1)/3),formatUTCWeekdayNumberMonday=a=>{var b=a.getUTCDay();return 0===b?7:b},formatUTCWeekNumberSunday=(a,b)=>pad(utcSunday.count(utcYear.floor(a),a),b,2),formatUTCWeekNumberISO=(a,b)=>{var c=a.getUTCDay();return a=4<=c||0===c?utcThursday.floor(a):utcThursday.ceil(a),pad(utcThursday.count(utcYear.floor(a),a)+(4===utcYear.floor(a).getUTCDay()),b,2)},formatUTCWeekdayNumberSunday=a=>a.getUTCDay(),formatUTCWeekNumberMonday=(a,b)=>pad(utcMonday.count(utcYear.floor(a),a),b,2),formatUTCYear=(a,b)=>pad(a.getUTCFullYear()%100,b,2),formatUTCFullYear=(a,b)=>pad(a.getUTCFullYear()%1e4,b,4),formatUTCZone=()=>'+0000',formatLiteralPercent=()=>'%',formatUnixTimestamp=a=>+a,formatUnixTimestampSeconds=a=>Math.floor(+a/1e3);class TimeConverter{constructor(a){const{dateTime:b,date:c,time:e,periods:f,days:g,shortDays:h,months:i,shortMonths:j}=a,k=formatRe(f),l=formatLookup(f),m=formatRe(g),o=formatLookup(g),p=formatRe(h),q=formatLookup(h),r=formatRe(i),s=formatLookup(i),t=formatRe(j),u=formatLookup(j);this._formats={a:a=>h[a.getDay()],A:a=>g[a.getDay()],b:a=>j[a.getMonth()],B:a=>i[a.getMonth()],d:formatDayOfMonth,e:formatDayOfMonth,f:formatMicroseconds,H:formatHour24,I:formatHour12,j:formatDayOfYear,L:formatMilliseconds,m:formatMonthNumber,M:formatMinutes,p:a=>f[+(12<=a.getHours())],q:formatQuarter,Q:formatUnixTimestamp,s:formatUnixTimestampSeconds,S:formatSeconds,u:formatWeekdayNumberMonday,U:formatWeekNumberSunday,V:formatWeekNumberISO,w:formatWeekdayNumberSunday,W:formatWeekNumberMonday,y:formatYear,Y:formatFullYear,Z:formatZone,"%":formatLiteralPercent},this._utcFormats={a:a=>h[a.getUTCDay()],A:a=>g[a.getUTCDay()],b:a=>j[a.getUTCMonth()],B:a=>i[a.getUTCMonth()],d:formatUTCDayOfMonth,e:formatUTCDayOfMonth,f:formatUTCMicroseconds,H:formatUTCHour24,I:formatUTCHour12,j:formatUTCDayOfYear,L:formatUTCMilliseconds,m:formatUTCMonthNumber,M:formatUTCMinutes,p:a=>f[+(12<=a.getUTCHours())],q:formatUTCQuarter,Q:formatUnixTimestamp,s:formatUnixTimestampSeconds,S:formatUTCSeconds,u:formatUTCWeekdayNumberMonday,U:formatUTCWeekNumberSunday,V:formatUTCWeekNumberISO,w:formatUTCWeekdayNumberSunday,W:formatUTCWeekNumberMonday,y:formatUTCYear,Y:formatUTCFullYear,Z:formatUTCZone,"%":formatLiteralPercent},this._parses={a:(a,b,c)=>{const d=p.exec(b.slice(c));return d?(a.w=q[d[0].toLowerCase()],c+d[0].length):-1},A:(a,b,c)=>{const d=m.exec(b.slice(c));return d?(a.w=o[d[0].toLowerCase()],c+d[0].length):-1},b:(a,b,c)=>{const d=t.exec(b.slice(c));return d?(a.m=u[d[0].toLowerCase()],c+d[0].length):-1},B:(a,b,c)=>{const d=r.exec(b.slice(c));return d?(a.m=s[d[0].toLowerCase()],c+d[0].length):-1},c:null,d:parseDayOfMonth,e:parseDayOfMonth,f:parseMicroseconds,H:parseHour24,I:parseHour24,j:parseDayOfYear,L:parseMilliseconds,m:parseMonthNumber,M:parseMinutes,p:(a,b,c)=>{const d=k.exec(b.slice(c));return d?(a.p=l[d[0].toLowerCase()],c+d[0].length):-1},Q:parseUnixTimestamp,q:parseQuarter,s:parseUnixTimestampSeconds,S:parseSeconds,u:parseWeekdayNumberMonday,U:parseWeekNumberSunday,V:parseWeekNumberISO,w:parseWeekdayNumberSunday,W:parseWeekNumberMonday,x:null,X:null,y:parseYear,Y:parseFullYear,Z:parseZone,"%":parseLiteralPercent},this._formats.x=a=>new TimeFormatter(c,this._formats).format(a),this._formats.X=a=>new TimeFormatter(e,this._formats).format(a),this._formats.c=a=>new TimeFormatter(b,this._formats).format(a),this._utcFormats.x=a=>new TimeFormatter(c,this._utcFormats).format(a),this._utcFormats.X=a=>new TimeFormatter(e,this._utcFormats).format(a),this._utcFormats.c=a=>new TimeFormatter(b,this._utcFormats).format(a),this._parses.c=(a,c,d)=>new TimeParser(b,this._parses).parseSpecifier(a,c,d),this._parses.x=(a,b,d)=>new TimeParser(c,this._parses).parseSpecifier(a,b,d),this._parses.X=(a,b,c)=>new TimeParser(e,this._parses).parseSpecifier(a,b,c)}formatter(a){return new TimeFormatter(a,this._formats)}utcFormatter(a){return new TimeFormatter(a,this._utcFormats)}parser(a){return new TimeParser(a+='',this._parses,a=>{if(0<=a.y&&100>a.y){var b=new Date(-1,a.m,a.d,a.H,a.M,a.S,a.L);return b.setFullYear(a.y),b}return new Date(a.y,a.m,a.d,a.H,a.M,a.S,a.L)})}utcParser(a){return new TimeParser(a+='',this._parses,utcDate)}}export{TimeConverter};export default new TimeConverter(enUS);