All files / app/assets/javascripts/lib/utils/datetime pikaday_utility.js

100% Statements 13/13
100% Branches 1/1
100% Functions 3/3
100% Lines 12/12

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 291177x             1177x 478x 478x 478x 478x   478x               1177x 227x 227x 227x   227x    
export const pad = (val, len = 2) => `0${val}`.slice(-len);
 
/**
 * Formats dates in Pickaday
 * @param {String} dateString Date in yyyy-mm-dd format
 * @return {Date} UTC format
 */
export const parsePikadayDate = (dateString) => {
  const parts = dateString.split('-');
  const year = parseInt(parts[0], 10);
  const month = parseInt(parts[1] - 1, 10);
  const day = parseInt(parts[2], 10);
 
  return new Date(year, month, day);
};
 
/**
 * Used `onSelect` method in pickaday
 * @param {Date} date UTC format
 * @return {String} Date formatted in yyyy-mm-dd
 */
export const pikadayToString = (date) => {
  const day = pad(date.getDate());
  const month = pad(date.getMonth() + 1);
  const year = date.getFullYear();
 
  return `${year}-${month}-${day}`;
};