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));
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ export class UploadActions {
|
||||
this.nodesApi = new NodesApi(apiService.getInstance());
|
||||
}
|
||||
|
||||
async uploadFile(fileLocation, fileName, parentFolderId): Promise<any> {
|
||||
async uploadFile(fileLocation: fs.PathLike, fileName: string, parentFolderId: string): Promise<NodeEntry> {
|
||||
const file = fs.createReadStream(fileLocation);
|
||||
|
||||
return this.uploadApi.uploadFile(
|
||||
@@ -50,7 +50,7 @@ export class UploadActions {
|
||||
);
|
||||
}
|
||||
|
||||
async createEmptyFiles(emptyFileNames: string[], parentFolderId): Promise<NodeEntry> {
|
||||
async createEmptyFiles(emptyFileNames: string[], parentFolderId: string): Promise<NodeEntry> {
|
||||
const filesRequest = [];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
||||
@@ -64,7 +64,7 @@ export class UploadActions {
|
||||
return this.nodesApi.createNode(parentFolderId, filesRequest as any, {});
|
||||
}
|
||||
|
||||
async createFolder(folderName, parentFolderId): Promise<NodeEntry> {
|
||||
async createFolder(folderName: string, parentFolderId: string): Promise<NodeEntry> {
|
||||
return this.nodesApi.createNode(parentFolderId, {
|
||||
name: folderName,
|
||||
nodeType: 'cm:folder'
|
||||
|
Reference in New Issue
Block a user