Comparing version 0.7.3 to 0.7.4
{ | ||
"name": "notabase", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "API Wrapper For Notion's Database", | ||
@@ -5,0 +5,0 @@ "main": "src/notabase.js", |
@@ -270,4 +270,4 @@ const utils = require('./utils') | ||
res = { | ||
startDate: date.start_date ? utils.fixTimeZone(new Date(`${date.start_date} ${date.start_time || '00:00'}`), date.time_zone) : undefined, | ||
endDate: date.end_date ? utils.fixTimeZone(new Date(`${date.end_date} ${date.end_time || '00:00'}`), date.time_zone) : undefined, | ||
startDate: date.start_date ? utils.fixTimeZone(`${date.start_date} ${date.start_time || '00:00'}`, date.time_zone) : undefined, | ||
endDate: date.end_date ? utils.fixTimeZone(`${date.end_date} ${date.end_time || '00:00'}`, date.time_zone) : undefined, | ||
includeTime: date.type.indexOf("time") !== -1, | ||
@@ -274,0 +274,0 @@ timeZone: date.time_zone |
@@ -55,3 +55,3 @@ const NOTION_BASE_URL = "https://www.notion.so" | ||
const formatDate = (date) => { | ||
return `${date.getFullYear()}-${(date.getMonth() + "").padStart(2, "0")}-${(date.getDate() + "").padStart(2, "0")}` | ||
return `${date.getFullYear()}-${(date.getMonth() + 1 + "").padStart(2, "0")}-${(date.getDate() + "").padStart(2, "0")}` | ||
} | ||
@@ -61,23 +61,14 @@ const formatTime = (date) => { | ||
} | ||
const fixTimeZone = (date, timeZone) => { | ||
const firstDate = new Date(date.toLocaleString('en-US', { | ||
timeZone | ||
})); | ||
const secondDate = new Date(date.toLocaleString('en-US', { | ||
timeZone: "UTC" | ||
})); | ||
const diff = firstDate.getTime() - secondDate.getTime(); | ||
return new Date(date.getTime() + diff); | ||
const fixTimeZone = (dateAsString, timeZone) => { | ||
const shortTz = new Date(). | ||
toLocaleString("en", { timeZoneName: "short", timeZone }). | ||
split(' '). | ||
pop() | ||
return new Date(dateAsString + " " + shortTz); | ||
} | ||
const unFixTimeZone = (date, timeZone) => { | ||
const firstDate = new Date(date.toLocaleString('en-US', { | ||
timeZone | ||
})); | ||
const secondDate = new Date(date.toLocaleString('en-US', { | ||
timeZone: "UTC" | ||
})); | ||
const diff = firstDate.getTime() - secondDate.getTime(); | ||
return new Date(date.getTime() + diff); | ||
const adjustedTime = date.toLocaleString("en-US", { timeZone }); | ||
return new Date(adjustedTime); | ||
} | ||
module.exports = { isPageId, getBlockHashId, getFullBlockId, getBrowseableUrl, getUrlPageId, parseImageUrl, formatDate, formatTime, fixTimeZone, unFixTimeZone } |
36936
740