Work Hours Calendar Sync Tool
Schedule Period
Default Weekly Recurring Hours
Specific Dates (Overrides / Additions / Days Off)
Add specific dates to override weekly schedule. To mark a day off, add the date and leave times empty or uncheck "Working?".
Default Calendar Event Details (for recurring blocks)
Generated Schedule Summary
Define your schedule on the first tab and click "Preview & Proceed to Download".
Total Work Blocks to Generate: ${whcsGeneratedWorkBlocks.length}
`; summaryHTML += `A few upcoming work blocks:
- `;
whcsGeneratedWorkBlocks.slice(0, 5).forEach(block => {
summaryHTML += `
- ${block.date.toLocaleDateString()}: ${block.startTimeStr} - ${block.endTimeStr} (${block.title}) `; }); summaryHTML += `
...and ${whcsGeneratedWorkBlocks.length - 5} more.
`; summaryEl.innerHTML = summaryHTML; document.getElementById('whcs-download-ics-button').disabled = false; document.getElementById('whcs-download-pdf-button').disabled = false; whcsOpenTab(null, 'whcs-download'); } function whcsDownloadICS() { if (whcsGeneratedWorkBlocks.length === 0) { alert("No work blocks to generate. Please define a schedule first."); return; } let icsContent = `BEGIN:VCALENDAR VERSION:2.0 PRODID:-//SmartElementorTool//WorkHoursCalendar//EN CALSCALE:GREGORIAN `; whcsGeneratedWorkBlocks.forEach(block => { const uid = whcsGenerateUID() + "@elementortool.com"; const dtstamp = whcsFormatDateTimeUTC(new Date(), new Date().toTimeString().substring(0,5)); // Current time as DTSTAMP const dtstart = whcsFormatDateTimeUTC(block.date, block.startTimeStr); const dtend = whcsFormatDateTimeUTC(block.date, block.endTimeStr); icsContent += `BEGIN:VEVENT UID:${uid} DTSTAMP:${dtstamp} DTSTART:${dtstart} DTEND:${dtend} SUMMARY:${block.title.replace(/([,;\\])/g, '\\$1')} ${block.description ? `DESCRIPTION:${block.description.replace(/\n/g, '\\n').replace(/([,;\\])/g, '\\$1')}\n` : ''} ${block.location ? `LOCATION:${block.location.replace(/([,;\\])/g, '\\$1')}\n` : ''} STATUS:CONFIRMED TRANSP:OPAQUE END:VEVENT `; }); icsContent += `END:VCALENDAR`; const blob = new Blob([icsContent], { type: 'text/calendar;charset=utf-8' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'WorkHoursSchedule.ics'; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(link.href); } function whcsDownloadPDFSummary() { if (!whcsCollectWorkBlocks() && whcsGeneratedWorkBlocks.length === 0) { // Re-collect if not already done, or ensure preview has run alert("No schedule data to generate PDF. Please define and preview your schedule."); return; } let pdfHTML = `Work Hours Schedule Definition
`; pdfHTML += `Schedule Period: ${document.getElementById('whcs-start-date').value} to ${document.getElementById('whcs-end-date').value}
`; pdfHTML += `Default Weekly Hours
| Day | Working? | Start Time | End Time |
|---|---|---|---|
| ${dayName} | ${isChecked ? 'Yes' : 'No'} | ${isChecked ? start : 'N/A'} | ${isChecked ? end : 'N/A'} |
Specific Date Overrides/Additions (${whcsSpecificDates.length})
| Date | Times | Custom Title |
|---|---|---|
| ${entry.date} | ${times} | ${entry.title || 'N/A'} |
Specific Date Overrides/Additions
None defined.
`; } pdfHTML += `Default Calendar Event Details
`; pdfHTML += `Title: ${document.getElementById('whcs-event-title').value || "Work"}
`; pdfHTML += `Description: ${document.getElementById('whcs-event-desc').value || "N/A"}
`; pdfHTML += `Location: ${document.getElementById('whcs-event-location').value || "N/A"}
`; const pdfContainer = document.getElementById('whcs-report-content-for-pdf'); pdfContainer.innerHTML = pdfHTML; const opt = { margin: [0.5, 0.5, 0.5, 0.5], filename: 'WorkHoursDefinition.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, logging: false }, jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' } }; html2pdf().from(pdfContainer).set(opt).save().then(() => { pdfContainer.innerHTML = ''; }).catch(err => { console.error("Error generating PDF:", err); pdfContainer.innerHTML = ''; alert("An error occurred while generating the PDF summary. Check console for details."); }); }