Dates, UTC and time zones
All dates are fixed, so the output never changes. Look at the daylight-saving line: one calendar day later is only 23 real hours later.
Automation scripts do boring work reliably: they rename and move files with pathlib, handle dates and time zones correctly with datetime and zoneinfo, and run other programs with subprocess.run using a list of arguments, a timeout and a return-code check, never a shell built from user input.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write archive_name(filename) that returns the lower-case name with spaces replaced by underscores, keeping the extension.
Write to_utc_string(text) that takes an ISO time with an offset such as 2026-10-10T08:15:00+05:30 and returns it in UTC in the same format.
Write (non-runnable) a function git_branch() that returns the current git branch using subprocess.run with a list, check=True and a timeout.
Explain it without notes
How do you make a file-renaming script safe?
What is the difference between naive and aware datetimes, and which should you store?
Why is subprocess.run(command_string, shell=True) dangerous with untrusted input, and what is the safe alternative?
What do check=True and timeout= do in subprocess.run?
Expected output
UTC: 2026-03-29T09:30:00+00:00
Asia/Kolkata 2026-03-29T15:00:00+05:30
Europe/London 2026-03-29T10:30:00+01:00
America/New_York 2026-03-29T05:30:00-04:00
London 2026-03-28T12:00:00+00:00 -> 2026-03-29T12:00:00+01:00
real hours between: 23.0
10 Oct 2026, 02:45 UTC
next run: 2026-10-11T02:00:00+00:00 in 17:45:00