Skip to content

Commit

Permalink
- Fixing issue moment#3132
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis authored and fbonzon committed Oct 28, 2017
1 parent 1c75c3a commit e8bd9cb
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/lib/moment/start-end-of.js
@@ -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);
}
Expand All @@ -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;
Expand All @@ -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');
}
}

0 comments on commit e8bd9cb

Please sign in to comment.