MCPcopy
hub / github.com/iamkun/dayjs / tzOffset

Function tzOffset

src/plugin/timezone/index.js:45–67  ·  view source on GitHub ↗
(timestamp, timezone)

Source from the content-addressed store, hash-verified

43 }
44
45 const tzOffset = (timestamp, timezone) => {
46 const formatResult = makeFormatParts(timestamp, timezone)
47 const filled = []
48 for (let i = 0; i < formatResult.length; i += 1) {
49 const { type, value } = formatResult[i]
50 const pos = typeToPos[type]
51
52 if (pos >= 0) {
53 filled[pos] = parseInt(value, 10)
54 }
55 }
56 const hour = filled[3]
57 // Workaround for the same behavior in different node version
58 // https://github.com/nodejs/node/issues/33027
59 /* istanbul ignore next */
60 const fixedHour = hour === 24 ? 0 : hour
61 const utcString = `${filled[0]}-${filled[1]}-${filled[2]} ${fixedHour}:${filled[4]}:${filled[5]}:000`
62 const utcTs = d.utc(utcString).valueOf()
63 let asTS = +timestamp
64 const over = asTS % 1000
65 asTS -= over
66 return (utcTs - asTS) / (60 * 1000)
67 }
68
69 // find the right offset a given local time. The o input is our guess, which determines which
70 // offset we'll pick in ambiguous cases (e.g. there are two 3 AMs b/c Fallback DST)

Callers 2

fixOffsetFunction · 0.85
index.jsFile · 0.85

Calls 3

makeFormatPartsFunction · 0.85
utcMethod · 0.80
valueOfMethod · 0.45

Tested by

no test coverage detected