mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 03:43:28 +10:00
Use year/month/date triple when discussing with Stripe.
This commit is contained in:
parent
63afe46b90
commit
9101e92a9d
2 changed files with 22 additions and 6 deletions
|
|
@ -29,8 +29,8 @@ const pad = num => {
|
|||
};
|
||||
|
||||
const parseNum = str => {
|
||||
const num = parseInt(str, 10);
|
||||
return isNaN(num) ? null : num;
|
||||
const num = Number.parseInt(str, 10);
|
||||
return Number.isNaN(num) ? null : num;
|
||||
};
|
||||
|
||||
// Validate that the given date has the same info as the selected
|
||||
|
|
@ -54,7 +54,7 @@ const dateFromSelected = ({ day, month, year }) => {
|
|||
const yearNum = parseNum(year);
|
||||
if (dayNum !== null && monthNum !== null && yearNum !== null) {
|
||||
const d = new Date(Date.UTC(yearNum, monthNum - 1, dayNum));
|
||||
return isValidDate(d, yearNum, monthNum, dayNum) ? d : null;
|
||||
return isValidDate(d, yearNum, monthNum, dayNum) ? { year, month, day } : null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -114,10 +114,26 @@ export const moneySubUnitAmountAtLeast = (message, minValue) => value => {
|
|||
return value instanceof Money && value.amount >= minValue ? VALID : message;
|
||||
};
|
||||
|
||||
const parseNum = str => {
|
||||
const num = Number.parseInt(str, 10);
|
||||
return Number.isNaN(num) ? null : num;
|
||||
};
|
||||
|
||||
export const ageAtLeast = (message, minYears) => value => {
|
||||
const now = moment();
|
||||
const ageInYears = now.diff(moment(value), 'years', true);
|
||||
return value && value instanceof Date && ageInYears >= minYears ? VALID : message;
|
||||
const { year, month, day } = value;
|
||||
const dayNum = parseNum(day);
|
||||
const monthNum = parseNum(month);
|
||||
const yearNum = parseNum(year);
|
||||
|
||||
// day, month, and year needs to be numbers
|
||||
if (dayNum !== null && monthNum !== null && yearNum !== null) {
|
||||
const now = moment();
|
||||
const age = new Date(yearNum, monthNum - 1, dayNum);
|
||||
const ageInYears = now.diff(moment(age), 'years', true);
|
||||
|
||||
return age && age instanceof Date && ageInYears >= minYears ? VALID : message;
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
export const composeValidators = (...validators) => value =>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue