UNPKG

1.25 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs_plugin_timezone=e()}(this,function(){"use strict";var t={year:0,month:1,day:2,hour:3,minute:4,second:5};return function(e,n,r){var o=r().utcOffset(),i=function(e,n){for(var o=new Date(e),i=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(o),u=[],a=0;a<i.length;a+=1){var f=i[a],c=f.type,d=f.value,s=t[c];s>=0&&(u[s]=parseInt(d,10))}var m=u[0]+"-"+u[1]+"-"+u[2]+" "+u[3]+":"+u[4]+":"+u[5]+":000",v=+o;return(r.utc(m).valueOf()-(v-=v%1e3))/6e4};n.prototype.tz=function(t){var e=this.toDate().toLocaleString("en-US",{timeZone:t}),n=Math.round((this.toDate()-new Date(e))/1e3/60);return r(e).utcOffset(o-n,!0)},r.tz=function(t,e){var n,o=i(+r(),e);"string"!=typeof t&&(n=r(t)+60*o*1e3);var u=function(t,e,n){var r=t-60*e*1e3,o=i(r,n);if(e===o)return[r,e];var u=i(r-=60*(o-e)*1e3,n);return o===u?[r,o]:[t-60*Math.min(o,u)*1e3,Math.max(o,u)]}(n=n||r.utc(t).valueOf(),o,e),a=u[0],f=u[1];return r(a).utcOffset(f)},r.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}}});