Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: negative activities possible
Browse files Browse the repository at this point in the history
  • Loading branch information
MitanOmar committed Mar 28, 2023
1 parent 6bb90d0 commit f6392ad
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/validators/moment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { get } from "@ember/object";
import moment from "moment";

function getDateTimeIfValid(momentObject) {
if (momentObject && momentObject._isValid) {
return momentObject;
}
return undefined;
}

/**
* Validator to determine if a value is a valid moment object and if it is
* greater or smaller than another property of the content.
Expand All @@ -24,15 +31,19 @@ export default function validateMoment(options = { gt: null, lt: null }) {

if (options.gt) {
const gtVal =
get(changes, options.gt) || get(content, options.gt) || moment();
getDateTimeIfValid(get(changes, options.gt)) ||
getDateTimeIfValid(get(content, options.gt)) ||
moment();

if (newValue <= gtVal) {
valid = false;
}
}
if (options.lt) {
const ltVal =
get(changes, options.lt) || get(content, options.lt) || moment();
getDateTimeIfValid(get(changes, options.lt)) ||
getDateTimeIfValid(get(content, options.lt)) ||
moment();

if (newValue >= ltVal) {
valid = false;
Expand Down

0 comments on commit f6392ad

Please sign in to comment.