🚀 feature request – parseDate – localizable date parsing, supporting different date formats into date object
This feature request is for @angular/common
on behalf of Annotation Slovakia s.r.o, we would like to propose an extension for date manipulation.
Throughout multiple projects we have found ourselves dwelling on missing native support for date parsing in angular. As a result of this we have been forced to use another “unnecessary” libraries, such as moment.js, or components without ControlValueAccessor, each with custom date parsing implementation.
We hope you will consider adding this function into framework and as soon as discussion is resolved we will create PR.
Annotation Slovakia s.r.o.
We are aware of PR #31143, but it was declined as exported utility and it would only work with one date format without localization
export type BasicDateFormat = 'short' | 'medium' | 'long' | 'full' | 'shortDate' | 'mediumDate' | 'longDate' | 'fullDate' | 'shortTime' | 'mediumTime' | 'longTime' | 'fullTime'; export function parseDate(value: string, format: BasicDateFormat | string, locale: string, oldValue?: Date): Date;
Example usage 1:
const dateString: string = '2021-01-27T22:37:44+02:00'; const format: string = 'yyyy-MM-ddTHH:mm:ssZZZZZ'; const date: Date = parseDate(dateString, format, 'sk', undefined); // date = Wed Jan 27 2021 21:37:44 GMT+0100 (Central European Standard Time)
Example usage 2:
const dateString: string = '1.1.2020'; const format: BasicDateFormat = 'shortDate'; const date: Date = parseDate(dateString, format, 'sk', undefined); // date = Wed Jan 01 2020 01:00:00 GMT+0100 (Central European Standard Time)
Describe the solution you’d like
We would like to open a discussion about this feature and as soon as it is approved we will create PR