forked from sheetjs/sheetjs
SheetJS
f335d310ac
- dateNF option for default date format override - general format renders undefined/null as empty string - ignore text elements when searching for decimal point - bubble negative sign to the front when format starts with text - fixes for eslint + closure - updated frac to 1.0.6 Issues: - fixes #10 h/t @adamgundy @SegFaultx64 @RichardCzechowski - fixes #15 h/t @wilg - fixes #25 h/t @dougschiller - fixes #26 h/t @rjmcguire
43 lines
1.6 KiB
JavaScript
43 lines
1.6 KiB
JavaScript
var abstime = /\[[HhMmSs]*\]/;
|
|
function fmt_is_date(fmt/*:string*/)/*:boolean*/ {
|
|
var i = 0, cc = 0, c = "", o = "";
|
|
while(i < fmt.length) {
|
|
switch((c = fmt.charAt(i))) {
|
|
case 'G': if(isgeneral(fmt, i)) i+= 6; i++; break;
|
|
case '"': for(;(cc=fmt.charCodeAt(++i)) !== 34 && i < fmt.length;) ++i; ++i; break;
|
|
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;
|
|
case 'A':
|
|
if(fmt.substr(i, 3) === "A/P") return true;
|
|
if(fmt.substr(i, 5) === "AM/PM") return true;
|
|
++i; break;
|
|
case '[':
|
|
o = c;
|
|
while(fmt.charAt(i++) !== ']' && i < fmt.length) o += fmt.charAt(i);
|
|
if(o.match(abstime)) return true;
|
|
break;
|
|
case '.':
|
|
/* falls through */
|
|
case '0': case '#':
|
|
while(i < fmt.length && ("0#?.,E+-%".indexOf(c=fmt.charAt(++i)) > -1 || c=='\\' && fmt.charAt(i+1) == "-" && "0#".indexOf(fmt.charAt(i+2))>-1)){}
|
|
break;
|
|
case '?': while(fmt.charAt(++i) === c){} break;
|
|
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':
|
|
while(i < fmt.length && "0123456789".indexOf(fmt.charAt(++i)) > -1){} break;
|
|
case ' ': ++i; break;
|
|
default: ++i; break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
SSF.is_date = fmt_is_date;
|