-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
405 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.minitz=factory())})(this,function(){"use strict";function minitz(year,month,day,hour,minute,second,timezone,throwOnInvalidTime){return minitz.fromTZ(minitz.tp(year,month,day,hour,minute,second,timezone),throwOnInvalidTime)}minitz.fromTZISO=(localTimeString,timezone,throwOnInvalidTime)=>{return minitz.fromTZ(parseISOLocal(localTimeString,timezone),throwOnInvalidTime)};minitz.fromTZ=function(timePoint,throwOnInvalidTime){const inputDate=new Date(Date.UTC(timePoint.year,timePoint.month-1,timePoint.day,timePoint.hour,timePoint.minute,timePoint.second)),offset=getTimezoneOffset(timePoint.timezone,inputDate),guessedLocalDate=new Date(inputDate.getTime()-offset),guessedInputDateOffset=getTimezoneOffset(timePoint.timezone,guessedLocalDate);if(guessedInputDateOffset-offset===0){return guessedLocalDate}else{const guessedLocalDate2=new Date(inputDate.getTime()-guessedInputDateOffset),guessedInputDateOffset2=getTimezoneOffset(timePoint.timezone,guessedLocalDate2);if(guessedInputDateOffset2-guessedInputDateOffset===0){return guessedLocalDate2}else if(!throwOnInvalidTime){return guessedLocalDate}else{throw new Error("Invalid date passed to fromTZ()")}}};minitz.toTZ=function(date,tzString){const target=new Date(date.toLocaleString("sv-SE",{timeZone:tzString}));return{year:target.getFullYear(),month:target.getMonth()+1,day:target.getDate(),hour:target.getHours(),minute:target.getMinutes(),second:target.getSeconds(),timezone:tzString}};minitz.tp=(y,m,d,h,i,s,t)=>{return{year:y,month:m,day:d,hour:h,minute:i,second:s,timezone:t}};function getTimezoneOffset(timeZone,date=new Date){const tz=date.toLocaleString("en",{timeZone:timeZone,timeStyle:"long"}).split(" ").slice(-1)[0];const dateString=date.toString();return Date.parse(`${dateString} UTC`)-Date.parse(`${dateString} ${tz}`)}function parseISOLocal(dateTimeString,timezone){const parsed=new Date(Date.parse(dateTimeString));if(isNaN(parsed)){throw new Error("minitz: Invalid ISO8601 passed to parser.")}const stringEnd=dateTimeString.substring(9);if(dateTimeString.includes("Z")||stringEnd.includes("-")||stringEnd.includes("+")){return minitz.tp(parsed.getUTCFullYear(),parsed.getUTCMonth()+1,parsed.getUTCDate(),parsed.getUTCHours(),parsed.getUTCMinutes(),parsed.getUTCSeconds(),"Etc/UTC")}else{return minitz.tp(parsed.getFullYear(),parsed.getMonth()+1,parsed.getDate(),parsed.getHours(),parsed.getMinutes(),parsed.getSeconds(),timezone)}}minitz.minitz=minitz;return minitz}); | ||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.minitz=factory())})(this,function(){"use strict";function minitz(y,m,d,h,i,s,tz,throwOnInvalid){return minitz.fromTZ(minitz.tp(y,m,d,h,i,s,tz),throwOnInvalid)}minitz.fromTZISO=(localTimeStr,tz,throwOnInvalid)=>{return minitz.fromTZ(parseISOLocal(localTimeStr,tz),throwOnInvalid)};minitz.fromTZ=function(tp,throwOnInvalid){const inDate=new Date(Date.UTC(tp.y,tp.m-1,tp.d,tp.h,tp.i,tp.s)),offset=getTimezoneOffset(tp.tz,inDate),dateGuess=new Date(inDate.getTime()-offset),dateOffsGuess=getTimezoneOffset(tp.tz,dateGuess);if(dateOffsGuess-offset===0){return dateGuess}else{const dateGuess2=new Date(inDate.getTime()-dateOffsGuess),dateOffsGuess2=getTimezoneOffset(tp.tz,dateGuess2);if(dateOffsGuess2-dateOffsGuess===0){return dateGuess2}else if(!throwOnInvalid){return dateGuess}else{throw new Error("Invalid date passed to fromTZ()")}}};minitz.toTZ=function(d,tzStr){const td=new Date(d.toLocaleString("sv-SE",{timeZone:tzStr}));return{y:td.getFullYear(),m:td.getMonth()+1,d:td.getDate(),h:td.getHours(),i:td.getMinutes(),s:td.getSeconds(),tz:tzStr}};minitz.tp=(y,m,d,h,i,s,tz)=>{return{y:y,m:m,d:d,h:h,i:i,s:s,tz:tz}};function getTimezoneOffset(timeZone,date=new Date){const tz=date.toLocaleString("en",{timeZone:timeZone,timeStyle:"long"}).split(" ").slice(-1)[0];const dateString=date.toString();return Date.parse(`${dateString} UTC`)-Date.parse(`${dateString} ${tz}`)}function parseISOLocal(dtStr,tz){const pd=new Date(Date.parse(dtStr));if(isNaN(pd)){throw new Error("minitz: Invalid ISO8601 passed to parser.")}const stringEnd=dtStr.substring(9);if(dtStr.includes("Z")||stringEnd.includes("-")||stringEnd.includes("+")){return minitz.tp(pd.getUTCFullYear(),pd.getUTCMonth()+1,pd.getUTCDate(),pd.getUTCHours(),pd.getUTCMinutes(),pd.getUTCSeconds(),"Etc/UTC")}else{return minitz.tp(pd.getFullYear(),pd.getMonth()+1,pd.getDate(),pd.getHours(),pd.getMinutes(),pd.getSeconds(),tz)}}minitz.minitz=minitz;return minitz}); |
Oops, something went wrong.