Skip to content

Commit

Permalink
fix(dateadapter): moment dates not in utc format
Browse files Browse the repository at this point in the history
Moment DateAdapter should create dates in utc format to avoid time zone
collisions when passing date to servers

Closes angular#7167
  • Loading branch information
Silthus committed May 15, 2018
1 parent cc2bf64 commit 1db44c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('MomentDateAdapter', () => {
});

it('should create Moment date', () => {
expect(adapter.createDate(2017, JAN, 1).format()).toEqual(moment([2017, JAN, 1]).format());
expect(adapter.createDate(2017, JAN, 1).format()).toEqual(moment.utc([2017, JAN, 1]).format());
});

it('should not create Moment date with month over/under-flow', () => {
Expand All @@ -164,6 +164,10 @@ describe('MomentDateAdapter', () => {
expect(adapter.createDate(100, JAN, 1).year()).toBe(100);
});

it('should create Moment date in utc format', () => {
expect(adapter.createDate(2017, JAN, 5).isUTC()).toBeTruthy();
});

it("should get today's date", () => {
expect(adapter.sameDate(adapter.today(), moment()))
.toBe(true, "should be equal to today's date");
Expand Down
2 changes: 1 addition & 1 deletion src/material-moment-adapter/adapter/moment-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
}

let result = moment({year, month, date}).locale(this.locale);
let result = moment.utc({year, month, date}).locale(this.locale);

// If the result isn't valid, the date must have been out of bounds for this month.
if (!result.isValid()) {
Expand Down

0 comments on commit 1db44c3

Please sign in to comment.