Level 1 / Project 07 - Date Difference Helper¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | — | Browser |
Estimated time: 30 minutes
Focus¶
- basic datetime parsing and deltas
Why this project exists¶
Compute differences between dates, add days to a date, and find the day of the week. You will learn the datetime module, strptime/strftime for parsing and formatting, and timedelta for date arithmetic.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-1/07-date-difference-helper
python project.py --input data/sample_input.txt
pytest -q
Expected terminal output¶
=== Date Helper ===
diff 2024-01-01 2024-12-31 => 365 days
diff 2024-06-15 2024-07-04 => 19 days
add 2024-01-01 90 => 2024-03-31
Output written to data/output.json
6 passed
Expected artifacts¶
data/output.json- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
weekscommand that returns the number of weeks and remaining days between two dates. - Add support for alternate date formats like
DD/MM/YYYYusing a--formatflag. - Re-run script and tests.
Break it (required) — Core¶
- Add a line with an invalid date like
diff 2024-02-30 2024-03-01(Feb 30 does not exist) -- doesparse_date()crash? - Add a
diffcommand with dates in reversed order -- doesdays_between()return a negative number? - Add a command with a misspelled action like
dif 2024-01-01 2024-01-10-- what happens?
Fix it (required) — Core¶
- Wrap
parse_date()in a try/except to handle invalid dates with a clear error message. - Ensure
days_between()always returns a non-negative value usingabs(). - Add a test for the reversed-dates case.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- What does
datetime.strptime("2024-01-15", "%Y-%m-%d")do and what does each%code mean? - Why does
timedelta(days=N)exist and how is it different from just adding an integer to a date? - What does
.strftime("%A")return and why is day-of-week useful? - Where would date calculations appear in real software (billing cycles, SLA tracking, scheduling)?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|