Skip to content

Commit

Permalink
test(datetime-util): add tests for updateDate
Browse files Browse the repository at this point in the history
  • Loading branch information
tobika committed Oct 1, 2016
1 parent 9e7bcfa commit 0f9c307
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/util/test/datetime-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,74 @@ describe('parseISODate', () => {

});

describe('updateDate', () => {

it('should update year in existing date', () => {
var existingDate = { year: 2016, month: 10, day: 1 };
datetime.updateDate(existingDate, { year: { value: 2017 } });
expect(existingDate.year).toEqual(2017);
});

it('should update month in existing date', () => {
var existingDate = { year: 2016, month: 10, day: 1 };
datetime.updateDate(existingDate, { month: { value: 11 } });
expect(existingDate.month).toEqual(11);
});

it('should update day in existing date', () => {
var existingDate = { year: 2016, month: 10, day: 1 };
datetime.updateDate(existingDate, { day: { value: 2 } });
expect(existingDate.day).toEqual(2);
});

it('should update hour in existing time', () => {
var existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 11 } });
expect(existingDate.hour).toEqual(11);
});

it('should update minute in existing time', () => {
var existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { minute: { value: 45 } });
expect(existingDate.minute).toEqual(45);
});

it('should update second in existing time', () => {
var existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { second: { value: 10 } });
expect(existingDate.second).toEqual(10);
});

it('should update hour PM in existing time', () => {
var existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 1 }, ampm: { value: 'pm' }});
expect(existingDate.hour).toEqual(13);

existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 12 }, ampm: { value: 'pm' }});
expect(existingDate.hour).toEqual(12);

existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 4 }, ampm: { value: 'pm' }});
expect(existingDate.hour).toEqual(16);
});

it('should update hour AM in existing time', () => {
var existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 1 }, ampm: { value: 'am' }});
expect(existingDate.hour).toEqual(1);

existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 12 }, ampm: { value: 'am' }});
expect(existingDate.hour).toEqual(0);

existingDate = { hour: 10, minute: 30, second: 0 };
datetime.updateDate(existingDate, { hour: { value: 4 }, ampm: { value: 'am' }});
expect(existingDate.hour).toEqual(4);
});

});

// pt-br
var customLocale: datetime.LocaleData = {
dayNames: [
Expand Down

0 comments on commit 0f9c307

Please sign in to comment.