define(["globalize"],function(globalize){"use strict";functionparseISO8601Date(s,toLocal){varre=/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|([+-])(\d{2}):(\d{2}))?/,d=s.match(re);if(!d)throw"Couldn't parse ISO 8601 date string '"+s+"'";vara=[1,2,3,4,5,6,10,11];for(variina)d[a[i]]=parseInt(d[a[i]],10);d[7]=parseFloat(d[7]);varms=Date.UTC(d[1],d[2]-1,d[3],d[4],d[5],d[6]);if(d[7]>0&&(ms+=Math.round(1e3*d[7])),"Z"!==d[8]&&d[10]){varoffset=60*d[10]*60*1e3;d[11]&&(offset+=60*d[11]*1e3),"-"===d[9]?ms-=offset:ms+=offset}elsetoLocal===!1&&(ms+=6e4*(newDate).getTimezoneOffset());returnnewDate(ms)}functiongetDisplayRunningTime(ticks){varticksPerHour=36e9,ticksPerMinute=6e8,ticksPerSecond=1e7,parts=[],hours=ticks/ticksPerHour;hours=Math.floor(hours),hours&&parts.push(hours),ticks-=hours*ticksPerHour;varminutes=ticks/ticksPerMinute;minutes=Math.floor(minutes),ticks-=minutes*ticksPerMinute,minutes<10&&hours&&(minutes="0"+minutes),parts.push(minutes);varseconds=ticks/ticksPerSecond;returnseconds=Math.floor(seconds),seconds<10&&(seconds="0"+seconds),parts.push(seconds),parts.join(":")}functiongetCurrentLocale(){varlocale=globalize.getCurrentLocale();returnlocale}functiongetOptionList(options){varlist=[];for(variinoptions)list.push({name:i,value:options[i]});returnlist}functiontoLocaleString(date,options){if(!date)thrownewError("date cannot be null");if(options=options||{},toLocaleTimeStringSupportsLocales){varcurrentLocale=getCurrentLocale();if(currentLocale)returndate.toLocaleString(currentLocale,options)}returndate.toLocaleString()}functiontoLocaleDateString(date,options){if(!date)thrownewError("date cannot be null");if(options=options||{},toLocaleTimeStringSupportsLocales){varcurrentLocale=getCurrentLocale();if(currentLocale)returndate.toLocaleDateString(currentLocale,options)}varoptionList=getOptionList(options);if(1===optionList.length&&"weekday"===optionList[0].name){varweekday=[];returnweekday[0]="Sun",weekday[1]="Mon",weekday[2]="Tue",weekday[3]="Wed",weekday[4]="Thu",weekday[5]="Fri",weekday[6]="Sat",weekday[date.getDay()]}returndate.toLocaleDateString()}functiontoLocaleTimeString(date,options){if(!date)thrownewError("date cannot be null");if(options=options||{},toLocaleTimeStringSupportsLocales){varcurrentLocale=getCurrentLocale();if(currentLocale)returndate.toLocaleTimeString(currentLocale,options)}returndate.toLocaleTimeString()}functiongetDisplayTime(date){if(!date)thrownewError("date cannot be null");if("string"===(typeofdate).toString().toLowerCase())try{date=parseISO8601Date(date,!0)}catch(err){returndate}if(toLocaleTimeStringSupportsLocales)returntoLocaleTimeString(date,{hour:"numeric",minute:"2-digit"});vartime=toLocaleTimeString(date),timeLower=time.toLowerCase();if(timeLower.indexOf("am")!==-1||timeLower.indexOf("pm")!==-1){time=timeLower;varhour=date.getHours()%12,suffix=date.getHours()>11?"pm":"am";hour||(hour=12);varminutes=date.getMinutes();minutes<10&&(minutes="0"+minutes),minutes=":"+minutes,time=hour+minutes+suffix}else{vartimeParts=time.split(":");timeParts.length>2&&(timeParts.length-=1,time=timeParts.join(":"))}returntime}functionisRelativeDay(date,offsetInDays){if(!date)thrownewError("date cannot be null");varyesterday=newDate,day=yesterday.getDate()+offsetInDays;returnyesterday.setDate(day),date.getFullYear()===yesterday.getFullYear()&&date.getMonth()===yesterday.getMonth()&&date.getDate()===day}vartoLocaleTimeStringSupportsLocales=function(){try{(newDate).toLocaleTimeString("i")}catch(e){return"RangeError"===e.name}return!1}();return{parseISO8601Date:parseISO8601Date,getDisplayRunningTime:getDisplayRunningTime,toLocaleDateString:toLocaleDateString,toLocaleString:toLocaleString,getDisplayTime:getDisplayTime,isRelativeDay:isRelativeDay,toLocaleTimeString:toLocaleTimeString}});