]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Changed startOf method to use a switch with fallthrough as suggested by timrwood... 283/head
authorMattias Runge <mattias@runge.se>
Mon, 23 Apr 2012 19:14:30 +0000 (21:14 +0200)
committerMattias Runge <mattias@runge.se>
Mon, 23 Apr 2012 19:14:30 +0000 (21:14 +0200)
moment.js

index d14cbbb671e7b6f4759b1a4f2c7579d3c527385d..b85ca7d56313d96185f0b658c66f2ca78a5e4fdc 100644 (file)
--- a/moment.js
+++ b/moment.js
         },
 
         startOf: function (val) {
-            if (val === 'years') {
-                return this.clone()
-                    .month(0)
-                    .date(1)
-                    .hours(0)
-                    .minutes(0)
-                    .seconds(0)
-                    .milliseconds(0);
-            } else if (val === 'months') {
-                return this.clone()
-                    .date(1)
-                    .hours(0)
-                    .minutes(0)
-                    .seconds(0)
-                    .milliseconds(0);
-            } else if (val === 'days') {
-                return this.clone()
-                    .hours(0)
-                    .minutes(0)
-                    .seconds(0)
-                    .milliseconds(0);
-            } else if (val === 'hours') {
-                return this.clone()
-                    .minutes(0)
-                    .seconds(0)
-                    .milliseconds(0);
-            } else if (val === 'minutes') {
-                return this.clone()
-                    .seconds(0)
-                    .milliseconds(0);
-            } else if (val === 'seconds') {
-                return this.clone()
-                    .milliseconds(0);
+            var output = this.clone();
+            // the following switch intentionally omits break keywords
+            // to utilize falling through the cases.
+            switch (val) {
+            case 'years':
+                output.month(0);
+                /* falls through */
+            case 'months':
+                output.date(1);
+                /* falls through */
+            case 'days':
+                output.hours(0);
+                /* falls through */
+            case 'hours':
+                output.minutes(0);
+                /* falls through */
+            case 'minutes':
+                output.seconds(0);
+                /* falls through */
+            case 'seconds':
+                output.milliseconds(0);
+                /* falls through */
             }
-            return this.clone();
+            return output;
         },
-        
+                
         endOf: function (val) {
             return this.startOf(val).add(val, 1).subtract('milliseconds', 1);
         },