mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-5877][APPS-2159][APPS-2163][APPS-2160][APPS-2164] Migration from moment.js to date-fns
This commit is contained in:
@@ -26,7 +26,8 @@ import { NavigationBarPage } from '../../core/pages/navigation-bar.page';
|
||||
import { TasksCloudDemoPage } from './../pages/tasks-cloud-demo.page';
|
||||
import { TaskListCloudConfiguration } from './../config/task-list-cloud.config';
|
||||
import { taskFilterConfiguration } from './../config/task-filter.config';
|
||||
import { addDays, format, subDays } from 'date-fns';
|
||||
import { addDays, subDays } from 'date-fns';
|
||||
import { DateFnsUtils } from '@alfresco/adf-core';
|
||||
|
||||
describe('Edit task filters and task list properties', () => {
|
||||
|
||||
@@ -54,9 +55,9 @@ describe('Edit task filters and task list properties', () => {
|
||||
let otherOwnerTask; let testUser; let groupInfo; let simpleTask;
|
||||
const priority = 1;
|
||||
|
||||
const beforeDate = format(subDays(new Date(), 1), 'dd/MM/yyyy');
|
||||
const beforeDate = DateFnsUtils.formatDate(subDays(new Date(), 1), 'DD/MM/YYYY');
|
||||
const currentDate = DateUtil.formatDate('DD/MM/YYYY');
|
||||
const afterDate = format(addDays(new Date(), 1), 'dd/MM/yyyy');
|
||||
const afterDate = DateFnsUtils.formatDate(addDays(new Date(), 1), 'DD/MM/YYYY');
|
||||
|
||||
beforeAll(async () => {
|
||||
await apiService.loginWithProfile('identityAdmin');
|
||||
|
||||
@@ -29,6 +29,7 @@ import { TaskListDemoPage } from './../pages/task-list-demo.page';
|
||||
import { NavigationBarPage } from '../../core/pages/navigation-bar.page';
|
||||
import { TaskActionsApi, TaskRepresentation, TasksApi } from '@alfresco/js-api';
|
||||
import { addDays, format, subDays } from 'date-fns';
|
||||
import { DateFnsUtils } from '@alfresco/adf-core';
|
||||
|
||||
describe('Start Task - Custom App', () => {
|
||||
|
||||
@@ -63,9 +64,9 @@ describe('Start Task - Custom App', () => {
|
||||
let currentPage = 1;
|
||||
const totalNrOfPages = 'of 4';
|
||||
const currentDateStandardFormat = DateUtil.formatDate('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
||||
const beforeDate = format(subDays(new Date(), 1), 'MM/dd/yyyy');
|
||||
const beforeDate = DateFnsUtils.formatDate(subDays(new Date(), 1), 'MM/DD/YYYY');
|
||||
const currentDate = DateUtil.formatDate('MM/DD/YYYY');
|
||||
const afterDate = format(addDays(new Date(), 1), 'MM/dd/yyyy');
|
||||
const afterDate = DateFnsUtils.formatDate(addDays(new Date(), 1), 'MM/DD/YYYY');
|
||||
let taskWithDueDate;
|
||||
let processDefinitionId;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { format, parse } from 'date-fns';
|
||||
import { format, isMatch, parse } 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 {
|
||||
@@ -153,4 +153,15 @@ export class DateFnsUtils {
|
||||
static parseDate(value: string, dateFormat: string): Date {
|
||||
return parse(value, this.convertMomentToDateFnsFormat(dateFormat), new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a date string using the specified date format.
|
||||
*
|
||||
* @param value - Date string to be matched.
|
||||
* @param dateFormat - The date format string to use for matching.
|
||||
* @returns true if given date string correct against the given format else will return false.
|
||||
*/
|
||||
static isMatch(value: string, dateFormat: string): boolean {
|
||||
return isMatch(value, this.convertMomentToDateFnsFormat(dateFormat));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
import { LogService } from '../../common/services/log.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import moment from 'moment';
|
||||
import { FormFieldModel, FormModel, TabModel, ContainerModel, FormOutcomeModel } from '../components/widgets/core';
|
||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||
import { WidgetVisibilityModel, WidgetTypeEnum } from '../models/widget-visibility.model';
|
||||
import { DateFnsUtils } from '../../../..';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -128,7 +128,7 @@ export class WidgetVisibilityService {
|
||||
} else if (visibilityObj.rightType === WidgetTypeEnum.field) {
|
||||
valueFound = this.getFormValue(form, visibilityObj.rightValue);
|
||||
} else {
|
||||
if (moment(visibilityObj.rightValue, 'YYYY-MM-DD', true).isValid()) {
|
||||
if (DateFnsUtils.isMatch(visibilityObj.rightValue, 'YYYY-MM-DD')) {
|
||||
valueFound = visibilityObj.rightValue + 'T00:00:00.000Z';
|
||||
} else {
|
||||
valueFound = visibilityObj.rightValue;
|
||||
|
||||
Reference in New Issue
Block a user