All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.globalize.src.date.tokenizer.min.js Maven / Gradle / Ivy

There is a newer version: 1.2.2.1-jre17
Show newest version
define(["./pattern-re","../util/regexp/escape","../util/regexp/n","../util/remove-literal-quotes"],function(datePatternRe,regexpEscape,regexpN,removeLiteralQuotes){return function(value,numberParser,properties){var valid,timeSeparator=properties.timeSeparator,tokens=[],widths=["abbreviated","wide","narrow"];valid=properties.pattern.match(datePatternRe).every(function(current){var chr,length,numeric,tokenRe,token={};function hourFormatParse(tokenRe,numberParser){var aux=value.match(tokenRe);numberParser=numberParser||function(value){return+value};if(!aux){return false}if(aux.length<8){token.value=(aux[1]?-numberParser(aux[1]):numberParser(aux[4]))*60}else{token.value=(aux[1]?-numberParser(aux[1]):numberParser(aux[7]))*60+(aux[1]?-numberParser(aux[4]):numberParser(aux[10]))}return true}function hourFormatRe(hourFormat,gmtFormat,timeSeparator){var re;if(!gmtFormat){gmtFormat="{0}"}re=hourFormat.replace("+","\\+").replace(/HH|mm/g,"(("+regexpN.source+")("+regexpN.source+"))").replace(/H|m/g,"(("+regexpN.source+")("+regexpN.source+")?)");if(timeSeparator){re=re.replace(/:/g,timeSeparator)}re=re.split(";").map(function(part){return gmtFormat.replace("{0}",part)}).join("|");return new RegExp(re)}function oneDigitIfLengthOne(){if(length===1){numeric=true;return tokenRe=regexpN}}function oneOrTwoDigitsIfLengthOne(){if(length===1){numeric=true;return tokenRe=new RegExp("("+regexpN.source+"){1,2}")}}function oneOrTwoDigitsIfLengthOneOrTwo(){if(length===1||length===2){numeric=true;return tokenRe=new RegExp("("+regexpN.source+"){1,2}")}}function twoDigitsIfLengthTwo(){if(length===2){numeric=true;return tokenRe=new RegExp("("+regexpN.source+"){2}")}}function lookup(path){var i,re,data=properties[path.join("/")];for(i in data){re=new RegExp("^"+data[i]);if(re.test(value)){token.value=i;return tokenRe=new RegExp(data[i])}}return null}token.type=current;chr=current.charAt(0),length=current.length;if(chr==="Z"){if(length<4){chr="x";length=4}else if(length<5){chr="O";length=4}else{chr="X";length=5}}switch(chr){case"G":lookup(["gregorian/eras",length<=3?"eraAbbr":length===4?"eraNames":"eraNarrow"]);break;case"y":case"Y":numeric=true;if(length===1){tokenRe=new RegExp("("+regexpN.source+")+")}else if(length===2){tokenRe=new RegExp("("+regexpN.source+"){1,2}")}else{tokenRe=new RegExp("("+regexpN.source+"){"+length+",}")}break;case"Q":case"q":oneDigitIfLengthOne()||twoDigitsIfLengthTwo()||lookup(["gregorian/quarters",chr==="Q"?"format":"stand-alone",widths[length-3]]);break;case"M":case"L":oneOrTwoDigitsIfLengthOneOrTwo()||lookup(["gregorian/months",chr==="M"?"format":"stand-alone",widths[length-3]]);break;case"D":if(length<=3){numeric=true;tokenRe=new RegExp("("+regexpN.source+"){"+length+",3}")}break;case"W":case"F":oneDigitIfLengthOne();break;case"e":case"c":if(length<=2){oneDigitIfLengthOne()||twoDigitsIfLengthTwo();break}case"E":if(length===6){lookup(["gregorian/days",[chr==="c"?"stand-alone":"format"],"short"])||lookup(["gregorian/days",[chr==="c"?"stand-alone":"format"],"abbreviated"])}else{lookup(["gregorian/days",[chr==="c"?"stand-alone":"format"],widths[length<3?0:length-3]])}break;case"a":lookup(["gregorian/dayPeriods/format/wide"]);break;case"w":oneOrTwoDigitsIfLengthOne()||twoDigitsIfLengthTwo();break;case"d":case"h":case"H":case"K":case"k":case"j":case"m":case"s":oneOrTwoDigitsIfLengthOneOrTwo();break;case"S":numeric=true;tokenRe=new RegExp("("+regexpN.source+"){"+length+"}");break;case"A":numeric=true;tokenRe=new RegExp("("+regexpN.source+"){"+(length+5)+"}");break;case"z":case"O":if(value===properties["timeZoneNames/gmtZeroFormat"]){token.value=0;tokenRe=new RegExp(properties["timeZoneNames/gmtZeroFormat"])}else{tokenRe=hourFormatRe(length<4?"+H;-H":properties["timeZoneNames/hourFormat"],properties["timeZoneNames/gmtFormat"],timeSeparator);if(!hourFormatParse(tokenRe,numberParser)){return null}}break;case"X":if(value==="Z"){token.value=0;tokenRe=/Z/;break}case"x":tokenRe=hourFormatRe(length===1?"+HH;-HH":length%2?"+HH:mm;-HH:mm":"+HHmm;-HHmm");if(!hourFormatParse(tokenRe)){return null}break;case"'":token.type="literal";tokenRe=new RegExp(regexpEscape(removeLiteralQuotes(current)));break;default:token.type="literal";tokenRe=new RegExp(regexpEscape(current))}if(!tokenRe){return false}value=value.replace(new RegExp("^"+tokenRe.source),function(lexeme){token.lexeme=lexeme;if(numeric){token.value=numberParser(lexeme)}return""});if(!token.lexeme){return false}tokens.push(token);return true});if(value!==""){valid=false}return valid?tokens:[]}});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy