]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
- Fixing issue #3132
authorkostas <kkopanidis@gmail.com>
Tue, 9 May 2017 08:45:52 +0000 (11:45 +0300)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 9 Aug 2017 11:55:36 +0000 (14:55 +0300)
src/lib/moment/start-end-of.js

index 02f982479ad8959af97b4ea99812c110c95e3d98..36674ccc51ecd3fecb0d51a08918b757c72debf7 100644 (file)
@@ -1,29 +1,29 @@
-import { normalizeUnits } from '../units/aliases';
+import {normalizeUnits} from '../units/aliases';
 
-export function startOf (units) {
+export function startOf(units) {
     units = normalizeUnits(units);
     // the following switch intentionally omits break keywords
     // to utilize falling through the cases.
     switch (units) {
         case 'year':
             this.month(0);
-            /* falls through */
+        /* falls through */
         case 'quarter':
         case 'month':
             this.date(1);
-            /* falls through */
+        /* falls through */
         case 'week':
         case 'isoWeek':
         case 'day':
         case 'date':
             this.hours(0);
-            /* falls through */
+        /* falls through */
         case 'hour':
             this.minutes(0);
-            /* falls through */
+        /* falls through */
         case 'minute':
             this.seconds(0);
-            /* falls through */
+        /* falls through */
         case 'second':
             this.milliseconds(0);
     }
@@ -44,7 +44,7 @@ export function startOf (units) {
     return this;
 }
 
-export function endOf (units) {
+export function endOf(units) {
     units = normalizeUnits(units);
     if (units === undefined || units === 'millisecond') {
         return this;
@@ -55,5 +55,15 @@ export function endOf (units) {
         units = 'day';
     }
 
-    return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
+    switch (units) {
+        case 'day':
+            var endOfDay = this.startOf(units).add(1, units).subtract(1, 'ms');
+            endOfDay.hours(23);
+            endOfDay.minutes(59);
+            endOfDay.seconds(59);
+            endOfDay.milliseconds(999);
+            return endOfDay;
+        default:
+         return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
+    }
 }