]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Default ignoreOffset = true for dates, months and years 1467/head
authorIskren Chernev <iskren.chernev@gmail.com>
Thu, 6 Feb 2014 18:40:54 +0000 (10:40 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 6 Feb 2014 18:40:54 +0000 (10:40 -0800)
When you do moment.date(5), you'd expect the time-of-day to remain the same
even across DST. This only affects users of moment-timezone

moment.js

index edf54c173bc389b3200e81b3099648ab9a217048..e353879f9329769e195c36ea7712d75606de14d3 100644 (file)
--- a/moment.js
+++ b/moment.js
             hours = mom.hour();
         }
         if (days) {
-            mom.date(mom.date() + days * isAdding, true);
+            mom.date(mom.date() + days * isAdding);
         }
         if (months) {
-            mom.month(mom.month() + months * isAdding, true);
+            mom.month(mom.month() + months * isAdding);
         }
         if (milliseconds && !ignoreUpdateOffset) {
             moment.updateOffset(mom, days || months);
                     }
                 }
 
-                dayOfMonth = this.date();
-                this.date(1, true);
-                this._d['set' + utc + 'Month'](input, true);
-                this.date(Math.min(dayOfMonth, this.daysInMonth()), true);
-
+                dayOfMonth = Math.min(this.date(),
+                        daysInMonth(this.year(), input));
+                this._d['set' + utc + 'Month'](input, dayOfMonth);
                 moment.updateOffset(this, true);
                 return this;
             } else {
         // ignoreOffsetTransitions provides a hint to updateOffset to not
         // change hours/minutes when crossing a tz boundary.  This is frequently
         // desirable when modifying part of an existing moment object directly.
+        var defaultIgnoreOffsetTransitions = key === 'date' || key === 'month' || key === 'year';
         moment.fn[name] = moment.fn[name + 's'] = function (input, ignoreOffsetTransitions) {
             var utc = this._isUTC ? 'UTC' : '';
+            if (ignoreOffsetTransitions == null) {
+                ignoreOffsetTransitions = defaultIgnoreOffsetTransitions;
+            }
             if (input != null) {
                 this._d['set' + utc + key](input);
                 moment.updateOffset(this, ignoreOffsetTransitions);
         };
     }
 
-    // loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds)
+    // loop through and add shortcuts (Date, Hours, Minutes, Seconds, Milliseconds)
+    // Month has a custom getter/setter.
     for (i = 0; i < proxyGettersAndSetters.length; i ++) {
         makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase().replace(/s$/, ''), proxyGettersAndSetters[i]);
     }