Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validators: fix greaterThan validator #323

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions projects/rero/ng-core/src/lib/validator/time.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ import moment from 'moment';

// @dynamic
export class TimeValidator {

/**
* Allow to control if time interval limits are well formed : the end limit should be 'older' the start limit
* @param start: the field name where to find the start limit value
* @param end: the field name where to find the end limit value
*/
static greaterThanValidator(start: string, end: string): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } => {
if (control) {
let isLessThan = false;
const startTime = control.get('start_time');
const endTime = control.get('end_time');
const startTime = control.get(start);
const endTime = control.get(end);
const startDate = moment(startTime.value, 'HH:mm');
const endDate = moment(endTime.value, 'HH:mm');
if (startDate.format('HH:mm') !== '00:00' || endDate.format('HH:mm') !== '00:00') {
Expand Down