Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doing a first aim at getting midnight after adding 1 day. If that tim… #3716

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/lib/moment/start-end-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,12 @@ export function endOf (units) {
units = 'day';
}

return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
var firstAim = this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units));
var isMidnight = this.hours() === 0 && this.minutes() === 0;

if (isMidnight) {
return firstAim.subtract(1, 'ms');
}

return firstAim.startOf(units).subtract(1, 'ms');
}
17 changes: 16 additions & 1 deletion src/test/moment/start_end_of.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,22 @@ test('end of day', function (assert) {
assert.equal(m.hours(), 23, 'set the hours');
assert.equal(m.minutes(), 59, 'set the minutes');
assert.equal(m.seconds(), 59, 'set the seconds');
assert.equal(m.milliseconds(), 999, 'set the seconds');
assert.equal(m.milliseconds(), 999, 'set the milliseconds');
});

test('end of day with timezone on day DST switch occurs', function (assert) {
var m = moment(new Date(2016, 10, 16, 3, 4, 5, 6), 'America/Sao_Paulo').endOf('day'),
ms = moment(new Date(2016, 10, 16, 3, 4, 5, 6), 'America/Sao_Paulo').endOf('days'),
ma = moment(new Date(2016, 10, 16, 3, 4, 5, 6), 'America/Sao_Paulo').endOf('d');
assert.equal(+m, +ms, 'Plural or singular should work');
assert.equal(+m, +ma, 'Full or abbreviated should work');
assert.equal(m.year(), 2016, 'keep the year');
assert.equal(m.month(), 10, 'keep the month');
assert.equal(m.date(), 16, 'keep the day');
assert.equal(m.hours(), 23, 'set the hours');
assert.equal(m.minutes(), 59, 'set the minutes');
assert.equal(m.seconds(), 59, 'set the seconds');
assert.equal(m.milliseconds(), 999, 'set the milliseconds');
});

test('start of date', function (assert) {
Expand Down