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