MCPcopy
hub / github.com/date-fns/date-fns / syncToInternal

Function syncToInternal

pkgs/tz/src/date/mini.js:158–177  ·  view source on GitHub ↗

* @internal * Function syncs time to internal date, applying the current time zone offset. * * @param {Date} date - `Date` to sync

(date)

Source from the content-addressed store, hash-verified

156 * @param {Date} date - `Date` to sync
157 */
158function syncToInternal(date) {
159 // Start internal from the same real timestamp as external.
160 date.internal.setTime(+date);
161
162 // Shift internal by the target offset so its UTC fields become the target-zone
163 // wall-clock fields for the external timestamp.
164 //
165 // o internal UTC fields: 2024-02-11 00:00
166 // |
167 // | + Asia/Singapore offset (+08:00)
168 // v
169 // x internal UTC fields: 2024-02-11 08:00
170 //
171 date.internal.setUTCSeconds(
172 date.internal.getUTCSeconds() -
173 // Round after converting minutes to seconds to avoid fractional offset
174 // precision errors from historical offsets.
175 Math.round(-tzOffset(date.timeZone, date) * 60),
176 );
177}
178
179/**
180 * @internal

Callers 3

setTimeMethod · 0.85
mini.jsFile · 0.85
adjustToSystemTZFunction · 0.85

Calls 2

tzOffsetFunction · 0.90
setTimeMethod · 0.80

Tested by

no test coverage detected