2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
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);
|
2017-09-10 17:25:29 +05:30
|
|
|
};
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
/**
|
|
|
|
* Used `onSelect` method in pickaday
|
|
|
|
* @param {Date} date UTC format
|
|
|
|
* @return {String} Date formated 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}`;
|
|
|
|
};
|