mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
Merge pull request #8387 from tobika/fix/datetime-util
fix/datetime util
This commit is contained in:
@ -242,7 +242,7 @@ export function updateDate(existingData: DateTimeData, newData: any) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ((isPresent(newData.year) || isPresent(newData.hour))) {
|
} else if ((isPresent(newData.year) || isPresent(newData.hour) || isPresent(newData.month) || isPresent(newData.day) || isPresent(newData.minute) || isPresent(newData.second))) {
|
||||||
// newData is from of a datetime picker's selected values
|
// newData is from of a datetime picker's selected values
|
||||||
// update the existing DateTimeData data with the new values
|
// update the existing DateTimeData data with the new values
|
||||||
|
|
||||||
|
@ -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
|
// pt-br
|
||||||
var customLocale: datetime.LocaleData = {
|
var customLocale: datetime.LocaleData = {
|
||||||
dayNames: [
|
dayNames: [
|
||||||
|
Reference in New Issue
Block a user