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

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

The newest version!
define(["./is-leap-year","./last-day-of-month","./pattern-re","./start-of","../common/create-error/unsupported-feature","../util/date/set-month","../util/out-of-range"],function(dateIsLeapYear,dateLastDayOfMonth,datePatternRe,dateStartOf,createErrorUnsupportedFeature,dateSetMonth,outOfRange){return function(value,tokens,properties){var amPm,day,daysOfYear,month,era,hour,hour12,timezoneOffset,valid,YEAR=0,MONTH=1,DAY=2,HOUR=3,MINUTE=4,SECOND=5,MILLISECONDS=6,date=new Date,truncateAt=[],units=["year","month","day","hour","minute","second","milliseconds"];if(!tokens.length){return null}valid=tokens.every(function(token){var century,chr,value,length;if(token.type==="literal"){return true}chr=token.type.charAt(0);length=token.type.length;if(chr==="j"){chr=properties.preferredTimeData}switch(chr){case"G":truncateAt.push(YEAR);era=+token.value;break;case"y":value=token.value;if(length===2){if(outOfRange(value,0,99)){return false}century=Math.floor(date.getFullYear()/100)*100;value+=century;if(value>date.getFullYear()+20){value-=100}}date.setFullYear(value);truncateAt.push(YEAR);break;case"Y":throw createErrorUnsupportedFeature({feature:"year pattern `"+chr+"`"});case"Q":case"q":break;case"M":case"L":if(length<=2){value=token.value}else{value=+token.value}if(outOfRange(value,1,12)){return false}month=value;truncateAt.push(MONTH);break;case"w":case"W":break;case"d":day=token.value;truncateAt.push(DAY);break;case"D":daysOfYear=token.value;truncateAt.push(DAY);break;case"F":break;case"e":case"c":case"E":break;case"a":amPm=token.value;break;case"h":value=token.value;if(outOfRange(value,1,12)){return false}hour=hour12=true;date.setHours(value===12?0:value);truncateAt.push(HOUR);break;case"K":value=token.value;if(outOfRange(value,0,11)){return false}hour=hour12=true;date.setHours(value);truncateAt.push(HOUR);break;case"k":value=token.value;if(outOfRange(value,1,24)){return false}hour=true;date.setHours(value===24?0:value);truncateAt.push(HOUR);break;case"H":value=token.value;if(outOfRange(value,0,23)){return false}hour=true;date.setHours(value);truncateAt.push(HOUR);break;case"m":value=token.value;if(outOfRange(value,0,59)){return false}date.setMinutes(value);truncateAt.push(MINUTE);break;case"s":value=token.value;if(outOfRange(value,0,59)){return false}date.setSeconds(value);truncateAt.push(SECOND);break;case"A":date.setHours(0);date.setMinutes(0);date.setSeconds(0);case"S":value=Math.round(token.value*Math.pow(10,3-length));date.setMilliseconds(value);truncateAt.push(MILLISECONDS);break;case"Z":case"z":case"O":case"X":case"x":timezoneOffset=token.value;break}return true});if(!valid){return null}if(hour&&!(!amPm^hour12)){return null}if(era===0){date.setFullYear(date.getFullYear()*-1+1)}if(month!==undefined){dateSetMonth(date,month-1)}if(day!==undefined){if(outOfRange(day,1,dateLastDayOfMonth(date))){return null}date.setDate(day)}else if(daysOfYear!==undefined){if(outOfRange(daysOfYear,1,dateIsLeapYear(date.getFullYear())?366:365)){return null}date.setMonth(0);date.setDate(daysOfYear)}if(hour12&&amPm==="pm"){date.setHours(date.getHours()+12)}if(timezoneOffset!==undefined){date.setMinutes(date.getMinutes()+timezoneOffset-date.getTimezoneOffset())}truncateAt=Math.max.apply(null,truncateAt);date=dateStartOf(date,units[truncateAt]);return date}});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy