[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:
Kritagya Jaiswal
2023-10-06 01:30:46 +05:30
committed by GitHub
parent ecbee581a7
commit ea65756660
7 changed files with 64 additions and 39 deletions

View File

@@ -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));
}

View File

@@ -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'