walltime-js
Version:
A javascript library for easily translating a UTC time to a "Wall Time" for a particular time zone and back.
6 lines • 22.3 kB
JavaScript
/*
* WallTime 0.2.0
* Copyright (c) 2013 Sprout Social, Inc.
* Available under the MIT License (http://bit.ly/walltime-license)
*/
(function(){var e,t,n,r,i,s;(s=Array.prototype).indexOf||(s.indexOf=function(e){var t,n,r,i;for(t=r=0,i=this.length;r<i;t=++r){n=this[t];if(n===e)return t}return-1}),e={DayShortNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],DayIndex:function(e){return this.DayShortNames.indexOf(e)},DayNameFromIndex:function(e){return this.DayShortNames[e]},AddToDate:function(e,n){return r.MakeDateFromTimeStamp(e.getTime()+n*t.inDay)}},n={MonthsShortNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],CompareRuleMatch:new RegExp("([a-zA-Z]*)([\\<\\>]?=)([0-9]*)"),MonthIndex:function(e){return this.MonthsShortNames.indexOf(e.slice(0,3))},IsDayOfMonthRule:function(e){return e.indexOf(">")>-1||e.indexOf("<")>-1||e.indexOf("=")>-1},IsLastDayOfMonthRule:function(e){return e.slice(0,4)==="last"},DayOfMonthByRule:function(e,t,n){var r,s,o,u,a,f,l,c,h;f=this.CompareRuleMatch.exec(e);if(!f)throw new Error("Unable to parse the 'on' rule for "+e);h=f.slice(1,4),a=h[0],c=h[1],o=h[2],o=parseInt(o,10);if(o===NaN)throw new Error("Unable to parse the dateIndex of the 'on' rule for "+e);u=i.Days.DayIndex(a),s={">=":function(e,t){return e>=t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},"<":function(e,t){return e<t},"=":function(e,t){return e===t}},r=s[c];if(!r)throw new Error("Unable to parse the conditional for "+c);l=i.Time.MakeDateFromParts(t,n);while(u!==l.getUTCDay()||!r(l.getUTCDate(),o))l=i.Days.AddToDate(l,1);return l.getUTCDate()},LastDayOfMonthRule:function(e,t,n){var r,s,o;s=e.slice(4),r=i.Days.DayIndex(s),n<11?o=i.Time.MakeDateFromParts(t,n+1):o=i.Time.MakeDateFromParts(t+1,0),o=i.Days.AddToDate(o,-1);while(o.getUTCDay()!==r)o=i.Days.AddToDate(o,-1);return o.getUTCDate()}},t={inDay:864e5,inHour:36e5,inMinute:6e4,inSecond:1e3},r={Add:function(e,n,r,i){var s;return n==null&&(n=0),r==null&&(r=0),i==null&&(i=0),s=e.getTime()+n*t.inHour+r*t.inMinute+i*t.inSecond,this.MakeDateFromTimeStamp(s)},ParseGMTOffset:function(e){var t,n,r,i,s;return i=new RegExp("(-)?([0-9]*):([0-9]*):?([0-9]*)?"),r=i.exec(e),s=r?function(){var e,t,i,s;i=r.slice(2),s=[];for(e=0,t=i.length;e<t;e++)n=i[e],s.push(parseInt(n,10));return s}():[0,0,0],t=r&&r[1]==="-",s.splice(0,0,t),s},ParseTime:function(e){var t,n,r,i,s;return i=new RegExp("(\\d*)\\:(\\d*)([wsugz]?)"),n=i.exec(e),n?(s=function(){var e,r,i,s;i=n.slice(1,3),s=[];for(e=0,r=i.length;e<r;e++)t=i[e],s.push(parseInt(t,10));return s}(),r=n[3]?n[3]:"",s.push(r),s):[0,0,""]},ApplyOffset:function(e,n,r){var i;return i=t.inHour*n.hours+t.inMinute*n.mins+t.inSecond*n.secs,n.negative||(i*=-1),r&&(i*=-1),this.MakeDateFromTimeStamp(e.getTime()+i)},ApplySave:function(e,t,n){return n!==!0&&(n=!1),this.ApplyOffset(e,{negative:!0,hours:t.hours,mins:t.mins,secs:0},n)},UTCToWallTime:function(e,t,n){var r;return r=this.UTCToStandardTime(e,t),this.ApplySave(r,n)},UTCToStandardTime:function(e,t){return this.ApplyOffset(e,t,!0)},UTCToQualifiedTime:function(e,t,n,r){var i;i=e;switch(t){case"w":i=this.UTCToWallTime(i,n,r());break;case"s":i=this.UTCToStandardTime(i,n)}return i},QualifiedTimeToUTC:function(e,t,n,r){var i;i=e;switch(t){case"w":i=this.WallTimeToUTC(n,r(),i);break;case"s":i=this.StandardTimeToUTC(n,i)}return i},StandardTimeToUTC:function(e,t,n,r,i,s,o,u){var a;return n==null&&(n=0),r==null&&(r=1),i==null&&(i=0),s==null&&(s=0),o==null&&(o=0),u==null&&(u=0),a=typeof t=="number"?this.MakeDateFromParts(t,n,r,i,s,o,u):t,this.ApplyOffset(a,e)},WallTimeToUTC:function(e,t,n,r,i,s,o,u,a){var f;return r==null&&(r=0),i==null&&(i=1),s==null&&(s=0),o==null&&(o=0),u==null&&(u=0),a==null&&(a=0),f=this.StandardTimeToUTC(e,n,r,i,s,o,u,a),this.ApplySave(f,t,!0)},MakeDateFromParts:function(e,t,n,r,i,s,o){var u;return t==null&&(t=0),n==null&&(n=1),r==null&&(r=0),i==null&&(i=0),s==null&&(s=0),o==null&&(o=0),Date.UTC?new Date(Date.UTC(e,t,n,r,i,s,o)):(u=new Date,u.setUTCFullYear(e),u.setUTCMonth(t),u.setUTCDate(n),u.setUTCHours(r),u.setUTCMinutes(i),u.setUTCSeconds(s),u.setUTCMilliseconds(o),u)},LocalDate:function(e,t,n,r,i,s,o,u,a){return r==null&&(r=0),i==null&&(i=1),s==null&&(s=0),o==null&&(o=0),u==null&&(u=0),a==null&&(a=0),this.WallTimeToUTC(e,t,n,r,i,s,o,u,a)},MakeDateFromTimeStamp:function(e){return new Date(e)},MaxDate:function(){return this.MakeDateFromTimeStamp(864e12)},MinDate:function(){return this.MakeDateFromTimeStamp(-864e12)}},i={Days:e,Months:n,Milliseconds:t,Time:r,noSave:{hours:0,mins:0},noZone:{offset:{negative:!1,hours:0,mins:0,secs:0},name:"UTC"}},typeof window=="undefined"?module.exports=i:typeof define!="undefined"?define("olson/helpers",i):(this.WallTime||(this.WallTime={}),this.WallTime.helpers=i)}).call(this),function(){var e,t;e=function(e){var t;return t=function(){function t(t,n,r){this.utc=t,this.zone=n,this.save=r,this.offset=this.zone.offset,this.wallTime=e.Time.UTCToWallTime(this.utc,this.offset,this.save)}return t.prototype.getFullYear=function(){return this.wallTime.getUTCFullYear()},t.prototype.getMonth=function(){return this.wallTime.getUTCMonth()},t.prototype.getDate=function(){return this.wallTime.getUTCDate()},t.prototype.getDay=function(){return this.wallTime.getUTCDay()},t.prototype.getHours=function(){return this.wallTime.getUTCHours()},t.prototype.getMinutes=function(){return this.wallTime.getUTCMinutes()},t.prototype.getSeconds=function(){return this.wallTime.getUTCSeconds()},t.prototype.getMilliseconds=function(){return this.wallTime.getUTCMilliseconds()},t.prototype.getUTCFullYear=function(){return this.utc.getUTCFullYear()},t.prototype.getUTCMonth=function(){return this.utc.getUTCMonth()},t.prototype.getUTCDate=function(){return this.utc.getUTCDate()},t.prototype.getUTCDay=function(){return this.utc.getUTCDay()},t.prototype.getUTCHours=function(){return this.utc.getUTCHours()},t.prototype.getUTCMinutes=function(){return this.utc.getUTCMinutes()},t.prototype.getUTCSeconds=function(){return this.utc.getUTCSeconds()},t.prototype.getUTCMilliseconds=function(){return this.utc.getUTCMilliseconds()},t.prototype.getTime=function(){return this.utc.getTime()},t.prototype.getTimezoneOffset=function(){var e,t;return e=this.offset.hours*60+this.offset.mins,t=this.save.hours*60+this.save.mins,this.offset.negative||(e=-e),e-t},t.prototype.toISOString=function(){return this.utc.toISOString()},t.prototype.toUTCString=function(){return this.wallTime.toUTCString()},t.prototype.toDateString=function(){var e,t;return t=this.wallTime.toUTCString(),e=t.match("([a-zA-Z]*), ([0-9]+) ([a-zA-Z]*) ([0-9]+)"),[e[1],e[3],e[2],e[4]].join(" ")},t.prototype.toFormattedTime=function(e){var t,n,r,i;return e==null&&(e=!1),t=i=this.getHours(),t>12&&!e&&(t-=12),t===0&&(t=12),r=this.getMinutes(),r<10&&(r="0"+r),n=i>11?" PM":" AM",e&&(n=""),""+t+":"+r+n},t.prototype.setTime=function(t){return this.wallTime=e.Time.UTCToWallTime(new Date(t),this.zone.offset,this.save),this._updateUTC()},t.prototype.setFullYear=function(e){return this.wallTime.setUTCFullYear(e),this._updateUTC()},t.prototype.setMonth=function(e){return this.wallTime.setUTCMonth(e),this._updateUTC()},t.prototype.setDate=function(e){return this.wallTime.setUTCDate(e),this._updateUTC()},t.prototype.setHours=function(e){return this.wallTime.setUTCHours(e),this._updateUTC()},t.prototype.setMinutes=function(e){return this.wallTime.setUTCMinutes(e),this._updateUTC()},t.prototype.setSeconds=function(e){return this.wallTime.setUTCSeconds(e),this._updateUTC()},t.prototype.setMilliseconds=function(e){return this.wallTime.setUTCMilliseconds(e),this._updateUTC()},t.prototype._updateUTC=function(){return this.utc=e.Time.WallTimeToUTC(this.offset,this.save,this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds(),this.getMilliseconds()),this.utc.getTime()},t}(),t},typeof window=="undefined"?(t=require("./helpers"),module.exports=e(t)):typeof define!="undefined"?define("olson/timezonetime",["olson/helpers"],e):(this.WallTime||(this.WallTime={}),this.WallTime.TimeZoneTime=e(this.WallTime.helpers))}.call(this),function(){var e,t,n,r={}.hasOwnProperty;e=function(e,t){var n,i,s,o,u,a;return s=function(){function e(){}return e.prototype.applies=function(e){return!isNaN(parseInt(e,10))},e.prototype.parseDate=function(e){return parseInt(e,10)},e}(),i=function(){function t(){}return t.prototype.applies=e.Months.IsLastDayOfMonthRule,t.prototype.parseDate=function(t,n,r,i,s,o){return e.Months.LastDayOfMonthRule(t,n,r)},t}(),n=function(){function t(){}return t.prototype.applies=e.Months.IsDayOfMonthRule,t.prototype.parseDate=function(t,n,r){return e.Months.DayOfMonthByRule(t,n,r)},t}(),o=function(){function t(t,n,r,i,s,o,u,a,f){var l,c,h,p;this.name=t,this._from=n,this._to=r,this.type=i,this["in"]=s,this.on=o,this.at=u,this._save=a,this.letter=f,this.from=parseInt(this._from,10),this.isMax=!1,h=this.from;switch(this._to){case"max":h=e.Time.MaxDate().getUTCFullYear(),this.isMax=!0;break;case"only":h=this.from;break;default:h=parseInt(this._to,10)}this.to=h,p=this._parseTime(this._save),l=p[0],c=p[1],this.save={hours:l,mins:c}}return t.prototype.forZone=function(t){return this.offset=t,this.fromUTC=e.Time.MakeDateFromParts(this.from,0,1,0,0,0),this.fromUTC=e.Time.ApplyOffset(this.fromUTC,t),this.toUTC=e.Time.MakeDateFromParts(this.to,11,31,23,59,59,999),this.toUTC=e.Time.ApplyOffset(this.toUTC,t)},t.prototype.setOnUTC=function(t,n,r){var i,s,o,u,a,f,l,c=this;return f=e.Months.MonthIndex(this["in"]),s=parseInt(this.on,10),o=isNaN(s)?this._parseOnDay(this.on,t,f):s,l=this._parseTime(this.at),u=l[0],a=l[1],i=l[2],this.onUTC=e.Time.MakeDateFromParts(t,f,o,u,a),this.onUTC.setUTCMilliseconds(this.onUTC.getUTCMilliseconds()-1),this.atQualifier=i!==""?i:"w",this.onUTC=e.Time.QualifiedTimeToUTC(this.onUTC,this.atQualifier,n,function(){return r(c)}),this.onSort=""+f+"-"+o+"-"+this.onUTC.getUTCHours()+"-"+this.onUTC.getUTCMinutes()},t.prototype.appliesToUTC=function(e){return this.fromUTC<=e&&e<=this.toUTC},t.prototype._parseOnDay=function(e,t,r){var o,u,a,f;u=[new s,new i,new n];for(a=0,f=u.length;a<f;a++){o=u[a];if(!o.applies(e))continue;return o.parseDate(e,t,r)}throw new Error("Unable to parse 'on' field for "+this.name+"|"+this._from+"|"+this._to+"|"+e)},t.prototype._parseTime=function(t){return e.Time.ParseTime(t)},t}(),u=function(){function n(t,n){var i,s,o,u,a,f,l,c,h,p=this;this.rules=t!=null?t:[],this.timeZone=n,a=null,u=null,o={},i={},h=this.rules;for(l=0,c=h.length;l<c;l++){f=h[l],f.forZone(this.timeZone.offset,function(){return e.noSave});if(a===null||f.from<a)a=f.from;if(u===null||f.to>u)u=f.to;o[f.to]=o[f.to]||[],o[f.to].push(f),i[f.from]=i[f.from]||[],i[f.from].push(f)}this.minYear=a,this.maxYear=u,s=function(n,i){var s,u,a,l;n==null&&(n="toUTC"),i==null&&(i=o),l=[];for(u in i){if(!r.call(i,u))continue;t=i[u],a=p.allThatAppliesTo(t[0][n]);if(a.length<1)continue;t=p._sortRulesByOnTime(t),s=a.slice(-1)[0];if(s.save.hours===0&&s.save.mins===0)continue;l.push(function(){var r,i,o;o=[];for(r=0,i=t.length;r<i;r++)f=t[r],o.push(f[n]=e.Time.ApplySave(f[n],s.save));return o}())}return l},s("toUTC",o),s("fromUTC",i)}return n.prototype.allThatAppliesTo=function(e){var t,n,r,i,s;i=this.rules,s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t.appliesToUTC(e)&&s.push(t);return s},n.prototype.getWallTimeForUTC=function(n){var r,i,s,o,u,a,f;u=this.allThatAppliesTo(n);if(u.length<1)return new t(n,this.timeZone,e.noSave);u=this._sortRulesByOnTime(u),i=function(t){var n;return n=u.indexOf(t),n<1?u.length<1?e.noSave:u.slice(-1)[0].save:u[n-1].save};for(a=0,f=u.length;a<f;a++)o=u[a],o.setOnUTC(n.getUTCFullYear(),this.timeZone.offset,i);return r=function(){var e,t,r;r=[];for(e=0,t=u.length;e<t;e++)o=u[e],o.onUTC.getTime()<n.getTime()&&r.push(o);return r}(),s=u.length<1?e.noSave:u.slice(-1)[0].save,r.length>0&&(s=r.slice(-1)[0].save),new t(n,this.timeZone,s)},n.prototype.getUTCForWallTime=function(t){var n,r,i,s,o,u,a,f;u=e.Time.StandardTimeToUTC(this.timeZone.offset,t),o=function(){var e,t,n,r;n=this.rules,r=[];for(e=0,t=n.length;e<t;e++)s=n[e],s.appliesToUTC(u)&&r.push(s);return r}.call(this);if(o.length<1)return u;o=this._sortRulesByOnTime(o),r=function(t){var n;return n=o.indexOf(t),n<1?o.length<1?e.noSave:o.slice(-1)[0].save:o[n-1].save};for(a=0,f=o.length;a<f;a++)s=o[a],s.setOnUTC(u.getUTCFullYear(),this.timeZone.offset,r);return n=function(){var e,t,n;n=[];for(e=0,t=o.length;e<t;e++)s=o[e],s.onUTC.getTime()<u.getTime()&&n.push(s);return n}(),i=o.length<1?e.noSave:o.slice(-1)[0].save,n.length>0&&(i=n.slice(-1)[0].save),e.Time.WallTimeToUTC(this.timeZone.offset,i,t)},n.prototype.getYearEndDST=function(t){var n,r,i,s,o,u,a,f,l;a=typeof t===number?t:t.getUTCFullYear(),u=e.Time.StandardTimeToUTC(this.timeZone.offset,a,11,31,23,59,59),o=function(){var e,t,n,r;n=this.rules,r=[];for(e=0,t=n.length;e<t;e++)s=n[e],s.appliesToUTC(u)&&r.push(s);return r}.call(this);if(o.length<1)return e.noSave;o=this._sortRulesByOnTime(o),r=function(t){var n;return n=o.indexOf(t),n<1?e.noSave:o[n-1].save};for(f=0,l=o.length;f<l;f++)s=o[f],s.setOnUTC(u.getUTCFullYear(),this.timeZone.offset,r);return n=function(){var e,t,n;n=[];for(e=0,t=o.length;e<t;e++)s=o[e],s.onUTC.getTime()<u.getTime()&&n.push(s);return n}(),i=e.noSave,n.length>0&&(i=n.slice(-1)[0].save),i},n.prototype.isAmbiguous=function(t){var n,r,i,s,o,u,a,f,l,c,h,p,d,v;p=e.Time.StandardTimeToUTC(this.timeZone.offset,t),l=function(){var e,t,n,r;n=this.rules,r=[];for(e=0,t=n.length;e<t;e++)f=n[e],f.appliesToUTC(p)&&r.push(f);return r}.call(this);if(l.length<1)return!1;l=this._sortRulesByOnTime(l),r=function(t){var n;return n=l.indexOf(t),n<1?e.noSave:l[n-1].save};for(d=0,v=l.length;d<v;d++)f=l[d],f.setOnUTC(p.getUTCFullYear(),this.timeZone.offset,r);return n=function(){var e,t,n;n=[];for(e=0,t=l.length;e<t;e++)f=l[e],f.onUTC.getTime()<=p.getTime()-1&&n.push(f);return n}(),n.length<1?!1:(i=n.slice(-1)[0],u=r(i),h={prev:u.hours*60+u.mins,last:i.save.hours*60+i.save.mins},h.prev===h.last?!1:(c=h.prev<h.last,s=function(t,n){var r,i;return r={begin:e.Time.MakeDateFromTimeStamp(t.getTime()+1)},r.end=e.Time.Add(r.begin,0,n),r.begin.getTime()>r.end.getTime()&&(i=r.begin,r.begin=r.end,r.end=i),r},o=c?h.last:-h.prev,a=s(i.onUTC,o),p=e.Time.WallTimeToUTC(this.timeZone.offset,u,t),a.begin<=p&&p<=a.end))},n.prototype._sortRulesByOnTime=function(t){return t.sort(function(t,n){return e.Months.MonthIndex(t["in"])-e.Months.MonthIndex(n["in"])})},n}(),a={Rule:o,RuleSet:u,OnFieldHandlers:{NumberHandler:s,LastHandler:i,CompareHandler:n}},a},typeof window=="undefined"?(n=require("./helpers"),t=require("./timezonetime"),module.exports=e(n,t)):typeof define!="undefined"?define("olson/rule",["olson/helpers","olson/timezonetime"],e):(this.WallTime||(this.WallTime={}),this.WallTime.rule=e(this.WallTime.helpers,this.WallTime.TimeZoneTime))}.call(this),function(){var e,t,n,r;e=function(e,t,n){var r,i,s;return r=function(){function r(t,n,r,i,s,o){var u,a,f,l,c,h;this.name=t,this._offset=n,this._rule=r,this.format=i,this._until=s,h=e.Time.ParseGMTOffset(this._offset),a=h[0],f=h[1],l=h[2],c=h[3],this.offset={negative:a,hours:f,mins:l,secs:isNaN(c)?0:c},u=o?e.Time.MakeDateFromTimeStamp(o.range.end.getTime()+1):e.Time.MinDate(),this.range={begin:u,end:this._parseUntilDate(this._until)}}return r.prototype._parseUntilDate=function(t){var n,r,i,s,o,u,a,f,l,c,h,p,d;return p=t.split(" "),h=p[0],u=p[1],n=p[2],c=p[3],d=c?e.Time.ParseGMTOffset(c):[!1,0,0,0],a=d[0],i=d[1],s=d[2],f=d[3],f=isNaN(f)?0:f,!h||h===""?e.Time.MaxDate():(h=parseInt(h,10),o=u?e.Months.MonthIndex(u):0,n||(n="1"),e.Months.IsDayOfMonthRule(n)?n=e.Months.DayOfMonthByRule(n,h,o):e.Months.IsLastDayOfMonthRule(n)?n=e.Months.LastDayOfMonthRule(n,h,o):n=parseInt(n,10),l=e.Time.StandardTimeToUTC(this.offset,h,o,n,i,s,f),r=e.Time.MakeDateFromTimeStamp(l.getTime()-1),r)},r.prototype.updateEndForRules=function(n){var r,i,s,o,u;if(this._rule==="-"||this._rule==="")return;return this._rule.indexOf(":")>=0&&(u=e.Time.ParseTime(this._rule),i=u[0],s=u[1],this.range.end=e.Time.ApplySave(this.range.end,{hours:i,mins:s})),o=new t.RuleSet(n(this._rule),this),r=o.getYearEndDST(this.range.end),this.range.end=e.Time.ApplySave(this.range.end,r)},r.prototype.UTCToWallTime=function(r,i){var s,o,u,a;return this._rule==="-"||this._rule===""?new n(r,this,e.noSave):this._rule.indexOf(":")>=0?(a=e.Time.ParseTime(this._rule),s=a[0],o=a[1],new n(r,this,{hours:s,mins:o})):(u=new t.RuleSet(i(this._rule),this),u.getWallTimeForUTC(r))},r.prototype.WallTimeToUTC=function(n,r){var i,s,o,u;return this._rule==="-"||this._rule===""?e.Time.StandardTimeToUTC(this.offset,n):this._rule.indexOf(":")>=0?(u=e.Time.ParseTime(this._rule),i=u[0],s=u[1],e.Time.WallTimeToUTC(this.offset,{hours:i,mins:s},n)):(o=new t.RuleSet(r(this._rule),this),o.getUTCForWallTime(n,this.offset))},r.prototype.IsAmbiguous=function(n,r){var i,s,o,u,a,f,l,c,h;if(this._rule==="-"||this._rule==="")return!1;if(this._rule.indexOf(":")>=0){f=e.Time.StandardTimeToUTC(this.offset,n),l=e.Time.ParseTime(this._rule),s=l[0],u=l[1],o=function(t){var n,r;return n={begin:this.range.begin,end:e.Time.ApplySave(this.range.begin,{hours:s,mins:u})},n.end.getTime()<n.begin.getTime()&&(r=n.begin,n.begin=n.end,n.end=r),n},i=o(this.range.begin);if(i.begin.getTime()<=(c=f.getTime())&&c<i.end.getTime())return!0;i=o(this.range.end),i.begin.getTime()<=(h=f.getTime())&&h<i.end.getTime()}return a=new t.RuleSet(r(this._rule),this),a.isAmbiguous(n,this.offset)},r}(),i=function(){function t(e,t){var n,r,i,s;this.zones=e!=null?e:[],this.getRulesNamed=t,this.zones.length>0?this.name=this.zones[0].name:this.name="",s=this.zones;for(r=0,i=s.length;r<i;r++)n=s[r],n.updateEndForRules}return t.prototype.add=function(e){this.zones.length===0&&this.name===""&&(this.name=e.name);if(this.name!==e.name)throw new Error("Cannot add different named zones to a ZoneSet");return this.zones.push(e)},t.prototype.findApplicable=function(t,n){var r,i,s,o,u,a,f,l;n==null&&(n=!1),o=t.getTime(),r=function(t){return{begin:e.Time.UTCToStandardTime(t.range.begin,t.offset),end:e.Time.UTCToStandardTime(t.range.end,t.offset)}},i=null,l=this.zones;for(a=0,f=l.length;a<f;a++){u=l[a],s=n?r(u):u.range;if(s.begin.getTime()<=o&&o<=s.end.getTime()){i=u;break}}return i},t.prototype.getWallTimeForUTC=function(t){var r;return r=this.findApplicable(t),r?r.UTCToWallTime(t,this.getRulesNamed):new n(t,e.noZone,e.noSave)},t.prototype.getUTCForWallTime=function(e){var t;return t=this.findApplicable(e,!0),t?t.WallTimeToUTC(e,this.getRulesNamed):e},t.prototype.isAmbiguous=function(e){var t;return t=this.findApplicable(e,!0),t?t.IsAmbiguous(e,this.getRulesNamed):!1},t}(),s={Zone:r,ZoneSet:i}},typeof window=="undefined"?(n=require("./helpers"),r=require("./rule"),t=require("./timezonetime"),module.exports=e(n,r,t)):typeof define!="undefined"?define("olson/zone",["olson/helpers","olson/rule","olson/timezonetime"],e):(this.WallTime||(this.WallTime={}),this.WallTime.zone=e(this.WallTime.helpers,this.WallTime.rule,this.WallTime.TimeZoneTime))}.call(this),function(){var e,t,n,r,i,s,o,u,a,f,l={}.hasOwnProperty;t=function(e,t,n){var r;return r=function(){function r(){}return r.prototype.init=function(e,t){return e==null&&(e={}),t==null&&(t={}),this.zones={},this.rules={},this.addRulesZones(e,t),this.zoneSet=null,this.timeZoneName=null,this.doneInit=!0},r.prototype.addRulesZones=function(e,r){var i,s,o,u,a,f,c,h,p,d,v,m,g;e==null&&(e={}),r==null&&(r={}),i=null;for(p in r){if(!l.call(r,p))continue;d=r[p],u=[],i=null;for(v=0,m=d.length;v<m;v++)h=d[v],o=new n.Zone(h.name,h._offset,h._rule,h.format,h._until,i),u.push(o),i=o;this.zones[p]=u}g=[];for(f in e){if(!l.call(e,f))continue;c=e[f],s=function(){var e,n,r;r=[];for(e=0,n=c.length;e<n;e++)a=c[e],r.push(new t.Rule(a.name,a._from,a._to,a.type,a["in"],a.on,a.at,a._save,a.letter));return r}(),g.push(this.rules[f]=s)}return g},r.prototype.setTimeZone=function(e){var t,r=this;if(!this.doneInit)throw new Error("Must call init with rules and zones before setting time zone");if(!this.zones[e])throw new Error("Unable to find time zone named "+(e||"<blank>"));return t=this.zones[e],this.zoneSet=new n.ZoneSet(t,function(e){return r.rules[e]}),this.timeZoneName=e},r.prototype.Date=function(t,n,r,i,s,o,u){return n==null&&(n=0),r==null&&(r=1),i==null&&(i=0),s==null&&(s=0),o==null&&(o=0),u==null&&(u=0),t||(t=(new Date).getUTCFullYear()),e.Time.MakeDateFromParts(t,n,r,i,s,o,u)},r.prototype.UTCToWallTime=function(e,t){t==null&&(t=this.timeZoneName),typeof e=="number"&&(e=new Date(e)),t!==this.timeZoneName&&this.setTimeZone(t);if(!this.zoneSet)throw new Error("Must set the time zone before converting times");return this.zoneSet.getWallTimeForUTC(e)},r.prototype.WallTimeToUTC=function(t,n,r,i,s,o,u,a){var f;return t==null&&(t=this.timeZoneName),r==null&&(r=0),i==null&&(i=1),s==null&&(s=0),o==null&&(o=0),u==null&&(u=0),a==null&&(a=0),t!==this.timeZoneName&&this.setTimeZone(t),f=typeof n=="number"?e.Time.MakeDateFromParts(n,r,i,s,o,u,a):n,this.zoneSet.getUTCForWallTime(f)},r.prototype.IsAmbiguous=function(t,n,r,i,s,o){var u;return t==null&&(t=this.timeZoneName),o==null&&(o=0),t!==this.timeZoneName&&this.setTimeZone(t),u=typeof n=="number"?e.Time.MakeDateFromParts(n,r,i,s,o):n,this.zoneSet.isAmbiguous(u)},r}(),new r};if(typeof window=="undefined")s=require("./olson/zone"),i=require("./olson/rule"),r=require("./olson/helpers"),module.exports=t(r,i,s);else if(typeof define!="undefined")require.specified("walltime-data")||(typeof console!="undefined"&&console!==null&&typeof console.warn=="function"&&console.warn("To use WallTime with requirejs please include the walltime-data.js script before requiring walltime"),define("walltime-data",[],function(){return null})),define("walltime",["olson/helpers","olson/rule","olson/zone","walltime-data"],function(e,n,r,i){var s;return s=t(e,n,r),(i!=null?i.zones:void 0)&&s.init(i.rules,i.zones),s});else{this.WallTime||(this.WallTime={}),e=t(this.WallTime.helpers,this.WallTime.rule,this.WallTime.zone),u=this.WallTime;for(n in u){if(!l.call(u,n))continue;o=u[n],e[n]=o}this.WallTime=e,this.WallTime.autoinit&&((a=this.WallTime.data)!=null?a.rules:void 0)&&((f=this.WallTime.data)!=null?f.zones:void 0)&&this.WallTime.init(this.WallTime.data.rules,this.WallTime.data.zones)}}.call(this);