UNPKG

moment-timezone

Version:

Parse and display moments in any timezone.

1 lines • 8.85 kB
!function(t,e){"use strict";"object"==typeof module&&module.exports?module.exports=e(require("moment")):"function"==typeof define&&define.amd?define(["moment"],e):e(t.moment)}(this,function(m){"use strict";void 0===m.version&&m.default&&(m=m.default);var d,z,s,e,u={},i={},f={},l={},c={},v=!1,g=!1,a=!1,t=(m&&"string"==typeof m.version||Z("Moment Timezone requires Moment.js. See https://momentjs.com/timezone/docs/#/use-it/browser/"),m.version.split(".")),n=+t[0],o=+t[1];function h(t){return 96<t?t-87:64<t?t-29:t-48}function r(t){var e=0,n=t.split("."),o=n[0],r=n[1]||"",i=1,s=0,n=1;for(45===t.charCodeAt(0)&&(n=-(e=1));e<o.length;e++)s=60*s+h(o.charCodeAt(e));for(e=0;e<r.length;e++)i/=60,s+=h(r.charCodeAt(e))*i;return s*n}function p(t){for(var e=0;e<t.length;e++)t[e]=r(t[e])}function b(t,e){for(var n=[],o=0;o<e.length;o++)n[o]=t[e[o]];return n}function _(t){for(var t=t.split("|"),e=t[2].split(" "),n=t[3].split(""),o=t[4].split(" "),r=(p(e),p(n),p(o),o),i=n.length,s=0;s<i;s++)r[s]=Math.round((r[s-1]||0)+6e4*r[s]);return r[i-1]=1/0,{name:t[0],abbrs:b(t[1].split(" "),n),offsets:b(e,n),untils:o,population:0|t[5]}}function w(t){t&&this._set(_(t))}(n<2||2==n&&o<6)&&Z("Moment Timezone requires Moment.js >= 2.6.0. You are using Moment.js "+m.version+". See momentjs.com"),w.prototype={_set:function(t){this.name=t.name,this.abbrs=t.abbrs,this.untils=t.untils,this.offsets=t.offsets,this.population=t.population},_index:function(t){t=function(t,e){var n,o=e.length;if(t<e[0])return 0;if(1<o&&e[o-1]===1/0&&t>=e[o-2])return o-1;if(t>=e[o-1])return-1;for(var r=0,i=o-1;1<i-r;)e[n=Math.floor((r+i)/2)]<=t?r=n:i=n;return i}(+t,this.untils);if(0<=t)return t},countries:function(){var e=this.name;return Object.keys(f).filter(function(t){return-1!==f[t].zones.indexOf(e)})},parse:function(t){for(var e,n,o=+t,r=this.offsets,i=this.untils,s=i.length-1,f=0;f<s;f++)if(((e=r[f])<(n=r[f+1])&&P.moveAmbiguousForward||n<e&&P.moveInvalidForward)&&(e=n),o<i[f]-6e4*e)return r[f];return r[s]},abbr:function(t){return this.abbrs[this._index(t)]},offset:function(t){return Z("zone.offset has been deprecated in favor of zone.utcOffset"),this.offsets[this._index(t)]},utcOffset:function(t){return this.offsets[this._index(t)]}};var O=new w;function k(t,e){this.name=t,this.zones=e}function y(t){var e=t.toTimeString(),n=e.match(/\([a-z ]+\)/i);"GMT"===(n=n&&n[0]?(n=n[0].match(/[A-Z]/g))?n.join(""):void 0:(n=e.match(/[A-Z]{3,5}/g))?n[0]:void 0)&&(n=void 0),this.at=+t,this.abbr=n,this.offset=t.getTimezoneOffset()}function T(t){this.zone=t,this.offsetScore=0,this.abbrScore=0}function E(){for(var t,e,n,o=(new Date).getFullYear()-2,r=new y(new Date(o,0,1)),i=r.offset,s=[r],f=1;f<48;f++)(n=new Date(o,f,1).getTimezoneOffset())!==i&&(t=function(t,e){for(var n;n=6e4*((e.at-t.at)/12e4|0);)(n=new y(new Date(t.at+n))).offset===t.offset?t=n:e=n;return t}(r,e=new y(new Date(o,f,1))),s.push(t),s.push(new y(new Date(t.at+6e4))),r=e,i=n);for(f=0;f<4;f++)s.push(new y(new Date(o+f,0,1))),s.push(new y(new Date(o+f,6,1)));return s}function Y(t,e){return t.offsetScore!==e.offsetScore?t.offsetScore-e.offsetScore:t.abbrScore!==e.abbrScore?t.abbrScore-e.abbrScore:t.zone.population!==e.zone.population?e.zone.population-t.zone.population:e.zone.name.localeCompare(t.zone.name)}function q(){try{var t=Intl.DateTimeFormat().resolvedOptions().timeZone;if(t&&3<t.length){var e=l[D(t)];if(e)return e;Z("Moment Timezone found "+t+" from the Intl api, but did not have that data loaded.")}}catch(t){}for(var n,o,r=E(),i=r.length,s=function(t){for(var e,n,o,r=t.length,i={},s=[],f={},a=0;a<r;a++)if(n=t[a].offset,!f.hasOwnProperty(n)){for(e in o=c[n]||{})o.hasOwnProperty(e)&&(i[e]=!0);f[n]=!0}for(a in i)i.hasOwnProperty(a)&&s.push(l[a]);return s}(r),f=[],a=0;a<s.length;a++){for(n=new T(C(s[a])),o=0;o<i;o++)n.scoreOffsetAt(r[o]);f.push(n)}return f.sort(Y),0<f.length?f[0].zone.name:void 0}function D(t){return(t||"").toLowerCase().replace(/\//g,"_")}function j(t){var e,n,o,r;for("string"==typeof t&&(t=[t]),e=0;e<t.length;e++){r=D(n=(o=t[e].split("|"))[0]),u[r]=t[e],l[r]=n,s=i=a=f=void 0;var i,s,f=r,a=o[2].split(" ");for(p(a),i=0;i<a.length;i++)s=a[i],c[s]=c[s]||{},c[s][f]=!0}}function C(t,e){t=D(t);var n=u[t];return n instanceof w?n:"string"==typeof n?(n=new w(n),u[t]=n):i[t]&&e!==C&&(e=C(i[t],C))?((n=u[t]=new w)._set(e),n.name=l[t],n):null}function S(t){var e,n,o,r;for("string"==typeof t&&(t=[t]),e=0;e<t.length;e++)o=D((n=t[e].split("|"))[0]),r=D(n[1]),i[o]=r,l[o]=n[0],i[r]=o,l[r]=n[1]}function M(t){return M.didShowError||(M.didShowError=!0,Z("moment.tz.zoneExists('"+t+"') has been deprecated in favor of !moment.tz.zone('"+t+"')")),!!C(t)}function A(t){var e="X"===t._f||"x"===t._f;return!(!t._a||void 0!==t._tzm||e)}function U(t,e,n){var o,r,i,s,f=m.now,a=m.defaultZone,u=v,l=d,c=z,h=g,p=!1;v||(d=void 0,z=f,g=!1),v=!0,m.now=function(){return p||(g||(d=z.call(m),g=!0),o=d,p=!0,r=m.tz(o,e),r=r.valueOf()+6e4*r.utcOffset()),r},n&&(m.defaultZone=O);try{s=m.utc.apply(null,t),n&&p&&s._a&&void 0!==s._tzm&&((i=s.parsingFlags().parsedDateParts)&&null!=i[0]&&null!=i[1]&&null!=i[2]||(m.now=function(){return o},m.defaultZone=a,s=m.utc.apply(null,t)))}finally{m.now=f,m.defaultZone=a,(v=u)||(d=l,z=c,g=h)}return s}function Z(t){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(t)}function P(t){var e=Array.prototype.slice.call(arguments,0,-1),n=arguments[arguments.length-1],o=function(t){if(!m.isMoment(t)&&null!==t&&"[object Object]"===Object.prototype.toString.call(t)){if(Object.getOwnPropertyNames)return 0<Object.getOwnPropertyNames(t).length;for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0}return!1}(t),r=0<e.length&&"string"==typeof t,i=o||r?C(n):null,r=o&&i?U(e,n):r&&i?U(e,n,!0):m.utc.apply(null,e);return!m.isMoment(t)&&A(r)&&(i||!o&&(i=C(n)))&&r.add(i.parse(r),"minutes"),r.tz(n),r}O._set({name:"UTC",abbrs:["UTC"],untils:[1/0],offsets:[0],population:0}),T.prototype.scoreOffsetAt=function(t){this.offsetScore+=Math.abs(this.zone.utcOffset(t.at)-t.offset),this.zone.abbr(t.at).replace(/[^A-Z]/g,"")!==t.abbr&&this.abbrScore++},P.version="0.6.4",P.dataVersion="",P._zones=u,P._links=i,P._names=l,P._countries=f,P.add=j,P.link=S,P.load=function(t){j(t.zones),S(t.links);var e,n,o,r=t.countries;if(r&&r.length)for(e=0;e<r.length;e++)n=(o=r[e].split("|"))[0].toUpperCase(),o=o[1].split(" "),f[n]=new k(n,o);P.dataVersion=t.version},P.zone=C,P.zoneExists=M,P.guess=function(t){return e=e&&!t?e:q()},P.names=function(){var t,e=[];for(t in l)l.hasOwnProperty(t)&&(u[t]||u[i[t]])&&l[t]&&e.push(l[t]);return e.sort()},P.Zone=w,P.unpack=_,P.unpackBase60=r,P.needsOffset=A,P.moveInvalidForward=!0,P.moveAmbiguousForward=!1,P.countries=function(){return Object.keys(f)},P.zonesForCountry=function(t,e){var n;return n=(n=t).toUpperCase(),(t=f[n]||null)?(n=t.zones.sort(),e?n.map(function(t){return{name:t,offset:C(t).utcOffset(new Date)}}):n):null};var F,t=m.fn,x=(m.tz=P,m.defaultZone=null,m._getDefaultDateParts);function I(t){return function(){return this._z?this._z.abbr(this):t.call(this)}}function N(t){return function(){return this._z=null,t.apply(this,arguments)}}x&&(m._getDefaultDateParts=function(t,e,n){var o,r,i=m.defaultZone;if(n=n||t._isDefaultDatePartsForWeek,v&&void 0===t._tzm)return[(r=new Date(e)).getUTCFullYear(),r.getUTCMonth(),r.getUTCDate()];if(i&&!t._useUTC&&void 0===t._tzm)return[(r=new Date(e-6e4*i.utcOffset(e))).getUTCFullYear(),r.getUTCMonth(),r.getUTCDate()];if(!n||!t._useUTC&&void 0===t._tzm)return x.call(this,t,e,n);i=s,r=a,s=e,a=!0;try{o=x.call(this,t,e,n)}finally{s=i,a=r}return o}),m.updateOffset=function(t,e){var n,o,r=a&&s===t._i?null:m.defaultZone;void 0===t._z&&(r&&A(t)&&!t._isUTC&&t.isValid()&&(t._d=m.utc(t._a)._d,t.utc().add(r.parse(t),"minutes")),t._z=r),t._z&&(r=t._z.utcOffset(t),e&&(o=t._d.valueOf(),t._isUTC||(o-=6e4*t._d.getTimezoneOffset()),t._z.utcOffset(o+6e4*r)!==r)&&(n=(o+=6e4*(r=t._z.parse(o)))-6e4*(r=t._z.utcOffset(o))),Math.abs(r)<16&&(r/=60),void 0!==t.utcOffset?(o=t._z,t.utcOffset(-r,e),t._z=o):t.zone(r,e),null!=n)&&t._d.setTime(n)},t.tz=function(t,e){if(t){if("string"!=typeof t)throw new Error("Time zone name must be a string, got "+t+" ["+typeof t+"]");return this._z=C(t),this._z?m.updateOffset(this,e):Z("Moment Timezone has no data for "+t+". See http://momentjs.com/timezone/docs/#/data-loading/."),this}if(this._z)return this._z.name},t.zoneName=I(t.zoneName),t.zoneAbbr=I(t.zoneAbbr),t.utc=N(t.utc),t.local=N(t.local),t.utcOffset=(F=t.utcOffset,function(){return 0<arguments.length&&(this._z=null),F.apply(this,arguments)}),m.tz.setDefault=function(t){return(n<2||2==n&&o<9)&&Z("Moment Timezone setDefault() requires Moment.js >= 2.9.0. You are using Moment.js "+m.version+"."),m.defaultZone=t?C(t):null,m};t=m.momentProperties;return"[object Array]"===Object.prototype.toString.call(t)?(t.push("_z"),t.push("_a")):t&&(t._z=null),m});