The splitDate function takes a JavaScript Date object and returns a structured representation containing day, month, and year in both single and two-digit formats. It first verifies if the input is a valid date using dateLogic.isInstanceOfDate(dateObj), ensuring robustness. This approach simplifies date handling in applications, making it easier to work with formatted date values.
/**
* @description Take the Date Object and return it as {DD:value, MM:value, YYYY:value}
* @param {void|object} dateObj || date object
* @return{void|object} date formated object
*/
splitDate: function splitDate(dateObj) {
if (!dateLogic.isInstanceOfDate(dateObj))
return false;
return {
D: dateObj.getDate(),
DD: dateLogic.formatNumberToTwoDigit(dateObj.getDate()),
M: dateObj.getMonth() + 1,
MM: dateLogic.formatNumberToTwoDigit(dateObj.getMonth() + 1),
YYYY: dateObj.getFullYear()
};
},
/**
* @description check whether the given dateObj is instance of Date Object
* @param {void|objecy} dateObj || date object
* @return !(!checkForParameter(dateObj) || '[object Date]' !== Object.prototype.toString.call(dateObj))
*/
isInstanceOfDate: function isInstanceOfDate(dateObj) {
return checkForParameter(dateObj) && '[object Date]' === Object.prototype.toString.call(dateObj)
},