All files / src/qComponents/helpers dateHelpers.js

12.5% Statements 2/16
0% Branches 0/18
0% Functions 0/3
12.5% Lines 2/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31    23x       23x                                                
import { isDate } from 'date-fns';
 
const addZero = value => {
  return String(value).padStart(2, '0');
};
 
const isTimeValueValid = value => {
  let isValid = false;
  if (typeof value === 'string') {
    const array = value.split(':');
    isValid =
      array.every((datePart, index) => {
        let condition = false;
        if (index === 0) {
          // hours
          condition = Number(datePart) >= 0 && Number(datePart) < 24;
        } else if ([1, 2].includes(index)) {
          // minutes / seconds
          condition = Number(datePart) >= 0 && Number(datePart) < 60;
        }
        return condition && datePart.length === 2;
      }) && array.length === 3;
  } else if (isDate(value) || value === null) {
    isValid = true;
  }
 
  return isValid;
};
 
export { addZero, isTimeValueValid };