UNPKG

@web3r/flowerkit

Version:

A collection of more than 60 often used utility JS functions that simplify frontend development.

14 lines (13 loc) 812 B
import{isValidDate}from"../isValidDate/index.js"; /** * Gets a Date instance without time (hours, minutes, seconds and milliseconds) * @param date{*=} * @return {Date|null} * @example * // How to get date without time e.g. hours, minutes, seconds and milliseconds? * const dateWithTime = new Date(); * console.log(dateWithTime.getMilliseconds()); // => {number} * const dateWithoutTime = getPureDate(dateWithTime); * console.log(dateWithoutTime.getMilliseconds()); // => 0 */const getPureDate=(date=new Date)=>{const getWithoutTime=date=>{date.setHours(0,0,0,0);return date};if(isValidDate(date))return getWithoutTime(date);else{const convertedDare=new Date(date);if(isValidDate(convertedDare))return getPureDate(convertedDare);else return null}};export{getPureDate}; //# sourceMappingURL=index.js.map