Skip to content

Commit

Permalink
Fix endOf day on brazilian DST start being the next day
Browse files Browse the repository at this point in the history
  • Loading branch information
gfpacheco committed Oct 9, 2018
1 parent 2e2a5b3 commit 33b0106
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/moment/start-end-of.js
Expand Up @@ -55,5 +55,5 @@ export function endOf (units) {
units = 'day';
}

return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
return this.add(1, (units === 'isoWeek' ? 'week' : units)).startOf(units).subtract(1, 'ms');
}
21 changes: 21 additions & 0 deletions src/test/moment/start_end_of.js
Expand Up @@ -347,6 +347,27 @@ test('startOf across DST +1', function (assert) {
moment.updateOffset = oldUpdateOffset;
});

test('endOf across DST +1', function (assert) {
var oldUpdateOffset = moment.updateOffset,
// Based on a real story somewhere in America/Sao_Paulo
dstAt = moment('2018-11-04T00:00:00-03:00').parseZone(),
m;

moment.updateOffset = function (mom, keepTime) {
if (mom.isBefore(dstAt)) {
mom.utcOffset(-3, keepTime);
} else {
mom.utcOffset(-2, keepTime);
}
};

m = moment('2018-11-04T09:00:00-02:00').parseZone();
m.endOf('d');
assert.equal(m.format(), '2018-11-04T23:59:59-02:00', 'endOf(\'d\') across +1');

moment.updateOffset = oldUpdateOffset;
});

test('startOf across DST -1', function (assert) {
var oldUpdateOffset = moment.updateOffset,
// Based on a real story somewhere in America/Los_Angeles
Expand Down

0 comments on commit 33b0106

Please sign in to comment.