From c1ad804be8921a9b45f214ef7f22f9728406e38f Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 1 Jun 2016 08:56:04 -0500 Subject: [PATCH] fix(datetime): clear out existing datetime data Closes #6614 --- src/components/datetime/test/basic/index.ts | 8 ++++++-- src/components/datetime/test/basic/main.html | 2 ++ src/components/datetime/test/datetime.spec.ts | 14 ++++++++++++++ src/util/datetime-util.ts | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/components/datetime/test/basic/index.ts b/src/components/datetime/test/basic/index.ts index 494ff488dda..e3fdc729e65 100644 --- a/src/components/datetime/test/basic/index.ts +++ b/src/components/datetime/test/basic/index.ts @@ -27,14 +27,18 @@ class E2EPage { 'l\u00f8r' ]; - onChange(ev) { + onChange(ev: any) { console.log("Changed", ev); } - onCancel(ev) { + onCancel(ev: any) { console.log("Canceled", ev); } + clearLeapYear() { + this.leapYearsSummerMonths = null; + } + } diff --git a/src/components/datetime/test/basic/main.html b/src/components/datetime/test/basic/main.html index 9d145657c13..bda450e2e8b 100644 --- a/src/components/datetime/test/basic/main.html +++ b/src/components/datetime/test/basic/main.html @@ -68,4 +68,6 @@ Leap year, summer months: {{leapYearsSummerMonths}}

+ + diff --git a/src/components/datetime/test/datetime.spec.ts b/src/components/datetime/test/datetime.spec.ts index d99a0b4bf86..519d71d943e 100644 --- a/src/components/datetime/test/datetime.spec.ts +++ b/src/components/datetime/test/datetime.spec.ts @@ -442,6 +442,20 @@ describe('DateTime', () => { expect(datetime.getValue()).toEqual({}); }); + it('should clear out existing value with blank value', () => { + datetime.setValue('1994-12-15T13:47:20.789Z'); + datetime.setValue(null); + expect(datetime.getValue()).toEqual({}); + + datetime.setValue('1994-12-15T13:47:20.789Z'); + datetime.setValue(undefined); + expect(datetime.getValue()).toEqual({}); + + datetime.setValue('1994-12-15T13:47:20.789Z'); + datetime.setValue(''); + expect(datetime.getValue()).toEqual({}); + }); + it('should not parse a value with blank value', () => { datetime.setValue(null); expect(datetime.getValue()).toEqual({}); diff --git a/src/util/datetime-util.ts b/src/util/datetime-util.ts index 7f80e1cfa57..bf43273c76c 100644 --- a/src/util/datetime-util.ts +++ b/src/util/datetime-util.ts @@ -261,6 +261,12 @@ export function updateDate(existingData: DateTimeData, newData: any) { // eww, invalid data console.warn(`Error parsing date: "${newData}". Please provide a valid ISO 8601 datetime format: https://www.w3.org/TR/NOTE-datetime`); + + } else { + // blank data, clear everything out + for (var k in existingData) { + delete existingData[k]; + } } }