1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

test: remove api call for timezone

This commit is contained in:
Steven Tang 2023-01-21 19:39:28 +11:00
parent 0160a9ae52
commit 71563c2c33
No known key found for this signature in database
GPG Key ID: 1597520C734BAE66

View File

@ -3370,20 +3370,17 @@
"// pretend we're in Berlin, as this is also the time zone configured for the user", "// pretend we're in Berlin, as this is also the time zone configured for the user",
"const userZone = 'Europe/Berlin'", "const userZone = 'Europe/Berlin'",
"", "",
"// postman doesn't have moment-timezone package included", "// https://stackoverflow.com/a/63199512",
"// and we can't just use utcOffset(2), because of summer / winter time", "// return UTC offset of timezone in minutes",
"// inspired by https://stackoverflow.com/a/56853085/3112139", "function getTimezoneOffset(timeZone, date = new Date()) {",
"function getUtcOffset(cb) {", " const tz = date.toLocaleString(\"en\", {timeZone, timeStyle: \"long\"}).split(\" \").slice(-1)[0];",
" let offset = pm.globals.get('utcOffset')", " const dateString = date.toString();",
" if (offset) return cb(offset)", " const offset = Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);",
" pm.sendRequest(`https://worldtimeapi.org/api/timezone/${userZone}`, (err, res) => {", " return offset / 1000 / 60;",
" offset = res.json().utc_offset",
" pm.globals.set('utcOffset', offset)",
" return cb(offset)",
" })",
"}", "}",
"", "",
"getUtcOffset((utcOffset) => {", "const utcOffset = getTimezoneOffset(userZone);",
"",
"const now = moment().utcOffset(utcOffset)", "const now = moment().utcOffset(utcOffset)",
"const startOfDay = now.clone().startOf('day')", "const startOfDay = now.clone().startOf('day')",
"const endOfDay = now.clone().endOf('day')", "const endOfDay = now.clone().endOf('day')",
@ -3419,8 +3416,7 @@
"pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())", "pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
"pm.variables.set('ts1', now.clone().startOf('hour').format('x') / 1000)", "pm.variables.set('ts1', now.clone().startOf('hour').format('x') / 1000)",
"pm.variables.set('ts2', now.clone().startOf('hour').add(1, 'm').format('x') / 1000)", "pm.variables.set('ts2', now.clone().startOf('hour').add(1, 'm').format('x') / 1000)",
" pm.variables.set('ts3', now.clone().startOf('hour').add(2, 'm').format('x') / 1000)", "pm.variables.set('ts3', now.clone().startOf('hour').add(2, 'm').format('x') / 1000)"
"})"
] ]
} }
}, },