| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | /* ssf.js (C) 2013-present SheetJS -- http://sheetjs.com */ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | /*jshint -W041 */ | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function _strrev(x/*:string*/)/*:string*/ { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; } | 
					
						
							|  |  |  | function pad0(v/*:any*/,d/*:number*/)/*:string*/{var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;} | 
					
						
							|  |  |  | function pad_(v/*:any*/,d/*:number*/)/*:string*/{var t=""+v;return t.length>=d?t:fill(' ',d-t.length)+t;} | 
					
						
							|  |  |  | function rpad_(v/*:any*/,d/*:number*/)/*:string*/{var t=""+v; return t.length>=d?t:t+fill(' ',d-t.length);} | 
					
						
							|  |  |  | function pad0r1(v/*:any*/,d/*:number*/)/*:string*/{var t=""+Math.round(v); return t.length>=d?t:fill('0',d-t.length)+t;} | 
					
						
							|  |  |  | function pad0r2(v/*:any*/,d/*:number*/)/*:string*/{var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;} | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | var p2_32 = /*#__PURE__*/Math.pow(2,32); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function pad0r(v/*:any*/,d/*:number*/)/*:string*/{if(v>p2_32||v<-p2_32) return pad0r1(v,d); var i = Math.round(v); return pad0r2(i,d); } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | /* yes, in 2022 this is still faster than string compare */ | 
					
						
							|  |  |  | function SSF_isgeneral(s/*:string*/, i/*:?number*/)/*:boolean*/ { i = i || 0; return s.length >= 7 + i && (s.charCodeAt(i)|32) === 103 && (s.charCodeAt(i+1)|32) === 101 && (s.charCodeAt(i+2)|32) === 110 && (s.charCodeAt(i+3)|32) === 101 && (s.charCodeAt(i+4)|32) === 114 && (s.charCodeAt(i+5)|32) === 97 && (s.charCodeAt(i+6)|32) === 108; } | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | var days/*:Array<Array<string> >*/ = [ | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	['Sun', 'Sunday'], | 
					
						
							|  |  |  | 	['Mon', 'Monday'], | 
					
						
							|  |  |  | 	['Tue', 'Tuesday'], | 
					
						
							|  |  |  | 	['Wed', 'Wednesday'], | 
					
						
							|  |  |  | 	['Thu', 'Thursday'], | 
					
						
							|  |  |  | 	['Fri', 'Friday'], | 
					
						
							|  |  |  | 	['Sat', 'Saturday'] | 
					
						
							|  |  |  | ]; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | var months/*:Array<Array<string> >*/ = [ | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	['J', 'Jan', 'January'], | 
					
						
							|  |  |  | 	['F', 'Feb', 'February'], | 
					
						
							|  |  |  | 	['M', 'Mar', 'March'], | 
					
						
							|  |  |  | 	['A', 'Apr', 'April'], | 
					
						
							|  |  |  | 	['M', 'May', 'May'], | 
					
						
							|  |  |  | 	['J', 'Jun', 'June'], | 
					
						
							|  |  |  | 	['J', 'Jul', 'July'], | 
					
						
							|  |  |  | 	['A', 'Aug', 'August'], | 
					
						
							|  |  |  | 	['S', 'Sep', 'September'], | 
					
						
							|  |  |  | 	['O', 'Oct', 'October'], | 
					
						
							|  |  |  | 	['N', 'Nov', 'November'], | 
					
						
							| 
									
										
										
										
											2013-04-17 01:32:20 +00:00
										 |  |  | 	['D', 'Dec', 'December'] | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | ]; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_init_table(t/*:any*/) { | 
					
						
							|  |  |  | 	if(!t) t = {}; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 	t[0]=  'General'; | 
					
						
							|  |  |  | 	t[1]=  '0'; | 
					
						
							|  |  |  | 	t[2]=  '0.00'; | 
					
						
							|  |  |  | 	t[3]=  '#,##0'; | 
					
						
							|  |  |  | 	t[4]=  '#,##0.00'; | 
					
						
							|  |  |  | 	t[9]=  '0%'; | 
					
						
							|  |  |  | 	t[10]= '0.00%'; | 
					
						
							|  |  |  | 	t[11]= '0.00E+00'; | 
					
						
							|  |  |  | 	t[12]= '# ?/?'; | 
					
						
							|  |  |  | 	t[13]= '# ??/??'; | 
					
						
							|  |  |  | 	t[14]= 'm/d/yy'; | 
					
						
							|  |  |  | 	t[15]= 'd-mmm-yy'; | 
					
						
							|  |  |  | 	t[16]= 'd-mmm'; | 
					
						
							|  |  |  | 	t[17]= 'mmm-yy'; | 
					
						
							|  |  |  | 	t[18]= 'h:mm AM/PM'; | 
					
						
							|  |  |  | 	t[19]= 'h:mm:ss AM/PM'; | 
					
						
							|  |  |  | 	t[20]= 'h:mm'; | 
					
						
							|  |  |  | 	t[21]= 'h:mm:ss'; | 
					
						
							|  |  |  | 	t[22]= 'm/d/yy h:mm'; | 
					
						
							|  |  |  | 	t[37]= '#,##0 ;(#,##0)'; | 
					
						
							|  |  |  | 	t[38]= '#,##0 ;[Red](#,##0)'; | 
					
						
							|  |  |  | 	t[39]= '#,##0.00;(#,##0.00)'; | 
					
						
							|  |  |  | 	t[40]= '#,##0.00;[Red](#,##0.00)'; | 
					
						
							|  |  |  | 	t[45]= 'mm:ss'; | 
					
						
							|  |  |  | 	t[46]= '[h]:mm:ss'; | 
					
						
							|  |  |  | 	t[47]= 'mmss.0'; | 
					
						
							|  |  |  | 	t[48]= '##0.0E+0'; | 
					
						
							|  |  |  | 	t[49]= '@'; | 
					
						
							|  |  |  | 	t[56]= '"上午/下午 "hh"時"mm"分"ss"秒 "'; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	return t; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | /* repeated to satiate webpack */ | 
					
						
							|  |  |  | var table_fmt = { | 
					
						
							|  |  |  | 	0:  'General', | 
					
						
							|  |  |  | 	1:  '0', | 
					
						
							|  |  |  | 	2:  '0.00', | 
					
						
							|  |  |  | 	3:  '#,##0', | 
					
						
							|  |  |  | 	4:  '#,##0.00', | 
					
						
							|  |  |  | 	9:  '0%', | 
					
						
							|  |  |  | 	10: '0.00%', | 
					
						
							|  |  |  | 	11: '0.00E+00', | 
					
						
							|  |  |  | 	12: '# ?/?', | 
					
						
							|  |  |  | 	13: '# ??/??', | 
					
						
							|  |  |  | 	14: 'm/d/yy', | 
					
						
							|  |  |  | 	15: 'd-mmm-yy', | 
					
						
							|  |  |  | 	16: 'd-mmm', | 
					
						
							|  |  |  | 	17: 'mmm-yy', | 
					
						
							|  |  |  | 	18: 'h:mm AM/PM', | 
					
						
							|  |  |  | 	19: 'h:mm:ss AM/PM', | 
					
						
							|  |  |  | 	20: 'h:mm', | 
					
						
							|  |  |  | 	21: 'h:mm:ss', | 
					
						
							|  |  |  | 	22: 'm/d/yy h:mm', | 
					
						
							|  |  |  | 	37: '#,##0 ;(#,##0)', | 
					
						
							|  |  |  | 	38: '#,##0 ;[Red](#,##0)', | 
					
						
							|  |  |  | 	39: '#,##0.00;(#,##0.00)', | 
					
						
							|  |  |  | 	40: '#,##0.00;[Red](#,##0.00)', | 
					
						
							|  |  |  | 	45: 'mm:ss', | 
					
						
							|  |  |  | 	46: '[h]:mm:ss', | 
					
						
							|  |  |  | 	47: 'mmss.0', | 
					
						
							|  |  |  | 	48: '##0.0E+0', | 
					
						
							|  |  |  | 	49: '@', | 
					
						
							|  |  |  | 	56: '"上午/下午 "hh"時"mm"分"ss"秒 "' | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | /* Defaults determined by systematically testing in Excel 2019 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* These formats appear to default to other formats in the table */ | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | var SSF_default_map = { | 
					
						
							|  |  |  | 	5:  37, 6:  38, 7:  39, 8:  40,         //  5 -> 37 ...  8 -> 40
 | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	23:  0, 24:  0, 25:  0, 26:  0,         // 23 ->  0 ... 26 ->  0
 | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	27: 14, 28: 14, 29: 14, 30: 14, 31: 14, // 27 -> 14 ... 31 -> 14
 | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	50: 14, 51: 14, 52: 14, 53: 14, 54: 14, // 50 -> 14 ... 58 -> 14
 | 
					
						
							|  |  |  | 	55: 14, 56: 14, 57: 14, 58: 14, | 
					
						
							|  |  |  | 	59:  1, 60:  2, 61:  3, 62:  4,         // 59 ->  1 ... 62 ->  4
 | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	67:  9, 68: 10,                         // 67 ->  9 ... 68 -> 10
 | 
					
						
							|  |  |  | 	69: 12, 70: 13, 71: 14,                 // 69 -> 12 ... 71 -> 14
 | 
					
						
							|  |  |  | 	72: 14, 73: 15, 74: 16, 75: 17,         // 72 -> 14 ... 75 -> 17
 | 
					
						
							|  |  |  | 	76: 20, 77: 21, 78: 22,                 // 76 -> 20 ... 78 -> 22
 | 
					
						
							|  |  |  | 	79: 45, 80: 46, 81: 47,                 // 79 -> 45 ... 81 -> 47
 | 
					
						
							|  |  |  | 	82: 0                                   // 82 ->  0 ... 65536 -> 0 (omitted)
 | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* These formats technically refer to Accounting formats with no equivalent */ | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | var SSF_default_str = { | 
					
						
							| 
									
										
										
										
											2022-03-11 05:29:05 +00:00
										 |  |  | 	//  5 -- Currency,   0 decimal, black negative
 | 
					
						
							|  |  |  | 	5:  '"$"#,##0_);\\("$"#,##0\\)', | 
					
						
							|  |  |  | 	63: '"$"#,##0_);\\("$"#,##0\\)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//  6 -- Currency,   0 decimal, red   negative
 | 
					
						
							|  |  |  | 	6:  '"$"#,##0_);[Red]\\("$"#,##0\\)', | 
					
						
							|  |  |  | 	64: '"$"#,##0_);[Red]\\("$"#,##0\\)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//  7 -- Currency,   2 decimal, black negative
 | 
					
						
							|  |  |  | 	7:  '"$"#,##0.00_);\\("$"#,##0.00\\)', | 
					
						
							|  |  |  | 	65: '"$"#,##0.00_);\\("$"#,##0.00\\)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//  8 -- Currency,   2 decimal, red   negative
 | 
					
						
							|  |  |  | 	8:  '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', | 
					
						
							|  |  |  | 	66: '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 41 -- Accounting, 0 decimal, No Symbol
 | 
					
						
							|  |  |  | 	41: '_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 42 -- Accounting, 0 decimal, $  Symbol
 | 
					
						
							|  |  |  | 	42: '_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 43 -- Accounting, 2 decimal, No Symbol
 | 
					
						
							|  |  |  | 	43: '_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 44 -- Accounting, 2 decimal, $  Symbol
 | 
					
						
							|  |  |  | 	44: '_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)' | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_frac(x/*:number*/, D/*:number*/, mixed/*:?boolean*/)/*:Array<number>*/ { | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	var sgn = x < 0 ? -1 : 1; | 
					
						
							|  |  |  | 	var B = x * sgn; | 
					
						
							|  |  |  | 	var P_2 = 0, P_1 = 1, P = 0; | 
					
						
							|  |  |  | 	var Q_2 = 1, Q_1 = 0, Q = 0; | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 	var A = Math.floor(B); | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	while(Q_1 < D) { | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 		A = Math.floor(B); | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 		P = A * P_1 + P_2; | 
					
						
							|  |  |  | 		Q = A * Q_1 + Q_2; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		if((B - A) < 0.00000005) break; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 		B = 1 / (B - A); | 
					
						
							|  |  |  | 		P_2 = P_1; P_1 = P; | 
					
						
							|  |  |  | 		Q_2 = Q_1; Q_1 = Q; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 	if(Q > D) { if(Q_1 > D) { Q = Q_2; P = P_2; } else { Q = Q_1; P = P_1; } } | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	if(!mixed) return [0, sgn * P, Q]; | 
					
						
							|  |  |  | 	var q = Math.floor(sgn * P/Q); | 
					
						
							|  |  |  | 	return [q, sgn*P - q*Q, Q]; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | function SSF_normalize_xl_unsafe(v/*:number*/)/*:number*/ { | 
					
						
							|  |  |  | 	var s = v.toPrecision(16); | 
					
						
							|  |  |  | 	if(s.indexOf("e") > -1) { | 
					
						
							|  |  |  | 		var m = s.slice(0, s.indexOf("e")); | 
					
						
							|  |  |  | 		m = m.indexOf(".") > -1 ? m.slice(0, (m.slice(0,2) == "0." ? 17 : 16)) : (m.slice(0,15) + fill("0", m.length - 15)); | 
					
						
							|  |  |  | 		return m + s.slice(s.indexOf("e")); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var n = s.indexOf(".") > -1 ? s.slice(0, (s.slice(0,2) == "0." ? 17 : 16)) : (s.slice(0,15) + fill("0", s.length - 15)); | 
					
						
							|  |  |  | 	return Number(n); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_parse_date_code(v/*:number*/,opts/*:?any*/,b2/*:?boolean*/) { | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	if(v > 2958465 || v < 0) return null; | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 	v = SSF_normalize_xl_unsafe(v); | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	var date = (v|0), time = Math.floor(86400 * (v - date)), dow=0; | 
					
						
							|  |  |  | 	var dout=[]; | 
					
						
							|  |  |  | 	var out={D:date, T:time, u:86400*(v-date)-time,y:0,m:0,d:0,H:0,M:0,S:0,q:0}; | 
					
						
							|  |  |  | 	if(Math.abs(out.u) < 1e-6) out.u = 0; | 
					
						
							|  |  |  | 	if(opts && opts.date1904) date += 1462; | 
					
						
							|  |  |  | 	if(out.u > 0.9999) { | 
					
						
							|  |  |  | 		out.u = 0; | 
					
						
							|  |  |  | 		if(++time == 86400) { out.T = time = 0; ++date; ++out.D; } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if(date === 60) {dout = b2 ? [1317,10,29] : [1900,2,29]; dow=3;} | 
					
						
							|  |  |  | 	else if(date === 0) {dout = b2 ? [1317,8,29] : [1900,1,0]; dow=6;} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if(date > 60) --date; | 
					
						
							|  |  |  | 		/* 1 = Jan 1 1900 in Gregorian */ | 
					
						
							|  |  |  | 		var d = new Date(1900, 0, 1); | 
					
						
							|  |  |  | 		d.setDate(d.getDate() + date - 1); | 
					
						
							|  |  |  | 		dout = [d.getFullYear(), d.getMonth()+1,d.getDate()]; | 
					
						
							|  |  |  | 		dow = d.getDay(); | 
					
						
							|  |  |  | 		if(date < 60) dow = (dow + 6) % 7; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		if(b2) dow = SSF_fix_hijri(d, dout); | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	out.y = dout[0]; out.m = dout[1]; out.d = dout[2]; | 
					
						
							|  |  |  | 	out.S = time % 60; time = Math.floor(time / 60); | 
					
						
							|  |  |  | 	out.M = time % 60; time = Math.floor(time / 60); | 
					
						
							|  |  |  | 	out.H = time; | 
					
						
							|  |  |  | 	out.q = dow; | 
					
						
							|  |  |  | 	return out; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | /* ECMA-376 18.8.30 numFmt*/ | 
					
						
							|  |  |  | /* Note: `toPrecision` uses standard form when prec > E and E >= -6 */ | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | /* exponent >= -9 and <= 9 */ | 
					
						
							|  |  |  | function SSF_strip_decimal(o/*:string*/)/*:string*/ { | 
					
						
							|  |  |  | 	return (o.indexOf(".") == -1) ? o : o.replace(/(?:\.0*|(\.\d*[1-9])0+)$/, "$1"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | /* General Exponential always shows 2 digits exp and trims the mantissa */ | 
					
						
							|  |  |  | function SSF_normalize_exp(o/*:string*/)/*:string*/ { | 
					
						
							|  |  |  | 	if(o.indexOf("E") == -1) return o; | 
					
						
							|  |  |  | 	return o.replace(/(?:\.0*|(\.\d*[1-9])0+)[Ee]/,"$1E").replace(/(E[+-])(\d)$/,"$10$2"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | /* exponent >= -9 and <= 9 */ | 
					
						
							|  |  |  | function SSF_small_exp(v/*:number*/)/*:string*/ { | 
					
						
							|  |  |  | 	var w = (v<0?12:11); | 
					
						
							|  |  |  | 	var o = SSF_strip_decimal(v.toFixed(12)); if(o.length <= w) return o; | 
					
						
							|  |  |  | 	o = v.toPrecision(10); if(o.length <= w) return o; | 
					
						
							|  |  |  | 	return v.toExponential(5); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | /* exponent >= 11 or <= -10 likely exponential */ | 
					
						
							|  |  |  | function SSF_large_exp(v/*:number*/)/*:string*/ { | 
					
						
							|  |  |  | 	var o = SSF_strip_decimal(v.toFixed(11)); | 
					
						
							|  |  |  | 	return (o.length > (v<0?12:11) || o === "0" || o === "-0") ? v.toPrecision(6) : o; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_general_num(v/*:number*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2024-07-04 19:54:34 +00:00
										 |  |  | 	if(!isFinite(v)) return isNaN(v) ? "#NUM!" : "#DIV/0!"; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	var V = Math.floor(Math.log(Math.abs(v))*Math.LOG10E), o; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	if(V >= -4 && V <= -1) o = v.toPrecision(10+V); | 
					
						
							|  |  |  | 	else if(Math.abs(V) <= 9) o = SSF_small_exp(v); | 
					
						
							|  |  |  | 	else if(V === 10) o = v.toFixed(10).substr(0,12); | 
					
						
							|  |  |  | 	else o = SSF_large_exp(v); | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	return SSF_strip_decimal(SSF_normalize_exp(o.toUpperCase())); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | 	"General" rules: | 
					
						
							|  |  |  | 	- text is passed through ("@") | 
					
						
							|  |  |  | 	- booleans are rendered as TRUE/FALSE | 
					
						
							|  |  |  | 	- "up to 11 characters" displayed for numbers | 
					
						
							|  |  |  | 	- Default date format (code 14) used for Dates | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-17 04:38:06 +00:00
										 |  |  | 	The longest 32-bit integer text is "-2147483648", exactly 11 chars | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 	TODO: technically the display depends on the width of the cell | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_general(v/*:any*/, opts/*:any*/) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	switch(typeof v) { | 
					
						
							|  |  |  | 		case 'string': return v; | 
					
						
							|  |  |  | 		case 'boolean': return v ? "TRUE" : "FALSE"; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		case 'number': return (v|0) === v ? v.toString(10) : SSF_general_num(v); | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		case 'undefined': return ""; | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 		case 'object': | 
					
						
							|  |  |  | 			if(v == null) return ""; | 
					
						
							| 
									
										
										
										
											2023-06-23 09:48:47 +00:00
										 |  |  | 			if(v instanceof Date) return SSF_format(14, datenum(v, opts && opts.date1904), opts); | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-17 08:44:22 +00:00
										 |  |  | 	throw new Error("unsupported value in General format: " + v); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | function SSF_fix_hijri(date/*:Date*/, o/*:[number, number, number]*/) { | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  |   /* TODO: properly adjust y/m/d and  */ | 
					
						
							|  |  |  |   o[0] -= 581; | 
					
						
							|  |  |  |   var dow = date.getDay(); | 
					
						
							|  |  |  |   if(date < 60) dow = (dow + 6) % 7; | 
					
						
							|  |  |  |   return dow; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //var THAI_DIGITS = "\u0E50\u0E51\u0E52\u0E53\u0E54\u0E55\u0E56\u0E57\u0E58\u0E59".split("");
 | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_write_date(type/*:number*/, fmt/*:string*/, val, ss0/*:?number*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var o="", ss=0, tt=0, y = val.y, out, outl = 0; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	switch(type) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case 98: /* 'b' buddhist year */ | 
					
						
							|  |  |  | 			y = val.y + 543; | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 			/* falls through */ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case 121: /* 'y' year */ | 
					
						
							|  |  |  | 		switch(fmt.length) { | 
					
						
							|  |  |  | 			case 1: case 2: out = y % 100; outl = 2; break; | 
					
						
							|  |  |  | 			default: out = y % 10000; outl = 4; break; | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case 109: /* 'm' month */ | 
					
						
							|  |  |  | 		switch(fmt.length) { | 
					
						
							|  |  |  | 			case 1: case 2: out = val.m; outl = fmt.length; break; | 
					
						
							|  |  |  | 			case 3: return months[val.m-1][1]; | 
					
						
							|  |  |  | 			case 5: return months[val.m-1][0]; | 
					
						
							| 
									
										
										
										
											2014-02-12 06:09:42 +00:00
										 |  |  | 			default: return months[val.m-1][2]; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case 100: /* 'd' day */ | 
					
						
							|  |  |  | 		switch(fmt.length) { | 
					
						
							|  |  |  | 			case 1: case 2: out = val.d; outl = fmt.length; break; | 
					
						
							|  |  |  | 			case 3: return days[val.q][0]; | 
					
						
							| 
									
										
										
										
											2014-02-12 06:09:42 +00:00
										 |  |  | 			default: return days[val.q][1]; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case 104: /* 'h' 12-hour */ | 
					
						
							|  |  |  | 		switch(fmt.length) { | 
					
						
							|  |  |  | 			case 1: case 2: out = 1+(val.H+11)%12; outl = fmt.length; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 			default: throw 'bad hour format: ' + fmt; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case 72: /* 'H' 24-hour */ | 
					
						
							|  |  |  | 		switch(fmt.length) { | 
					
						
							|  |  |  | 			case 1: case 2: out = val.H; outl = fmt.length; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 			default: throw 'bad hour format: ' + fmt; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case 77: /* 'M' minutes */ | 
					
						
							|  |  |  | 		switch(fmt.length) { | 
					
						
							|  |  |  | 			case 1: case 2: out = val.M; outl = fmt.length; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 			default: throw 'bad minute format: ' + fmt; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case 115: /* 's' seconds */ | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 			if(fmt != 's' && fmt != 'ss' && fmt != '.0' && fmt != '.00' && fmt != '.000') throw 'bad second format: ' + fmt; | 
					
						
							|  |  |  | 			if(val.u === 0 && (fmt == "s" || fmt == "ss")) return pad0(val.S, fmt.length); | 
					
						
							|  |  |  | 			/*::if(!ss0) ss0 = 0; */ | 
					
						
							|  |  |  | 			if(ss0 >= 2) tt = ss0 === 3 ? 1000 : 100; | 
					
						
							|  |  |  | 			else tt = ss0 === 1 ? 10 : 1; | 
					
						
							|  |  |  | 			ss = Math.round((tt)*(val.S + val.u)); | 
					
						
							|  |  |  | 			if(ss >= 60*tt) ss = 0; | 
					
						
							|  |  |  | 			if(fmt === 's') return ss === 0 ? "0" : ""+ss/tt; | 
					
						
							|  |  |  | 			o = pad0(ss,2 + ss0); | 
					
						
							|  |  |  | 			if(fmt === 'ss') return o.substr(0,2); | 
					
						
							|  |  |  | 			return "." + o.substr(2,fmt.length-1); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case 90: /* 'Z' absolute time */ | 
					
						
							|  |  |  | 		switch(fmt) { | 
					
						
							|  |  |  | 			case '[h]': case '[hh]': out = val.D*24+val.H; break; | 
					
						
							|  |  |  | 			case '[m]': case '[mm]': out = (val.D*24+val.H)*60+val.M; break; | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 			case '[s]': case '[ss]': out = ((val.D*24+val.H)*60+val.M)*60+(ss0 == 0 ? Math.round(val.S+val.u) : val.S); break; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 			default: throw 'bad abstime format: ' + fmt; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		} outl = fmt.length === 3 ? 1 : 2; break; | 
					
						
							|  |  |  | 		case 101: /* 'e' era */ | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 			out = y; outl = 1; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 	var outstr = outl > 0 ? pad0(out, outl) : ""; | 
					
						
							|  |  |  | 	return outstr; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*jshint -W086 */ | 
					
						
							| 
									
										
										
										
											2014-01-22 04:58:26 +00:00
										 |  |  | /*jshint +W086 */ | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function commaify(s/*:string*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	var w = 3; | 
					
						
							|  |  |  | 	if(s.length <= w) return s; | 
					
						
							|  |  |  | 	var j = (s.length % w), o = s.substr(0,j); | 
					
						
							|  |  |  | 	for(; j!=s.length; j+=w) o+=(o.length > 0 ? "," : "") + s.substr(j,w); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	return o; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | var pct1 = /%/g; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_pct(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/{ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var sfmt = fmt.replace(pct1,""), mul = fmt.length - sfmt.length; | 
					
						
							|  |  |  | 	return write_num(type, sfmt, val * Math.pow(10,2*mul)) + fill("%",mul); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_cm(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/{ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var idx = fmt.length - 1; | 
					
						
							|  |  |  | 	while(fmt.charCodeAt(idx-1) === 44) --idx; | 
					
						
							|  |  |  | 	return write_num(type, fmt.substr(0,idx), val / Math.pow(10,3*(fmt.length-idx))); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_exp(fmt/*:string*/, val/*:number*/)/*:string*/{ | 
					
						
							|  |  |  | 	var o/*:string*/; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1; | 
					
						
							|  |  |  | 	if(fmt.match(/^#+0.0E\+0$/)) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		if(val == 0) return "0.0E+0"; | 
					
						
							|  |  |  | 		else if(val < 0) return "-" + write_num_exp(fmt, -val); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		var ee = Math.floor(Math.log(val)*Math.LOG10E)%period; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		if(ee < 0) ee += period; | 
					
						
							|  |  |  | 		o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | 
					
						
							|  |  |  | 		if(o.indexOf("e") === -1) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 			var fakee = Math.floor(Math.log(val)*Math.LOG10E); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 			if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 			else o += "E+" + (fakee - ee); | 
					
						
							|  |  |  | 			while(o.substr(0,2) === "0.") { | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 				o = o.charAt(0) + o.substr(2,period) + "." + o.substr(2+period); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				o = o.replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0."); | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 			o = o.replace(/\+-/,"-"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		o = o.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; }); | 
					
						
							|  |  |  | 	} else o = val.toExponential(idx); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if(fmt.match(/E\+00$/) && o.match(/e[+-]\d$/)) o = o.substr(0,o.length-1) + "0" + o.charAt(o.length-1); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(fmt.match(/E\-/) && o.match(/e\+/)) o = o.replace(/e\+/,"e"); | 
					
						
							|  |  |  | 	return o.replace("e","E"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | var frac1 = /# (\?+)( ?)\/( ?)(\d+)/; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_f1(r/*:Array<string>*/, aval/*:number*/, sign/*:string*/)/*:string*/ { | 
					
						
							|  |  |  | 	var den = parseInt(r[4],10), rr = Math.round(aval * den), base = Math.floor(rr/den); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var myn = (rr - base*den), myd = den; | 
					
						
							|  |  |  | 	return sign + (base === 0 ? "" : ""+base) + " " + (myn === 0 ? fill(" ", r[1].length + 1 + r[4].length) : pad_(myn,r[1].length) + r[2] + "/" + r[3] + pad0(myd,r[4].length)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_f2(r/*:Array<string>*/, aval/*:number*/, sign/*:string*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	return sign + (aval === 0 ? "" : ""+aval) + fill(" ", r[1].length + 2 + r[4].length); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | var dec1 = /^#*0*\.([0#]+)/; | 
					
						
							| 
									
										
										
										
											2024-04-05 01:20:28 +00:00
										 |  |  | var closeparen = /\)[^)]*[0#]/; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | var phone = /\(###\) ###\\?-####/; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function hashq(str/*:string*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var o = "", cc; | 
					
						
							|  |  |  | 	for(var i = 0; i != str.length; ++i) switch((cc=str.charCodeAt(i))) { | 
					
						
							|  |  |  | 		case 35: break; | 
					
						
							|  |  |  | 		case 63: o+= " "; break; | 
					
						
							|  |  |  | 		case 48: o+= "0"; break; | 
					
						
							|  |  |  | 		default: o+= String.fromCharCode(cc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return o; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function rnd(val/*:number*/, d/*:number*/)/*:string*/ { var dd = Math.pow(10,d); return ""+(Math.round(val * dd)/dd); } | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | function dec(val/*:number*/, d/*:number*/)/*:number*/ { | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 	var _frac = val - Math.floor(val), dd = Math.pow(10,d); | 
					
						
							|  |  |  | 	if (d < ('' + Math.round(_frac * dd)).length) return 0; | 
					
						
							|  |  |  | 	return Math.round(_frac * dd); | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | function carry(val/*:number*/, d/*:number*/)/*:number*/ { | 
					
						
							|  |  |  | 	if (d < ('' + Math.round((val-Math.floor(val))*Math.pow(10,d))).length) { | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | function flr(val/*:number*/)/*:string*/ { | 
					
						
							|  |  |  | 	if(val < 2147483647 && val > -2147483648) return ""+(val >= 0 ? (val|0) : (val-1|0)); | 
					
						
							|  |  |  | 	return ""+Math.floor(val); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_flt(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(type.charCodeAt(0) === 40 && !fmt.match(closeparen)) { | 
					
						
							|  |  |  | 		var ffmt = fmt.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,""); | 
					
						
							|  |  |  | 		if(val >= 0) return write_num_flt('n', ffmt, val); | 
					
						
							|  |  |  | 		return '(' + write_num_flt('n', ffmt, -val) + ')'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if(fmt.charCodeAt(fmt.length - 1) === 44) return write_num_cm(type, fmt, val); | 
					
						
							|  |  |  | 	if(fmt.indexOf('%') !== -1) return write_num_pct(type, fmt, val); | 
					
						
							|  |  |  | 	if(fmt.indexOf('E') !== -1) return write_num_exp(fmt, val); | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 	if(fmt.charCodeAt(0) === 36) return "$"+write_num_flt(type,fmt.substr(fmt.charAt(1)==' '?2:1),val); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	var o; | 
					
						
							|  |  |  | 	var r/*:?Array<string>*/, ri, ff, aval = Math.abs(val), sign = val < 0 ? "-" : ""; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(fmt.match(/^00+$/)) return sign + pad0r(aval,fmt.length); | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 	if(fmt.match(/^[#?]+$/)) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = pad0r(val,0); if(o === "0") o = ""; | 
					
						
							|  |  |  | 		return o.length > fmt.length ? o : hashq(fmt.substr(0,fmt.length-o.length)) + o; | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(frac1))) return write_num_f1(r, aval, sign); | 
					
						
							|  |  |  | 	if(fmt.match(/^#+0+$/)) return sign + pad0r(aval,fmt.length - fmt.indexOf("0")); | 
					
						
							|  |  |  | 	if((r = fmt.match(dec1))) { | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | 		o = rnd(val, r[1].length).replace(/^([^\.]+)$/,"$1."+hashq(r[1])).replace(/\.$/,"."+hashq(r[1])).replace(/\.(\d*)$/,function($$, $1) { return "." + $1 + fill("0", hashq(/*::(*/r/*::||[""])*/[1]).length-$1.length); }); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return fmt.indexOf("0.") !== -1 ? o : o.replace(/^0\./,"."); | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 	fmt = fmt.replace(/^#+([0.])/, "$1"); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^(0*)\.(#*)$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return sign + rnd(aval, r[2].length).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":"."); | 
					
						
							| 
									
										
										
										
											2014-02-17 08:44:22 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 	if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify(pad0r(aval,0)); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^#,##0\.([#0]*0)$/))) { | 
					
						
							| 
									
										
										
										
											2017-03-18 00:45:06 +00:00
										 |  |  | 		return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(""+(Math.floor(val) + carry(val, r[1].length))) + "." + pad0(dec(val, r[1].length),r[1].length); | 
					
						
							| 
									
										
										
										
											2014-02-17 08:44:22 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^#,#*,#0/))) return write_num_flt(type,fmt.replace(/^#,#*,/,""),val); | 
					
						
							|  |  |  | 	if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = _strrev(write_num_flt(type, fmt.replace(/[\\-]/g,""), val)); | 
					
						
							|  |  |  | 		ri = 0; | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 		return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return ri<o.length?o.charAt(ri++):x==='0'?'0':"";})); | 
					
						
							| 
									
										
										
										
											2014-03-29 22:53:15 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if(fmt.match(phone)) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = write_num_flt(type, "##########", val); | 
					
						
							|  |  |  | 		return "(" + o.substr(0,3) + ") " + o.substr(3, 3) + "-" + o.substr(6); | 
					
						
							| 
									
										
										
										
											2014-03-29 22:53:15 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 	var oa = ""; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) { | 
					
						
							|  |  |  | 		ri = Math.min(/*::String(*/r[4]/*::)*/.length,7); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		ff = SSF_frac(aval, Math.pow(10,ri)-1, false); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = "" + sign; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 		oa = write_num("n", /*::String(*/r[1]/*::)*/, ff[1]); | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 		if(oa.charAt(oa.length-1) == " ") oa = oa.substr(0,oa.length-1) + "0"; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 		o += oa + /*::String(*/r[2]/*::)*/ + "/" + /*::String(*/r[3]/*::)*/; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		oa = rpad_(ff[2],ri); | 
					
						
							|  |  |  | 		if(oa.length < r[4].length) oa = hashq(r[4].substr(r[4].length-oa.length)) + oa; | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 		o += oa; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return o; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		ri = Math.min(Math.max(r[1].length, r[4].length),7); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		ff = SSF_frac(aval, Math.pow(10,ri)-1, true); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad_(ff[1],ri) + r[2] + "/" + r[3] + rpad_(ff[2],ri): fill(" ", 2*ri+1 + r[2].length + r[3].length)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^[#0?]+$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = pad0r(val, 0); | 
					
						
							|  |  |  | 		if(fmt.length <= o.length) return o; | 
					
						
							|  |  |  | 		return hashq(fmt.substr(0,fmt.length-o.length)) + o; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^([#0?]+)\.([#0]+)$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1"); | 
					
						
							|  |  |  | 		ri = o.indexOf("."); | 
					
						
							|  |  |  | 		var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres; | 
					
						
							|  |  |  | 		return hashq(fmt.substr(0,lres) + o + fmt.substr(fmt.length-rres)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^00,000\.([#0]*0)$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		ri = dec(val, r[1].length); | 
					
						
							|  |  |  | 		return val < 0 ? "-" + write_num_flt(type, fmt, -val) : commaify(flr(val)).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function($$) { return "00," + ($$.length < 3 ? pad0(0,3-$$.length) : "") + $$; }) + "." + pad0(ri,r[1].length); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	switch(fmt) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		case "###,##0.00": return write_num_flt(type, "#,##0.00", val); | 
					
						
							|  |  |  | 		case "###,###": | 
					
						
							|  |  |  | 		case "##,###": | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case "#,###": var x = commaify(pad0r(aval,0)); return x !== "0" ? sign + x : ""; | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		case "###,###.00": return write_num_flt(type, "###,##0.00",val).replace(/^0\./,"."); | 
					
						
							|  |  |  | 		case "#,###.00": return write_num_flt(type, "#,##0.00",val).replace(/^0\./,"."); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	throw new Error("unsupported format |" + fmt + "|"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_cm2(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/{ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var idx = fmt.length - 1; | 
					
						
							|  |  |  | 	while(fmt.charCodeAt(idx-1) === 44) --idx; | 
					
						
							|  |  |  | 	return write_num(type, fmt.substr(0,idx), val / Math.pow(10,3*(fmt.length-idx))); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_pct2(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/{ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var sfmt = fmt.replace(pct1,""), mul = fmt.length - sfmt.length; | 
					
						
							|  |  |  | 	return write_num(type, sfmt, val * Math.pow(10,2*mul)) + fill("%",mul); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_exp2(fmt/*:string*/, val/*:number*/)/*:string*/{ | 
					
						
							|  |  |  | 	var o/*:string*/; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var idx = fmt.indexOf("E") - fmt.indexOf(".") - 1; | 
					
						
							|  |  |  | 	if(fmt.match(/^#+0.0E\+0$/)) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		if(val == 0) return "0.0E+0"; | 
					
						
							|  |  |  | 		else if(val < 0) return "-" + write_num_exp2(fmt, -val); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		var period = fmt.indexOf("."); if(period === -1) period=fmt.indexOf('E'); | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		var ee = Math.floor(Math.log(val)*Math.LOG10E)%period; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		if(ee < 0) ee += period; | 
					
						
							|  |  |  | 		o = (val/Math.pow(10,ee)).toPrecision(idx+1+(period+ee)%period); | 
					
						
							|  |  |  | 		if(!o.match(/[Ee]/)) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 			var fakee = Math.floor(Math.log(val)*Math.LOG10E); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 			if(o.indexOf(".") === -1) o = o.charAt(0) + "." + o.substr(1) + "E+" + (fakee - o.length+ee); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 			else o += "E+" + (fakee - ee); | 
					
						
							|  |  |  | 			o = o.replace(/\+-/,"-"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		o = o.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function($$,$1,$2,$3) { return $1 + $2 + $3.substr(0,(period+ee)%period) + "." + $3.substr(ee) + "E"; }); | 
					
						
							|  |  |  | 	} else o = val.toExponential(idx); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if(fmt.match(/E\+00$/) && o.match(/e[+-]\d$/)) o = o.substr(0,o.length-1) + "0" + o.charAt(o.length-1); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(fmt.match(/E\-/) && o.match(/e\+/)) o = o.replace(/e\+/,"e"); | 
					
						
							|  |  |  | 	return o.replace("e","E"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function write_num_int(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(type.charCodeAt(0) === 40 && !fmt.match(closeparen)) { | 
					
						
							|  |  |  | 		var ffmt = fmt.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,""); | 
					
						
							|  |  |  | 		if(val >= 0) return write_num_int('n', ffmt, val); | 
					
						
							|  |  |  | 		return '(' + write_num_int('n', ffmt, -val) + ')'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if(fmt.charCodeAt(fmt.length - 1) === 44) return write_num_cm2(type, fmt, val); | 
					
						
							|  |  |  | 	if(fmt.indexOf('%') !== -1) return write_num_pct2(type, fmt, val); | 
					
						
							|  |  |  | 	if(fmt.indexOf('E') !== -1) return write_num_exp2(fmt, val); | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 	if(fmt.charCodeAt(0) === 36) return "$"+write_num_int(type,fmt.substr(fmt.charAt(1)==' '?2:1),val); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var o; | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 	var r/*:?Array<string>*/, ri, ff, aval = Math.abs(val), sign = val < 0 ? "-" : ""; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(fmt.match(/^00+$/)) return sign + pad0(aval,fmt.length); | 
					
						
							|  |  |  | 	if(fmt.match(/^[#?]+$/)) { | 
					
						
							|  |  |  | 		o = (""+val); if(val === 0) o = ""; | 
					
						
							|  |  |  | 		return o.length > fmt.length ? o : hashq(fmt.substr(0,fmt.length-o.length)) + o; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(frac1))) return write_num_f2(r, aval, sign); | 
					
						
							|  |  |  | 	if(fmt.match(/^#+0+$/)) return sign + pad0(aval,fmt.length - fmt.indexOf("0")); | 
					
						
							|  |  |  | 	if((r = fmt.match(dec1))) { | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		/*:: if(!Array.isArray(r)) throw new Error("unreachable"); */ | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | 		o = (""+val).replace(/^([^\.]+)$/,"$1."+hashq(r[1])).replace(/\.$/,"."+hashq(r[1])); | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 		o = o.replace(/\.(\d*)$/,function($$, $1) { | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		/*:: if(!Array.isArray(r)) throw new Error("unreachable"); */ | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | 			return "." + $1 + fill("0", hashq(r[1]).length-$1.length); }); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return fmt.indexOf("0.") !== -1 ? o : o.replace(/^0\./,"."); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fmt = fmt.replace(/^#+([0.])/, "$1"); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^(0*)\.(#*)$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return sign + (""+aval).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":"."); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 	if((r = fmt.match(/^#{1,3},##0(\.?)$/))) return sign + commaify((""+aval)); | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^#,##0\.([#0]*0)$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify((""+val)) + "." + fill('0',r[1].length); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^#,#*,#0/))) return write_num_int(type,fmt.replace(/^#,#*,/,""),val); | 
					
						
							|  |  |  | 	if((r = fmt.match(/^([0#]+)(\\?-([0#]+))+$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = _strrev(write_num_int(type, fmt.replace(/[\\-]/g,""), val)); | 
					
						
							|  |  |  | 		ri = 0; | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 		return _strrev(_strrev(fmt.replace(/\\/g,"")).replace(/[0#]/g,function(x){return ri<o.length?o.charAt(ri++):x==='0'?'0':"";})); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if(fmt.match(phone)) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = write_num_int(type, "##########", val); | 
					
						
							|  |  |  | 		return "(" + o.substr(0,3) + ") " + o.substr(3, 3) + "-" + o.substr(6); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var oa = ""; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		ri = Math.min(/*::String(*/r[4]/*::)*/.length,7); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		ff = SSF_frac(aval, Math.pow(10,ri)-1, false); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = "" + sign; | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		oa = write_num("n", /*::String(*/r[1]/*::)*/, ff[1]); | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 		if(oa.charAt(oa.length-1) == " ") oa = oa.substr(0,oa.length-1) + "0"; | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		o += oa + /*::String(*/r[2]/*::)*/ + "/" + /*::String(*/r[3]/*::)*/; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		oa = rpad_(ff[2],ri); | 
					
						
							|  |  |  | 		if(oa.length < r[4].length) oa = hashq(r[4].substr(r[4].length-oa.length)) + oa; | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 		o += oa; | 
					
						
							|  |  |  | 		return o; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		ri = Math.min(Math.max(r[1].length, r[4].length),7); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		ff = SSF_frac(aval, Math.pow(10,ri)-1, true); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad_(ff[1],ri) + r[2] + "/" + r[3] + rpad_(ff[2],ri): fill(" ", 2*ri+1 + r[2].length + r[3].length)); | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^[#0?]+$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		o = "" + val; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 		if(fmt.length <= o.length) return o; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return hashq(fmt.substr(0,fmt.length-o.length)) + o; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^([#0]+)\.([#0]+)$/))) { | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 		o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1"); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		ri = o.indexOf("."); | 
					
						
							|  |  |  | 		var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres; | 
					
						
							|  |  |  | 		return hashq(fmt.substr(0,lres) + o + fmt.substr(fmt.length-rres)); | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if((r = fmt.match(/^00,000\.([#0]*0)$/))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		return val < 0 ? "-" + write_num_int(type, fmt, -val) : commaify(""+val).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function($$) { return "00," + ($$.length < 3 ? pad0(0,3-$$.length) : "") + $$; }) + "." + pad0(0,r[1].length); | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	switch(fmt) { | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 		case "###,###": | 
					
						
							|  |  |  | 		case "##,###": | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case "#,###": var x = commaify(""+aval); return x !== "0" ? sign + x : ""; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 			if(fmt.match(/\.[0#?]*$/)) return write_num_int(type, fmt.slice(0,fmt.lastIndexOf(".")), val) + hashq(fmt.slice(fmt.lastIndexOf("."))); | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	throw new Error("unsupported format |" + fmt + "|"); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function write_num(type/*:string*/, fmt/*:string*/, val/*:number*/)/*:string*/ { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	return (val|0) === val ? write_num_int(type, fmt, val) : write_num_flt(type, fmt, val); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | function SSF_split_fmt(fmt/*:string*/)/*:Array<string>*/ { | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	var out/*:Array<string>*/ = []; | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 	var in_str = false/*, cc*/; | 
					
						
							|  |  |  | 	for(var i = 0, j = 0; i < fmt.length; ++i) switch((/*cc=*/fmt.charCodeAt(i))) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case 34: /* '"' */ | 
					
						
							|  |  |  | 			in_str = !in_str; break; | 
					
						
							|  |  |  | 		case 95: case 42: case 92: /* '_' '*' '\\' */ | 
					
						
							|  |  |  | 			++i; break; | 
					
						
							|  |  |  | 		case 59: /* ';' */ | 
					
						
							|  |  |  | 			out[out.length] = fmt.substr(j,i-j); | 
					
						
							|  |  |  | 			j = i+1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	out[out.length] = fmt.substr(j); | 
					
						
							|  |  |  | 	if(in_str === true) throw new Error("Format |" + fmt + "| unterminated string "); | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	return out; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | var SSF_abstime = /\[[HhMmSs\u0E0A\u0E19\u0E17]*\]/; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | function fmt_is_date(fmt/*:string*/)/*:boolean*/ { | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 	var i = 0, /*cc = 0,*/ c = "", o = ""; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 	while(i < fmt.length) { | 
					
						
							|  |  |  | 		switch((c = fmt.charAt(i))) { | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 			case 'G': if(SSF_isgeneral(fmt, i)) i+= 6; i++; break; | 
					
						
							| 
									
										
										
										
											2020-03-15 07:42:05 +00:00
										 |  |  | 			case '"': for(;(/*cc=*/fmt.charCodeAt(++i)) !== 34 && i < fmt.length;){/*empty*/} ++i; break; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 			case '\\': i+=2; break; | 
					
						
							|  |  |  | 			case '_': i+=2; break; | 
					
						
							|  |  |  | 			case '@': ++i; break; | 
					
						
							|  |  |  | 			case 'B': case 'b': | 
					
						
							|  |  |  | 				if(fmt.charAt(i+1) === "1" || fmt.charAt(i+1) === "2") return true; | 
					
						
							|  |  |  | 				/* falls through */ | 
					
						
							|  |  |  | 			case 'M': case 'D': case 'Y': case 'H': case 'S': case 'E': | 
					
						
							|  |  |  | 				/* falls through */ | 
					
						
							|  |  |  | 			case 'm': case 'd': case 'y': case 'h': case 's': case 'e': case 'g': return true; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 			case 'A': case 'a': case '上': | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | 				if(fmt.substr(i, 3).toUpperCase() === "A/P") return true; | 
					
						
							|  |  |  | 				if(fmt.substr(i, 5).toUpperCase() === "AM/PM") return true; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 				if(fmt.substr(i, 5).toUpperCase() === "上午/下午") return true; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				++i; break; | 
					
						
							|  |  |  | 			case '[': | 
					
						
							|  |  |  | 				o = c; | 
					
						
							|  |  |  | 				while(fmt.charAt(i++) !== ']' && i < fmt.length) o += fmt.charAt(i); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 				if(o.match(SSF_abstime)) return true; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			case '.': | 
					
						
							|  |  |  | 				/* falls through */ | 
					
						
							|  |  |  | 			case '0': case '#': | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 				while(i < fmt.length && ("0#?.,E+-%".indexOf(c=fmt.charAt(++i)) > -1 || (c=='\\' && fmt.charAt(i+1) == "-" && "0#".indexOf(fmt.charAt(i+2))>-1))){/* empty */} | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 			case '?': while(fmt.charAt(++i) === c){/* empty */} break; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 			case '*': ++i; if(fmt.charAt(i) == ' ' || fmt.charAt(i) == '*') ++i; break; | 
					
						
							|  |  |  | 			case '(': case ')': ++i; break; | 
					
						
							|  |  |  | 			case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 				while(i < fmt.length && "0123456789".indexOf(fmt.charAt(++i)) > -1){/* empty */} break; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 			case ' ': ++i; break; | 
					
						
							|  |  |  | 			default: ++i; break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | function eval_fmt(fmt/*:string*/, v/*:any*/, opts/*:any*/, flen/*:number*/) { | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	var out = [], o = "", i = 0, c = "", lst='t', dt, j, cc; | 
					
						
							| 
									
										
										
										
											2013-04-17 01:32:20 +00:00
										 |  |  | 	var hr='H'; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	/* Tokenize */ | 
					
						
							|  |  |  | 	while(i < fmt.length) { | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 		switch((c = fmt.charAt(i))) { | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 			case 'G': /* General */ | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 				if(!SSF_isgeneral(fmt, i)) throw new Error('unrecognized character ' + c + ' in ' +fmt); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:'G', v:'General'}; i+=7; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 			case '"': /* Literal text */ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				for(o="";(cc=fmt.charCodeAt(++i)) !== 34 && i < fmt.length;) o += String.fromCharCode(cc); | 
					
						
							|  |  |  | 				out[out.length] = {t:'t', v:o}; ++i; break; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 			case '\\': var w = fmt.charAt(++i), t = (w === "(" || w === ")") ? w : 't'; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:t, v:w}; ++i; break; | 
					
						
							|  |  |  | 			case '_': out[out.length] = {t:'t', v:" "}; i+=2; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 			case '@': /* Text Placeholder */ | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:'T', v:v}; ++i; break; | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 			case 'B': case 'b': | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				if(fmt.charAt(i+1) === "1" || fmt.charAt(i+1) === "2") { | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 					if(dt==null) { dt=SSF_parse_date_code(v, opts, fmt.charAt(i+1) === "2"); if(dt==null) return ""; } | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 					out[out.length] = {t:'X', v:fmt.substr(i,2)}; lst = c; i+=2; break; | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				/* falls through */ | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 			case 'M': case 'D': case 'Y': case 'H': case 'S': case 'E': | 
					
						
							|  |  |  | 				c = c.toLowerCase(); | 
					
						
							|  |  |  | 				/* falls through */ | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			case 'm': case 'd': case 'y': case 'h': case 's': case 'e': case 'g': | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 				if(v < 0) return ""; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 				if(dt==null) { dt=SSF_parse_date_code(v, opts); if(dt==null) return ""; } | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 				o = c; while(++i < fmt.length && fmt.charAt(i).toLowerCase() === c) o+=c; | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 				if(c === 'm' && lst.toLowerCase() === 'h') c = 'M'; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 				if(c === 'h') c = hr; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:c, v:o}; lst = c; break; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 			case 'A': case 'a': case '上': | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 				var q={t:c, v:c}; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 				if(dt==null) dt=SSF_parse_date_code(v, opts); | 
					
						
							| 
									
										
										
										
											2022-04-10 05:41:52 +00:00
										 |  |  | 				if(fmt.substr(i, 3).toUpperCase() === "A/P") { if(dt!=null) q.v = dt.H >= 12 ? fmt.charAt(i+2) : c; q.t = 'T'; hr='h';i+=3;} | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | 				else if(fmt.substr(i,5).toUpperCase() === "AM/PM") { if(dt!=null) q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=5; hr='h'; } | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 				else if(fmt.substr(i,5).toUpperCase() === "上午/下午") { if(dt!=null) q.v = dt.H >= 12 ? "下午" : "上午"; q.t = 'T'; i+=5; hr='h'; } | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				else { q.t = "t"; ++i; } | 
					
						
							|  |  |  | 				if(dt==null && q.t === 'T') return ""; | 
					
						
							|  |  |  | 				out[out.length] = q; lst = c; break; | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 			case '[': | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 				o = c; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				while(fmt.charAt(i++) !== ']' && i < fmt.length) o += fmt.charAt(i); | 
					
						
							|  |  |  | 				if(o.slice(-1) !== ']') throw 'unterminated "[" block: |' + o + '|'; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 				if(o.match(SSF_abstime)) { | 
					
						
							|  |  |  | 					if(dt==null) { dt=SSF_parse_date_code(v, opts); if(dt==null) return ""; } | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 					out[out.length] = {t:'Z', v:o.toLowerCase()}; | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | 					lst = o.charAt(1); | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 				} else if(o.indexOf("$") > -1) { | 
					
						
							|  |  |  | 					o = (o.match(/\$([^-\[\]]*)/)||[])[1]||"$"; | 
					
						
							|  |  |  | 					if(!fmt_is_date(fmt)) out[out.length] = {t:'t',v:o}; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			/* Numbers */ | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 			case '.': | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				if(dt != null) { | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 					o = c; while(++i < fmt.length && (c=fmt.charAt(i)) === "0") o += c; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 					out[out.length] = {t:'s', v:o}; break; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				/* falls through */ | 
					
						
							|  |  |  | 			case '0': case '#': | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 				o = c; while(++i < fmt.length && "0#?.,E+-%".indexOf(c=fmt.charAt(i)) > -1) o += c; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:'n', v:o}; break; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 			case '?': | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				o = c; while(fmt.charAt(++i) === c) o+=c; | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 				out[out.length] = {t:c, v:o}; lst = c; break; | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 			case '*': ++i; if(fmt.charAt(i) == ' ' || fmt.charAt(i) == '*') ++i; break; // **
 | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 			case '(': case ')': out[out.length] = {t:(flen===1?'t':c), v:c}; ++i; break; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 			case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': | 
					
						
							| 
									
										
										
										
											2017-03-21 20:44:35 +00:00
										 |  |  | 				o = c; while(i < fmt.length && "0123456789".indexOf(fmt.charAt(++i)) > -1) o+=fmt.charAt(i); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:'D', v:o}; break; | 
					
						
							|  |  |  | 			case ' ': out[out.length] = {t:c, v:c}; ++i; break; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 			case '$': out[out.length] = {t:'t', v:'$'}; ++i; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2017-06-09 02:15:36 +00:00
										 |  |  | 				if(",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(c) === -1) throw new Error('unrecognized character ' + c + ' in ' + fmt); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[out.length] = {t:'t', v:c}; ++i; break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Scan for date/time parts */ | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 	var bt = 0, ss0 = 0, ssm; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	for(i=out.length-1, lst='t'; i >= 0; --i) { | 
					
						
							|  |  |  | 		switch(out[i].t) { | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			case 'h': case 'H': out[i].t = hr; lst='h'; if(bt < 1) bt = 1; break; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 			case 's': | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 				if((ssm=out[i].v.match(/\.0+$/))) { ss0=Math.max(ss0,ssm[0].length-1); bt = 4;} | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				if(bt < 3) bt = 3; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			/* falls through */ | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 			case 'd': case 'y': case 'e': lst=out[i].t; break; | 
					
						
							|  |  |  | 			case 'M': lst=out[i].t; if(bt < 2) bt = 2; break; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			case 'm': if(lst === 's') { out[i].t = 'M'; if(bt < 2) bt = 2; } break; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 			case 'X': /*if(out[i].v === "B2");*/ | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			case 'Z': | 
					
						
							|  |  |  | 				if(bt < 1 && out[i].v.match(/[Hh]/)) bt = 1; | 
					
						
							|  |  |  | 				if(bt < 2 && out[i].v.match(/[Mm]/)) bt = 2; | 
					
						
							|  |  |  | 				if(bt < 3 && out[i].v.match(/[Ss]/)) bt = 3; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 	/* time rounding depends on presence of minute / second / usec fields */ | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 	var _dt; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 	switch(bt) { | 
					
						
							|  |  |  | 		case 0: break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 		case 2: | 
					
						
							|  |  |  | 		case 3: | 
					
						
							| 
									
										
										
										
											2014-03-29 22:53:15 +00:00
										 |  |  | 			if(dt.u >= 0.5) { dt.u = 0; ++dt.S; } | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 			if(dt.S >=  60) { dt.S = 0; ++dt.M; } | 
					
						
							|  |  |  | 			if(dt.M >=  60) { dt.M = 0; ++dt.H; } | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 			if(dt.H >=  24) { dt.H = 0; ++dt.D; _dt = SSF_parse_date_code(dt.D); _dt.u = dt.u; _dt.S = dt.S; _dt.M = dt.M; _dt.H = dt.H; dt = _dt; } | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 		case 4: | 
					
						
							|  |  |  | 			switch(ss0) { | 
					
						
							|  |  |  | 				case 1: dt.u = Math.round(dt.u * 10)/10; break; | 
					
						
							|  |  |  | 				case 2: dt.u = Math.round(dt.u * 100)/100; break; | 
					
						
							|  |  |  | 				case 3: dt.u = Math.round(dt.u * 1000)/1000; break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(dt.u >=   1) { dt.u = 0; ++dt.S; } | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 			if(dt.S >=  60) { dt.S = 0; ++dt.M; } | 
					
						
							| 
									
										
										
										
											2023-11-13 11:03:35 +00:00
										 |  |  | 			if(dt.M >=  60) { dt.M = 0; ++dt.H; } | 
					
						
							|  |  |  | 			if(dt.H >=  24) { dt.H = 0; ++dt.D; _dt = SSF_parse_date_code(dt.D); _dt.u = dt.u; _dt.S = dt.S; _dt.M = dt.M; _dt.H = dt.H; dt = _dt; } | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	/* replace fields */ | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 	var nstr = "", jj; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 	for(i=0; i < out.length; ++i) { | 
					
						
							|  |  |  | 		switch(out[i].t) { | 
					
						
							| 
									
										
										
										
											2014-02-12 06:09:42 +00:00
										 |  |  | 			case 't': case 'T': case ' ': case 'D': break; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 			case 'X': out[i].v = ""; out[i].t = ";"; break; | 
					
						
							| 
									
										
										
										
											2014-04-03 22:51:54 +00:00
										 |  |  | 			case 'd': case 'm': case 'y': case 'h': case 'H': case 'M': case 's': case 'e': case 'b': case 'Z': | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 				/*::if(!dt) throw "unreachable"; */ | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 				out[i].v = SSF_write_date(out[i].t.charCodeAt(0), out[i].v, dt, ss0); | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 				out[i].t = 't'; break; | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 			case 'n': case '?': | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				jj = i+1; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				while(out[jj] != null && ( | 
					
						
							|  |  |  | 					(c=out[jj].t) === "?" || c === "D" || | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 					((c === " " || c === "t") && out[jj+1] != null && (out[jj+1].t === '?' || out[jj+1].t === "t" && out[jj+1].v === '/')) || | 
					
						
							|  |  |  | 					(out[i].t === '(' && (c === ' ' || c === 'n' || c === ')')) || | 
					
						
							|  |  |  | 					(c === 't' && (out[jj].v === '/' || out[jj].v === ' ' && out[jj+1] != null && out[jj+1].t == '?')) | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				)) { | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 					out[i].v += out[jj].v; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 					out[jj] = {v:"", t:";"}; ++jj; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				nstr += out[i].v; | 
					
						
							| 
									
										
										
										
											2014-01-23 06:20:19 +00:00
										 |  |  | 				i = jj-1; break; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 			case 'G': out[i].t = 't'; out[i].v = SSF_general(v,opts); break; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var vv = "", myv, ostr; | 
					
						
							|  |  |  | 	if(nstr.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		if(nstr.charCodeAt(0) == 40) /* '(' */ { | 
					
						
							|  |  |  | 			myv = (v<0&&nstr.charCodeAt(0) === 45 ? -v : v); | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 			ostr = write_num('n', nstr, myv); | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			myv = (v<0 && flen > 1 ? -v : v); | 
					
						
							|  |  |  | 			ostr = write_num('n', nstr, myv); | 
					
						
							|  |  |  | 			if(myv < 0 && out[0] && out[0].t == 't') { | 
					
						
							|  |  |  | 				ostr = ostr.substr(1); | 
					
						
							|  |  |  | 				out[0].v = "-" + out[0].v; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 		jj=ostr.length-1; | 
					
						
							|  |  |  | 		var decpt = out.length; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		for(i=0; i < out.length; ++i) if(out[i] != null && out[i].t != 't' && out[i].v.indexOf(".") > -1) { decpt = i; break; } | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		var lasti=out.length; | 
					
						
							|  |  |  | 		if(decpt === out.length && ostr.indexOf("E") === -1) { | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 			for(i=out.length-1; i>= 0;--i) { | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 				if(out[i] == null || 'n?'.indexOf(out[i].t) === -1) continue; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				if(jj>=out[i].v.length-1) { jj -= out[i].v.length; out[i].v = ostr.substr(jj+1, out[i].v.length); } | 
					
						
							|  |  |  | 				else if(jj < 0) out[i].v = ""; | 
					
						
							|  |  |  | 				else { out[i].v = ostr.substr(0, jj+1); jj = -1; } | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				out[i].t = 't'; | 
					
						
							|  |  |  | 				lasti = i; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(jj>=0 && lasti<out.length) out[lasti].v = ostr.substr(0,jj+1) + out[lasti].v; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		else if(decpt !== out.length && ostr.indexOf("E") === -1) { | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 			jj = ostr.indexOf(".")-1; | 
					
						
							|  |  |  | 			for(i=decpt; i>= 0; --i) { | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 				if(out[i] == null || 'n?'.indexOf(out[i].t) === -1) continue; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				j=out[i].v.indexOf(".")>-1&&i===decpt?out[i].v.indexOf(".")-1:out[i].v.length-1; | 
					
						
							|  |  |  | 				vv = out[i].v.substr(j+1); | 
					
						
							|  |  |  | 				for(; j>=0; --j) { | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 					if(jj>=0 && (out[i].v.charAt(j) === "0" || out[i].v.charAt(j) === "#")) vv = ostr.charAt(jj--) + vv; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[i].v = vv; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				out[i].t = 't'; | 
					
						
							|  |  |  | 				lasti = i; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(jj>=0 && lasti<out.length) out[lasti].v = ostr.substr(0,jj+1) + out[lasti].v; | 
					
						
							|  |  |  | 			jj = ostr.indexOf(".")+1; | 
					
						
							|  |  |  | 			for(i=decpt; i<out.length; ++i) { | 
					
						
							| 
									
										
										
										
											2017-05-11 07:29:59 +00:00
										 |  |  | 				if(out[i] == null || ('n?('.indexOf(out[i].t) === -1 && i !== decpt)) continue; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				j=out[i].v.indexOf(".")>-1&&i===decpt?out[i].v.indexOf(".")+1:0; | 
					
						
							|  |  |  | 				vv = out[i].v.substr(0,j); | 
					
						
							|  |  |  | 				for(; j<out[i].v.length; ++j) { | 
					
						
							| 
									
										
										
										
											2017-03-25 01:36:40 +00:00
										 |  |  | 					if(jj<ostr.length) vv += ostr.charAt(jj++); | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 				out[i].v = vv; | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 				out[i].t = 't'; | 
					
						
							|  |  |  | 				lasti = i; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-06-29 08:07:23 +00:00
										 |  |  | 	for(i=0; i<out.length; ++i) if(out[i] != null && 'n?'.indexOf(out[i].t)>-1) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		myv = (flen >1 && v < 0 && i>0 && out[i-1].v === "-" ? -v:v); | 
					
						
							|  |  |  | 		out[i].v = write_num(out[i].t, out[i].v, myv); | 
					
						
							| 
									
										
										
										
											2014-05-22 12:16:51 +00:00
										 |  |  | 		out[i].t = 't'; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 	var retval = ""; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	for(i=0; i !== out.length; ++i) if(out[i] != null) retval += out[i].v; | 
					
						
							| 
									
										
										
										
											2014-06-05 07:06:20 +00:00
										 |  |  | 	return retval; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 07:01:34 +00:00
										 |  |  | var cfregex2 = /\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | function chkcond(v, rr) { | 
					
						
							|  |  |  | 	if(rr == null) return false; | 
					
						
							|  |  |  | 	var thresh = parseFloat(rr[2]); | 
					
						
							|  |  |  | 	switch(rr[1]) { | 
					
						
							|  |  |  | 		case "=":  if(v == thresh) return true; break; | 
					
						
							|  |  |  | 		case ">":  if(v >  thresh) return true; break; | 
					
						
							|  |  |  | 		case "<":  if(v <  thresh) return true; break; | 
					
						
							|  |  |  | 		case "<>": if(v != thresh) return true; break; | 
					
						
							|  |  |  | 		case ">=": if(v >= thresh) return true; break; | 
					
						
							|  |  |  | 		case "<=": if(v <= thresh) return true; break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | function choose_fmt(f/*:string*/, v/*:any*/) { | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	var fmt = SSF_split_fmt(f); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var l = fmt.length, lat = fmt[l-1].indexOf("@"); | 
					
						
							|  |  |  | 	if(l<4 && lat>-1) --l; | 
					
						
							| 
									
										
										
										
											2017-03-12 18:02:43 +00:00
										 |  |  | 	if(fmt.length > 4) throw new Error("cannot find right format for |" + fmt.join("|") + "|"); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(typeof v !== "number") return [4, fmt.length === 4 || lat>-1?fmt[fmt.length-1]:"@"]; | 
					
						
							| 
									
										
										
										
											2024-04-27 23:49:12 +00:00
										 |  |  | 	/* NOTE: most spreadsheet software do not support NaN or infinities */ | 
					
						
							|  |  |  | 	if(typeof v === "number" && !isFinite(v)) v = 0; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	switch(fmt.length) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		case 1: fmt = lat>-1 ? ["General", "General", "General", fmt[0]] : [fmt[0], fmt[0], fmt[0], "@"]; break; | 
					
						
							|  |  |  | 		case 2: fmt = lat>-1 ? [fmt[0], fmt[0], fmt[0], fmt[1]] : [fmt[0], fmt[1], fmt[0], "@"]; break; | 
					
						
							|  |  |  | 		case 3: fmt = lat>-1 ? [fmt[0], fmt[1], fmt[0], fmt[2]] : [fmt[0], fmt[1], fmt[2], "@"]; break; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 		case 4: break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-29 22:53:15 +00:00
										 |  |  | 	var ff = v > 0 ? fmt[0] : v < 0 ? fmt[1] : fmt[2]; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(fmt[0].indexOf("[") === -1 && fmt[1].indexOf("[") === -1) return [l, ff]; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	if(fmt[0].match(/\[[=<>]/) != null || fmt[1].match(/\[[=<>]/) != null) { | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 		var m1 = fmt[0].match(cfregex2); | 
					
						
							|  |  |  | 		var m2 = fmt[1].match(cfregex2); | 
					
						
							|  |  |  | 		return chkcond(v, m1) ? [l, fmt[0]] : chkcond(v, m2) ? [l, fmt[1]] : [l, fmt[m1 != null && m2 != null ? 2 : 1]]; | 
					
						
							| 
									
										
										
										
											2014-03-29 22:53:15 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return [l, ff]; | 
					
						
							| 
									
										
										
										
											2013-03-31 22:56:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_format(fmt/*:string|number*/,v/*:any*/,o/*:?any*/) { | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 	if(o == null) o = {}; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var sfmt = ""; | 
					
						
							|  |  |  | 	switch(typeof fmt) { | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 		case "string": | 
					
						
							|  |  |  | 			if(fmt == "m/d/yy" && o.dateNF) sfmt = o.dateNF; | 
					
						
							|  |  |  | 			else sfmt = fmt; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "number": | 
					
						
							|  |  |  | 			if(fmt == 14 && o.dateNF) sfmt = o.dateNF; | 
					
						
							|  |  |  | 			else sfmt = (o.table != null ? (o.table/*:any*/) : table_fmt)[fmt]; | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 			if(sfmt == null) sfmt = (o.table && o.table[SSF_default_map[fmt]]) || table_fmt[SSF_default_map[fmt]]; | 
					
						
							|  |  |  | 			if(sfmt == null) sfmt = SSF_default_str[fmt] || "General"; | 
					
						
							| 
									
										
										
										
											2017-04-30 16:27:03 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	if(SSF_isgeneral(sfmt,0)) return SSF_general(v, o); | 
					
						
							| 
									
										
										
										
											2023-06-23 09:48:47 +00:00
										 |  |  | 	if(v instanceof Date) v = datenum(v, o.date1904); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	var f = choose_fmt(sfmt, v); | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 	if(SSF_isgeneral(f[1])) return SSF_general(v, o); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | 	if(v === true) v = "TRUE"; else if(v === false) v = "FALSE"; | 
					
						
							|  |  |  | 	else if(v === "" || v == null) return ""; | 
					
						
							| 
									
										
										
										
											2024-07-04 19:54:34 +00:00
										 |  |  | 	else if(isNaN(v) && f[1].indexOf("0") > -1) return "#NUM!"; | 
					
						
							| 
									
										
										
										
											2024-04-27 23:49:12 +00:00
										 |  |  | 	else if(!isFinite(v) && f[1].indexOf("0") > -1) return "#DIV/0!"; | 
					
						
							| 
									
										
										
										
											2013-12-27 03:15:16 +00:00
										 |  |  | 	return eval_fmt(f[1], v, o, f[0]); | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_load(fmt/*:string*/, idx/*:?number*/)/*:number*/ { | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	if(typeof idx != 'number') { | 
					
						
							|  |  |  | 		idx = +idx || -1; | 
					
						
							|  |  |  | /*::if(typeof idx != 'number') return 0x188; */ | 
					
						
							|  |  |  | 		for(var i = 0; i < 0x0188; ++i) { | 
					
						
							|  |  |  | /*::if(typeof idx != 'number') return 0x188; */ | 
					
						
							|  |  |  | 			if(table_fmt[i] == undefined) { if(idx < 0) idx = i; continue; } | 
					
						
							|  |  |  | 			if(table_fmt[i] == fmt) { idx = i; break; } | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | /*::if(typeof idx != 'number') return 0x188; */ | 
					
						
							|  |  |  | 		if(idx < 0) idx = 0x187; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | /*::if(typeof idx != 'number') return 0x188; */ | 
					
						
							|  |  |  | 	table_fmt[idx] = fmt; | 
					
						
							|  |  |  | 	return idx; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | function SSF_load_table(tbl/*:SSFTable*/)/*:void*/ { | 
					
						
							| 
									
										
										
										
											2017-07-28 23:27:16 +00:00
										 |  |  | 	for(var i=0; i!=0x0188; ++i) | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 		if(tbl[i] !== undefined) SSF_load(tbl[i], i); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function make_ssf() { | 
					
						
							|  |  |  | 	table_fmt = SSF_init_table(); | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-20 01:54:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | var SSF = { | 
					
						
							|  |  |  | 	format: SSF_format, | 
					
						
							|  |  |  | 	load: SSF_load, | 
					
						
							|  |  |  | 	_table: table_fmt, | 
					
						
							|  |  |  | 	load_table: SSF_load_table, | 
					
						
							|  |  |  | 	parse_date_code: SSF_parse_date_code, | 
					
						
							|  |  |  | 	is_date: fmt_is_date, | 
					
						
							|  |  |  | 	get_table: function get_table() { return SSF._table = table_fmt; } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 |