Repository navigation
Conversation
Introduces the `durations-and-periods` concept, which covers the date-based `Period`, the time-based `Duration` and counting units with `ChronoUnit.between()`, including common pitfalls such as `Period.getDays()` not being a total and month-end clamping. The new `gym-front-desk` concept exercise teaches it through a climbing gym front desk: membership end dates and lengths (`Period`), days left on a membership (`ChronoUnit.DAYS`) and the length of a visit printed on a receipt (`Duration`, `toHours()` vs `toMinutesPart()`). Also adds the concept to the `practices` and `prerequisites` of the `gigasecond` practice exercise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pull request
Description
This PR adds a new concept,
durations-and-periods, and a concept exercise that teaches it,gym-front-desk.The idea was discussed and approved on the forum: Add a concept for Duration and Period.
Motivation
The
datetimeconcept covers points in time (LocalDate,LocalDateTime) but not amounts of time, andbeauty-salon-regularsexplicitly leavesDurationandPeriodout of scope.Students who do date arithmetic in practice exercises either do it by hand or run into the usual pitfalls, the most common being
Period.between(a, b).getDays()used as a total number of days.Concept:
durations-and-periodsintroduction.md:Period(factory methods,plus(), month-end clamping,Period.between()and its parts), counting units withChronoUnit.X.between(), andDuration(factory methods,Duration.between(),toXxx()vstoXxxPart()).about.md: adds ISO-8601 parsing,until(),toTotalMonths(),normalized()and unit-by-unitequals(),UnsupportedTemporalTypeExceptionwhen mixing dates and durations, comparing and arithmetic with durations, and a short aside on whyPeriod.ofDays(1)andDuration.ofDays(1)differ across a DST change.jshell.Exercise:
gym-front-deskA climbing gym front desk, with five tasks:
membershipEnd(): add aPeriodof months to a start date (tests include month-end clamping and leap years).membershipLength():Period.between().daysLeft(): total days withChronoUnit.DAYS.between()(a test spans several months, soPeriod.getDays()fails it).visitDuration():Duration.between()for a visit, including one past midnight.formatVisit():"1h 35m"on a receipt, usingtoHours()andtoMinutesPart()(a test with a visit over 24 hours catchestoHoursPart()).Prerequisites:
datetime,strings.design.mdlists suggested analyzer rules.Config changes
config.json(UUIDs16500ebe-104e-44c3-84b3-3126a49bdb89and6553f255-154f-441d-a6e1-a428434f9653) and the exercise toexercises/settings.gradle.durations-and-periodsto thepracticesandprerequisitesofgigasecond, which adds a gigasecond to a date-time.Happy to drop it from
prerequisitesif you'd rather not lock the exercise behind the new concept.Checks run locally
./gradlew test,checkandcompileStarterTestJavafor the exercise (JDK 25): 23 tests pass, no Checkstyle issues.configlet lintandconfiglet generate(the exercise'sintroduction.mdis generated from the concept).markdownlint-cli2on the new Markdown files.The
i18n / completenesscheck will need theready-to-translatelabel to queue the new English for translation.Reviewer Resources:
Track Policies
🤖 Generated with Claude Code