Power Nap Duration Calculator

Calculate the perfect time to wake up from your nap to feel refreshed and energized. Based on sleep cycles, a 15-20 minute nap boosts alertness, while a 90-minute nap completes a full cycle, improving memory and creativity.

I plan to fall asleep at...

Select the time you want to start your nap, and we'll tell you the best times to set your alarm.

Start napping at this time for a 90-min cycle.

Desired Wake-Up Time: ${formatTime(wakeUpTime)}

Power Nap (20 min) Start Time: ${formatTime(shortNapStartTime)}

Full Cycle (90 min) Start Time: ${formatTime(longNapStartTime)}

`; startTimeResultsContainer.innerHTML = resultsHTML; startTimeResultsContainer.classList.remove('hidden'); // Add event listener to the newly created PDF button document.getElementById('download-pdf-start-time').addEventListener('click', () => generatePdf('start-time')); }; // --- PDF GENERATION --- /** * Generates a PDF from the calculated results. * @param {string} type - 'wake-up' or 'start-time' to determine which data to use. */ const generatePdf = (type) => { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Set document properties and styles doc.setFont('helvetica', 'bold'); doc.setFontSize(20); doc.setTextColor('#1f2937'); // text-gray-800 doc.text('Power Nap Schedule', 105, 20, null, null, 'center'); doc.setFont('helvetica', 'normal'); doc.setFontSize(12); doc.setTextColor('#4b5563'); // text-gray-600 doc.text(`Report generated on: ${new Date().toLocaleDateString()}`, 105, 28, null, null, 'center'); let pdfDataElement; let summaryTitle; let inputTime, shortNap, longNap; if (type === 'wake-up') { pdfDataElement = document.getElementById('pdf-data-wake-up'); summaryTitle = 'Wake-Up Time Calculation'; const startTime = getDateFromTimeString(napStartTimeInput.value); inputTime = `Nap Start Time: ${formatTime(startTime)}`; shortNap = `Power Nap (20 min) Wake-Up: ${formatTime(new Date(startTime.getTime() + 20 * 60000))}`; longNap = `Full Cycle (90 min) Wake-Up: ${formatTime(new Date(startTime.getTime() + 90 * 60000))}`; } else { pdfDataElement = document.getElementById('pdf-data-start-time'); summaryTitle = 'Nap Start Time Calculation'; const wakeTime = getDateFromTimeString(desiredWakeUpTimeInput.value); inputTime = `Desired Wake-Up Time: ${formatTime(wakeTime)}`; shortNap = `Power Nap (20 min) Start Time: ${formatTime(new Date(wakeTime.getTime() - 20 * 60000))}`; longNap = `Full Cycle (90 min) Start Time: ${formatTime(new Date(wakeTime.getTime() - 90 * 60000))}`; } if (!pdfDataElement) { console.error('PDF data element not found.'); return; } // Add content to PDF doc.setLineWidth(0.5); doc.line(20, 35, 190, 35); // horizontal line doc.setFontSize(16); doc.setFont('helvetica', 'bold'); doc.setTextColor('#374151'); // text-gray-700 doc.text(summaryTitle, 20, 45); doc.setFontSize(12); doc.setFont('helvetica', 'normal'); doc.setTextColor('#111827'); // text-gray-900 doc.text(inputTime, 20, 55); doc.setFont('helvetica', 'bold'); doc.text('Recommended Times:', 20, 65); doc.setFont('helvetica', 'normal'); doc.text(`• ${shortNap}`, 25, 75); doc.text(`• ${longNap}`, 25, 85); doc.save('Power-Nap-Schedule.pdf'); }; // --- EVENT LISTENERS --- calculateWakeUpBtn.addEventListener('click', handleCalculateWakeUp); calculateStartTimeBtn.addEventListener('click', handleCalculateStartTime); // Set default time values for inputs for better UX const now = new Date(); const currentTimeString = now.toTimeString().substring(0, 5); napStartTimeInput.value = currentTimeString; desiredWakeUpTimeInput.value = currentTimeString; });
Scroll to Top