From: Mattias Runge Date: Mon, 23 Apr 2012 19:14:30 +0000 (+0200) Subject: Changed startOf method to use a switch with fallthrough as suggested by timrwood... X-Git-Tag: 1.7.0~48^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F283%2Fhead;p=thirdparty%2Fmoment.git Changed startOf method to use a switch with fallthrough as suggested by timrwood, added /* falls through */ comments to pass JSHint --- diff --git a/moment.js b/moment.js index d14cbbb67..b85ca7d56 100644 --- a/moment.js +++ b/moment.js @@ -817,43 +817,32 @@ }, 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); },