Gregorian Date to Rata Die Converter

Enter a Gregorian date to calculate its Rata Die number. Rata Die counts the number of days since January 1, 1 A.D.

${rataDie.toLocaleString()}

`; resultContainer.style.display = "block"; // 6. Store for PDF lastResult.dateString = formattedDate; lastResult.rataDie = rataDie; } /** * Generates and triggers a download for a PDF of the result. (Spec II.C) */ function downloadPdf() { // Guard clause if no result has been calculated (Spec IV.B) if (lastResult.rataDie === null) { errorContainer.textContent = "Please calculate a result first before downloading."; errorContainer.style.display = "block"; return; } // Check for jsPDF library if (typeof jspdf === 'undefined') { alert('Error: PDF library could not be loaded. Please refresh the page.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); // PDF Content & Formatting (Spec II.C.2) doc.setFontSize(18); doc.setTextColor('#1e3a5f'); // Consistent color scheme (Spec II.C.3) doc.text("Rata Die Conversion Report", 105, 20, { align: 'center' }); doc.setDrawColor('#007bff'); doc.line(20, 25, 190, 25); doc.setFontSize(12); doc.setTextColor('#333'); doc.text("Input Gregorian Date:", 20, 40); doc.setFontSize(16); doc.setFont('helvetica', 'bold'); doc.text(lastResult.dateString, 20, 50); doc.setFontSize(12); doc.setFont('helvetica', 'normal'); doc.text("Calculated Rata Die Number:", 20, 70); doc.setFontSize(26); doc.setFont('helvetica', 'bold'); doc.setTextColor('#007bff'); doc.text(lastResult.rataDie.toLocaleString(), 20, 82); doc.setDrawColor('#dddddd'); doc.line(20, 95, 190, 95); doc.setFontSize(10); doc.setFont('helvetica', 'normal'); doc.setTextColor('#555'); const explanationText = doc.splitTextToSize( "The Rata Die (Latin for 'root/start date') is a system used to count days for calendrical purposes. Day 1 corresponds to January 1, 1 in the proleptic Gregorian calendar.", 170 ); doc.text(explanationText, 20, 105); // Save the PDF (Spec II.C.4) doc.save("Rata-Die-Conversion.pdf"); } // --- Event Listener Attachment (Spec IV.A, IV.C) --- if (convertBtn) { convertBtn.addEventListener("click", calculateAndDisplayRataDie); } else { console.error("Converter: Convert button not found."); } if (pdfBtn) { pdfBtn.addEventListener("click", downloadPdf); } else { console.error("Converter: PDF button not found."); } });
Scroll to Top