mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(datetime): fix edge cases with datetime and invalid values (#17769)
* fix edge cases with datetime and invalid values * clean up code * revert let changes * run linter
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user