All files / src/date formatDate.ts

90.91% Statements 10/11
92.86% Branches 13/14
100% Functions 1/1
90% Lines 9/10

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 221x 1x   1x       5x 2x 3x 1x 2x         2x          
import moment from 'moment';
import * as R from 'ramda';
 
export const formatDate = (
  value?: string | number | Date,
  formatStr = 'YY-MM-DD hh:mm:ss',
): string => {
  if (value && String(new Date(value)) !== 'Invalid Date') {
    return moment(value).format(formatStr);
  } else if (R.isNil(value) || R.isEmpty(value)) {
    return moment(new Date()).format(formatStr);
  } else Eif (
    !Number(value) ||
    String(value).length < 13 ||
    String(new Date(value)) === 'Invalid Date'
  ) {
    return 'this argumanet is invalid!';
  }
  // todo
  return ''
};