aa-daily-reflections
Version:
A lightweight Node.js library to fetch Daily Reflections from Alcoholics Anonymous (AA)
28 lines (27 loc) • 844 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateDate = validateDate;
exports.padNumber = padNumber;
exports.getCurrentDate = getCurrentDate;
function validateDate(month, day) {
if (month < 1 || month > 12) {
throw new Error('Month must be between 1 and 12');
}
if (day < 1 || day > 31) {
throw new Error('Day must be between 1 and 31');
}
const daysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (day > daysInMonth[month - 1]) {
throw new Error(`Day ${day} is not valid for month ${month}`);
}
}
function padNumber(num, length = 2) {
return num.toString().padStart(length, '0');
}
function getCurrentDate() {
const today = new Date();
return {
month: today.getMonth() + 1,
day: today.getDate()
};
}