mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[APPS-2157][APPS-2158][APPS-2161][APPS-2162][APPS-2165] Migration from moment to date-fns (#8965)
* [APPS-2157][APPS-2158][APPS-2161][APPS-2162][2165] Migration from moment to date-fns * Modified endDate to CompletedDate * Addressed review comments * Revert import for dataFnsUtil * Replace fit to it * fix types and avoid double date conversion * fix lint issue * support iso strings for date formatting --------- Co-authored-by: Denys Vuika <denys.vuika@gmail.com>
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { format, parse } from 'date-fns';
|
||||
import { format, parse, parseISO } from 'date-fns';
|
||||
import { ar, cs, da, de, enUS, es, fi, fr, it, ja, nb, nl, pl, ptBR, ru, sv, zhCN } from 'date-fns/locale';
|
||||
|
||||
export class DateFnsUtils {
|
||||
@@ -86,7 +86,8 @@ export class DateFnsUtils {
|
||||
static momentToDateFnsMap = {
|
||||
D: 'd',
|
||||
Y: 'y',
|
||||
A: 'a'
|
||||
A: 'a',
|
||||
ll: 'PP'
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -95,7 +96,8 @@ export class DateFnsUtils {
|
||||
static dateFnsToMomentMap = {
|
||||
d: 'D',
|
||||
y: 'Y',
|
||||
a: 'A'
|
||||
a: 'A',
|
||||
PP: 'll'
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -137,7 +139,10 @@ export class DateFnsUtils {
|
||||
* @param dateFormat - The date format string to use for formatting.
|
||||
* @returns The formatted date as a string.
|
||||
*/
|
||||
static formatDate(date: number | Date, dateFormat: string): string {
|
||||
static formatDate(date: number | Date | string, dateFormat: string): string {
|
||||
if (typeof date === 'string') {
|
||||
date = parseISO(date);
|
||||
}
|
||||
return format(date, this.convertMomentToDateFnsFormat(dateFormat));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user