diff --git a/core/src/components/datetime/datetime-util.ts b/core/src/components/datetime/datetime-util.ts index 0c3ba61d55..6a18709ca0 100644 --- a/core/src/components/datetime/datetime-util.ts +++ b/core/src/components/datetime/datetime-util.ts @@ -247,8 +247,8 @@ export function parseDate(val: string | undefined | null): DatetimeData | undefi * Note: This is not meant for time strings * such as "01:47" */ -export const getLocalDateTime = (dateString = ''): Date => { - const date = (dateString.length > 0) ? new Date(dateString) : new Date(); +export const getLocalDateTime = (dateString: any = ''): Date => { + const date = (typeof dateString === 'string' && dateString.length > 0) ? new Date(dateString) : new Date(); return new Date( Date.UTC( diff --git a/core/src/components/datetime/test/datetime.spec.ts b/core/src/components/datetime/test/datetime.spec.ts index 362bc8fa00..0611d1c3b5 100644 --- a/core/src/components/datetime/test/datetime.spec.ts +++ b/core/src/components/datetime/test/datetime.spec.ts @@ -40,7 +40,7 @@ describe('Datetime', () => { { expectedHourUTC: 12, input: `2019-11-02T12:08:06.601-00:00`, expectedOutput: `2019-11-02T%HOUR%:08:06.601Z` }, { expectedHourUTC: 8, input: `1994-12-15T13:47:20.789+05:00`, expectedOutput: `1994-12-15T%HOUR%:47:20.789Z` }, { expectedHourUTC: 18, input: `1994-12-15T13:47:20.789-05:00`, expectedOutput: `1994-12-15T%HOUR%:47:20.789Z` }, - { expectedHourUTC: 9, input: `2019-02-14T09:00:00.000Z`, expectedOutput: `2019-02-14T%HOUR%:00:00.000Z` } + { expectedHourUTC: 9, input: `2019-02-14T09:00:00.000Z`, expectedOutput: `2019-02-14T%HOUR%:00:00.000Z` } ]; dateStringTests.forEach(test => {