text: var arrays=require("./codearrays"),usCodes=arrays.usCodes,countryCodes=arrays.countryCodes,canadaCodes=arrays.canadaCodes;function getLocalInfo(t,e,n){if(t){var o=new Object,t=standardizeCountry(t=cleanText(t.toString()));if(o.text=t,setOptions(o,e),checkUS(o),addType(o),addLocation(o),addTime(o),"function"!=typeof n)return o;n(o)}}function standardizeCountry(t){return"00"===t.substring(0,2)&&(t=t.replace("00","+")),t}function setOptions(t,e){t.options={},t.options.military=!0,t.options.zone_display="offset";var n=e;(n=validateOptions(e))&&(0!=n.military&&"false"!=n.military||(t.options.military=!1),"name"===n.zone_display&&(t.options.zone_display="name"))}function validateOptions(t){if("object"!=typeof t||t.length<1)return!1;var e=Object.keys(t),n=["military","format","zone_display"];for(i=0;i<e.length;i++){var o=!1;for(x=0;x<n.length;x++)if(e[i]==n[x]){o=!0;break}o||delete t[e[i]]}return t}function checkUS(t){var e=t.text,n=e.substring(0,2);"+1"!==e&&("+1"===n&&(e=e.replace("+1","")),"1"==e.substring(0,1)&&(e=e.substring(1,e.length)),e.length<3&&(t.valid=!1)),t.text=e}function addType(t){var e=t.text,n=e.substring(0,1),o=e.substring(0,2),i="";t.time={},i="+"===n||"00"===o?(t.text=e.substring(0,5),t.time.zone=!1,"country"):(e.length<3&&(t.valid=!1),t.text=e.substring(0,3),t.time.zone=!1,"area"),t.type=i}function addLocation(t){var e=t.type,n=t.text,o=!1;switch(e){case"area":for(o=getLoc(t);!o&&3<n.length;)n=n.substring(0,n.length-1),t.text=n,o=getLoc(t);o&&chooseUsCanada(t);break;case"country":for(t.country_info=getCountryInfo(t),o=t.country_info.name;!o&&2<n.length;)n=n.substring(0,n.length-1),t.text=n,t.country_info=getCountryInfo(t),o=t.country_info.name}o||(t.valid=!1),t.location=o}function getLoc(t){var e=t.text,n=!1,o=t.options.zone_display;for(i=0;i<usCodes.length-1;i++)for(x=0;x<usCodes[i].codes.length;x++)if(e===usCodes[i].codes[x]){n=usCodes[i].codes[x+1];t.time.zone=usCodes[i][o],t.offset=usCodes[i].offset,t.dst=usCodes[i].dst;break}if(n)return n;var r=usCodes[usCodes.length-1];for(i=0;i<r.codes.length;i++)if(e===r.codes[i]){n="Toll Free or Other";t.time.zone="Toll Free or Other",t.offset=r.offset,t.dst=r.dst;break}return n}function chooseUsCanada(t){var e=t.text,n=getCountryInfo({text:"+1"}).index;for(t.country_info=countryCodes[n+1],i=0;i<canadaCodes.length;i++)if(e===canadaCodes[i]){t.country_info=countryCodes[n+2];break}}function getCountryInfo(t){var e=t.text,n=e.substring(1,e.length),o=[],r=!1;for(i=0;i<countryCodes.length;i++)if(n===countryCodes[i].code){o=countryCodes[i];t.offset=countryCodes[i].offset,t.dst=countryCodes[i].dst,r=i;break}return o.index=r,o}function addTime(t){var e,n,o,i,r,a,s,d,f,u,c,l,m,y,g;0!=t.valid?(t.dstnow=!1,e=t.type,n=t.time.zone,o=t.offset,i=t.location,r=t.dst,a=t.options.zone_display,"Toll Free or Other"!==n&&i?(d=(s=new Date).getHours(),f=s.getMinutes(),u=d+s.getTimezoneOffset()/60,c=!1,l=t.options.military,m=0,r&&checkDst(t)&&(m+=1),1<o.length?(d=u+o[1]+m,c=u+o[0]+m,g=formatTime(d,f,o[1],l),y=formatTime(c,f,o[0],l),t.time.hour2=y.hour,t.time.meridian2=y.meridian,meridian2=t.time.meridian2?" "+y.meridian:"",t.time.display2=y.hour.toString()+":"+g.mins.toString()+meridian2,"offset"!=a&&"country"!=e||(t.time.zone=formatOffsetZoneDisplay(o[1]+m,t),t.time.zone2=formatOffsetZoneDisplay(o[0]+m,t))):(g=formatTime(d=u+o+m,f,o,l),"offset"!=a&&"country"!=e||(t.time.zone=formatOffsetZoneDisplay(o+m,t))),t.time.hour=g.hour,t.time.mins=g.mins,t.time.meridian=g.meridian,meridian=t.time.meridian?" "+g.meridian:"",t.time.display=g.hour.toString()+":"+g.mins.toString()+meridian):t.time=!1):t.time=!1}function checkDst(t){var e,n=new Date,o=n.getFullYear(),i=!1,r=t.country_info,a=r.start_month,s=r.start_week,d=r.start_offset,f=r.start_day,u=r.end_month,c=r.end_week,l=r.end_day,m=nthWeekdayOfMonth(f,s,new Date(o,a)),y=nthWeekdayOfMonth(l,c,new Date(o,u)),g=new Date(o,5);return d&&(31<(e=(e=m.getDate())+d)&&(e-=31,a+=1),m=new Date(o,a,e)),m<g?m<=n&&n<y&&(i=!0):(n<m||y<=n)&&(i=!0),t.dstnow=i}function nthWeekdayOfMonth(t,e,n){for(var o=0,i=new Date(n.getFullYear(),n.getMonth(),1);i.getDay()!==t||++o!=e;)i.setDate(i.getDate()+1);return i}function formatOffsetZoneDisplay(t,e){return 0<(t=t.toString())&&(t="+"+t),0==t&&(t=""),"GMT"+t}function formatTime(t,e,n,o){var i=!1,r=n%1;return(r<0||-0===r)&&(r*=-1),0<r&&(offsetMinutes=60*r,e+=offsetMinutes,t-=r),e<0&&(e=60+e,--t),60<e&&(e-=60,t+=1),1==(e=e.toString()).length&&(e="0"+e),0==e&&(e="00"),60==e&&(e="00",t+=1),24<=t&&(t-=24),t<0&&(t+=24),t<10&&o&&(t="0"+t.toString()),o||(i=11<t?"PM":"AM",0!=t&&23!=t||(t="12"),12<t&&t<24&&(t-=12),t<0&&(t+=12)),{hour:t.toString(),mins:e.toString(),meridian:i}}function cleanText(t){var e=t;return 5<(e=(e=e.replace(/\s/g,"")).replace(/[^+0-9]/g,"")).length&&(e=e.substring(0,5)),e}module.exports=getLocalInfo;