Skip to content

Commit 874839d

Browse files
author
Jegors Cemisovs
committed
Add documentation for the Meetup concept exercise
Introduce `introduction.md.tpl` and `hints.md` for the Meetup exercise to guide learners. The hints provide detailed steps on working with `LocalDate` and `TemporalAdjusters` for date manipulations.
1 parent e533bf9 commit 874839d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Hints
2+
3+
## 1. Representing the Date
4+
5+
- The core class for representing dates without time in Java is [`java.time.LocalDate`][localdate-docs].
6+
- You'll need to work with the `year` and `month` provided in the constructor.
7+
- The target day of the week is conveniently provided directly as a [`java.time.DayOfWeek`][dayofweek-docs] enum instance in the `day()` method.
8+
9+
## 2. Starting Point for Adjustments
10+
11+
- `LocalDate` objects are immutable. To find the target meetup date, you typically start with *any* date within the target `month` and `year` and then apply an "adjuster" to find the correct day.
12+
- For example, you could create a `LocalDate` for the 1st of the month: `LocalDate.of(year, month, 1)`.
13+
- For "Teenth" calculations, starting from the 13th of the month (`LocalDate.of(year, month, 13)`) can be helpful.
14+
15+
## 3. Adjusting Dates with `TemporalAdjusters`
16+
17+
- The key to solving this idiomatically is the [`java.time.temporal.TemporalAdjusters`][temporaladjusters-docs] utility class (note the plural 's'). It provides static methods that return [`TemporalAdjuster`][temporaladjuster-docs] instances for common date calculations.
18+
- You apply an adjuster to a `LocalDate` using its `.with()` method: `someLocalDate.with(TemporalAdjusters.someAdjuster(...))`
19+
- This returns a *new* `LocalDate` instance with the adjustment applied.
20+
21+
## 4. Handling "Ordinal" Schedules (FIRST, SECOND, THIRD, FOURTH)
22+
23+
- Look for a method in `TemporalAdjusters` that allows you to find a date based on its ordinal position (1st, 2nd, 3rd, 4th) and its `DayOfWeek` within the month.
24+
- You might need to convert the `MeetupSchedule` enum values (`FIRST`, `SECOND`, etc.) into the corresponding integer ordinals (1, 2, 3, 4) to use this adjuster.
25+
26+
## 5. Handling the "LAST" Schedule
27+
28+
- `TemporalAdjusters` provides a specific adjuster to find the *last* occurrence of a given `DayOfWeek` within the month.
29+
30+
## 6. Handling the "TEENTH" Schedule
31+
32+
- "Teenth" days run from the 13th to the 19th of the month.
33+
- Consider starting from the 13th day of the month (`LocalDate.of(year, month, 13)`).
34+
- Look for an adjuster in `TemporalAdjusters` that finds the *next* occurrence of the target `DayOfWeek`, potentially *including* the date you're adjusting if it already matches the target day of the week.
35+
36+
## 7. Selecting the Right Adjuster
37+
38+
- Use the input `schedule` (which is a `MeetupSchedule` enum value) to determine which specific `TemporalAdjuster` method to use. A `switch` statement or `if-else if` chain on the `schedule` value is a common approach.
39+
40+
[localdate-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html
41+
[dayofweek-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html
42+
[temporaladjuster-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/temporal/TemporalAdjuster.html
43+
[temporaladjusters-docs]: https://docs.oracle.com/javase/8/docs/api/java/time/temporal/TemporalAdjusters.html
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Introduction
2+
3+
%{concept:strings}

0 commit comments

Comments
 (0)