UNPKG

sugar

Version:

A Javascript utility library for working with native objects.

20 lines (17 loc) 824 B
'use strict'; var _utc = require('../var/_utc'), callDateGet = require('./callDateGet'); function callDateSet(d, method, value, safe) { // "Safe" denotes not setting the date if the value is the same as what is // currently set. In theory this should be a noop, however it will cause // timezone shifts when in the middle of a DST fallback. This is unavoidable // as the notation itself is ambiguous (i.e. there are two "1:00ams" on // November 1st, 2015 in northern hemisphere timezones that follow DST), // however when advancing or rewinding dates this can throw off calculations // so avoiding this unintentional shifting on an opt-in basis. if (safe && value === callDateGet(d, method, value)) { return; } d['set' + (_utc(d) ? 'UTC' : '') + method](value); } module.exports = callDateSet;