[ACS-5877][APPS-2159][APPS-2163][APPS-2160][APPS-2164] Migration from moment.js to date-fns

This commit is contained in:
Aayush Rohila
2023-09-29 12:22:00 +05:30
parent be03a7c345
commit 2a2c9e0233
4 changed files with 21 additions and 8 deletions
@@ -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;