feature request – parseDate – localizable date parsing, supporting different date formats into date object

🚀 feature request – parseDate – localizable date parsing, supporting different date formats into date object

Relevant Package

This feature request is for @angular/common

Description

Hello,

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 have been internally working on @annotation/ng-datepicker where we implemented parseDate() function, which is based on angular formatDate() and we believe it should be part of angular framework.

We hope you will consider adding this function into framework and as soon as discussion is resolved we will create PR.

Regards.

Martin Filo,
Annotation Slovakia s.r.o.

Side note:
We are aware of PR #31143, but it was declined as exported utility and it would only work with one date format without localization

Demonstartion of parseDate() function

API:

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

1 possible answer(s) on “feature request – parseDate – localizable date parsing, supporting different date formats into date object