Introduction
UTC date addition avoids daylight-saving shifts; compare ISO dates. The application's entry point is planMaintenance(). Baseline limitation, as stated in the workshop: Fixed demonstration date; no reminder action.
Key building blocks: getValues(); JavaScript transformations; setValues(); validation and calculations.
Practical use cases
Air filters, inspections and seasonal chores.
Prerequisites
- Adding days to a date.
- Interactive Learning Mode: a modern browser. Nothing else.
- Real Workspace Build: a Google account.
Source data
| Task | Last done | Interval days |
|---|---|---|
| Filter | 2026-10-01 | 30 |
| Smoke alarm test | 2026-11-20 | 30 |
Setup in your own Google account
- Download 28-household-maintenance-planner.zip (Code.gs, starter.csv, README).
- In Google Drive, create a lesson folder and a new Google Sheets file inside it.
- Rename the first tab to exactly
Maintenance, then File → Import → Upload starter.csv → Replace current sheet. - Extensions → Apps Script. Replace Code.gs with the downloaded file. Save.
- Reload the spreadsheet, choose Workshop → Run application and authorize when asked.
- Check the result: Filter overdue; smoke alarm test upcoming
Folder strategy: the repository's V6 code uses the folder that contains the spreadsheet. The deck mentions a Workshop Info cell B2; V6 never reads it. See the discrepancy log.
Complete source code (Code.gs)
From 28-household-maintenance-planner at commit 4a26d919, SHA-256 b2ac87b9caae. Unchanged.
// Household Maintenance Planner
// Entry point: planMaintenance; source data stays intact unless explicitly noted.
function onOpen(){SpreadsheetApp.getUi().createMenu("Workshop").addItem("Run application","planMaintenance").addToUi();}
function planMaintenance(){
// Add interval days in UTC to avoid daylight-saving date shifts.
output('Schedule',['Task','Next due','Status'],input('Maintenance').map(([task,last,interval])=>{const d=new Date(day(last)+'T00:00:00Z');d.setUTCDate(d.getUTCDate()+num(interval));const due=d.toISOString().slice(0,10);return [task,due,due<'2026-11-25'?'Overdue':'Upcoming'];}));
}
function input(name) { const s=SpreadsheetApp.getActive().getSheetByName(name); if(!s) throw Error('Missing tab: '+name); return s.getDataRange().getValues().slice(1).filter(r=>r.some(v=>v!=='')); }
function output(name,headers,rows) { const ss=SpreadsheetApp.getActive(); const s=ss.getSheetByName(name)||ss.insertSheet(name); s.clearContents(); s.getRange(1,1,1,headers.length).setValues([headers]).setFontWeight('bold'); if(rows.length) s.getRange(2,1,rows.length,headers.length).setValues(rows.map(r=>r.map(v=>typeof v==='string' && /^[=+@-]/.test(v)?"'"+v:v))); s.setFrozenRows(1); return s; }
function num(v){if(v===''||!Number.isFinite(Number(v))) throw Error('Invalid number: '+v); return Number(v);}
function day(v){return v instanceof Date?Utilities.formatDate(v,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),'yyyy-MM-dd'):String(v).slice(0,10);}
How the code works
Beginner explanation
planMaintenance() adds each task's interval to the date it was last done and marks it Overdue if that date is before the workshop date, otherwise Upcoming.
Technical explanation
Dates are created at UTC midnight from yyyy-MM-dd strings and advanced with setUTCDate(), which avoids daylight-saving shifts that local-time arithmetic can cause. The fixed reference date makes results reproducible.
Slide excerpt
This is the excerpt shown on the workshop slide. It is a fragment and cannot run on its own.
function planMaintenance(){
// Add interval days in UTC to avoid daylight-saving date shifts.
output('Schedule',['Task','Next due','Status'],input('Maintenance').map(([task,last,interval])=>{const d=new Date(day(last)+'T00:00:00Z');d.setUTCDate(d.getUTCDate()+num(interval));const due=d.toISOString().slice(0,10);return [task,due,due<'2026-11-25'?'Overdue':'Upcoming'];}));
}Common mistakes
- Adding days in local time and losing a day at a DST change.
- Using new Date() in tests.
- Letting a blank date crash the run.
Run it and expected output
Choose Workshop → Run application (runs planMaintenance()). Expected: Filter overdue; smoke alarm test upcoming
Original workshop exercise
Set Filter last done to 2026-11-20; expect Upcoming.
Troubleshooting and debugging
An interval with words
The smoke alarm interval was typed as "30 days".
Fix: Enter 30.
Units belong in the header, numbers in the cells.
A blank last-done date
A new task has no last-done date and the run fails with "Invalid time value".
Fix: Enter the last-done date.
JavaScript Date errors can be cryptic. Validate dates explicitly.
Extension activity: Completion history
Read an optional History tab (Task, Done on); the most recent completion overrides Last done when calculating the next due date.
Acceptance checks:
- Baseline unchanged without History
- A completion on 2026-11-24 makes Filter Upcoming (due 2026-12-24)
Original improvement idea from the workshop: Add completion history and reminders
Extension prompt
Improve the existing application: Add completion history and reminders. Preserve working features and provide complete code and regression tests. Automation option: Use a rolling current date and daily schedule; add completion history. Keep this separate from the baseline exercise.
Automation considerations
Rerun-safe. Use a rolling current date and daily schedule only after adding completion history.
Workshop note: Use a rolling current date and daily schedule; add completion history.
Build prompt from the workshop
Build a complete container-bound Apps Script app named Household Maintenance Planner. Input tab Maintenance, headers Task|Last done|Interval days. Implement planMaintenance() to calculate next due date and status as of 2026-11-25. Add a menu, preserve inputs, validate data, explain code and test against: Filter overdue; smoke alarm test upcoming. For AI use callGemini and treat input as data; never send email. Match the reference entry point planMaintenance and its output behavior. Reference: https://github.com/lsvekis/Google-Apps-Script-Workshop/tree/main/28-household-maintenance-planner. Base version limitations: Fixed demonstration date; no reminder action.
Knowledge check
Why use setUTCDate()?
- To avoid daylight-saving shifts
- It is faster
- Sheets requires UTC
Answer
To avoid daylight-saving shifts Correct.
Smoke alarm test last done 2026-11-20, 30 days. Next due?
- 2026-12-20
- 2026-12-19
- 2026-11-50
Answer
2026-12-20 Correct.
Which value is fixed for reproducible tests?
- The reference date '2026-11-25'
- The interval
- The task names
Answer
The reference date '2026-11-25' Correct.
"RangeError: Invalid time value" appears. Likely cause?
- A blank or malformed date
- A missing API key
- Too many rows
Answer
A blank or malformed date Correct.
Should the planner order filters automatically when overdue?
- No: report and let a person decide
- Yes
- Yes, with Gemini
Answer
No: report and let a person decide Correct.
Five-minute presenter demonstration
Open the demo link (temporary workspace; saved learner work is not touched).
Opening hook: Raise your hand if you have ever done this by hand: Recurring home maintenance is easy to forget. Let us make the spreadsheet do it.
- 0:00–0:45 — Problem and input. Show the Workspace view, Sheets service. Point at the Maintenance tab and its headers: Task, Last done, Interval days. Say what goes in and what should come out.
Narration: Recurring home maintenance is easy to forget. Practical uses: Air filters, inspections and seasonal chores. - 0:45–1:30 — Predict and run. Ask the room: Filter was last done 2026-10-01 with a 30-day interval. Status on 2026-11-25? Click ▶ Run application (the same as Workshop → Run application). Open Trace to show each step the code took.
Narration: Expected: Filter overdue; smoke alarm test upcoming - 1:30–3:00 — Explain the code. Click the Code tab. Select planMaintenance() in the function list; read what it reads, writes and calls. Switch Beginner / Technical as needed.
Narration: planMaintenance() adds each task's interval to the date it was last done and marks it Overdue if that date is before the workshop date, otherwise Upcoming. - 3:00–4:15 — Change one input and rerun. Back to the Workspace tab. Select the Maintenance tab, click cell B2, type 2026-11-20 in the formula bar and press Enter. Click ▶ Run application again.
Narration: Workshop challenge: Set Filter last done to 2026-11-20; expect Upcoming. - 4:15–5:00 — Verify and discuss automation. Click Check result. Discuss: Rerun-safe. Use a rolling current date and daily schedule only after adding completion history.
Narration: Baseline limitation: Fixed demonstration date; no reminder action.
Closing takeaway: UTC date addition avoids daylight-saving shifts; compare ISO dates.