Skip to content

Commit 773ca81

Browse files
author
Jegors Cemisovs
committed
Add hints for the Meetup exercise
Provide guidance on Java's `java.time` API, including `YearMonth` and `TemporalAdjusters`, to help users solve date calculation tasks effectively. Emphasize idiomatic usage of modern date manipulation tools.
1 parent df966c3 commit 773ca81

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Hints
2+
3+
## General
4+
5+
Java's modern Date and Time API (`java.time` package, since Java 8) is particularly well-suited for this kind of date calculation exercise.
6+
7+
## Managing Month and Year Context
8+
9+
Your constructor receives the `month` and `year`. While you can use these directly, the `java.time` package offers a convenient class for handling this context:
10+
11+
- [`YearMonth`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/YearMonth.html): Represents a specific month in a specific year. It's useful because it inherently knows the number of days in that particular month, automatically handling leap years. This can simplify boundary checks.
12+
13+
## Calculating Specific Dates: `TemporalAdjusters`
14+
15+
The core of this exercise involves finding specific dates based on rules (FIRST, SECOND, TEENTH, LAST, etc.). Instead of manually iterating through days and counting, the `java.time` API provides a powerful utility class designed for exactly these kinds of common date adjustments:
16+
17+
- [`java.time.temporal.TemporalAdjusters`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/temporal/TemporalAdjusters.html) (note the plural 's').
18+
19+
This class is key to solving the exercise idiomatically. Explore its `static` methods. You'll find pre-built adjusters for finding:
20+
21+
- The first or last occurrence of a specific `DayOfWeek` within a month (e.g., `firstInMonth()`, `lastInMonth()`).
22+
- The Nth occurrence of a specific `DayOfWeek` within a month (e.g., `dayOfWeekInMonth()`).
23+
- The next occurrence of a specific `DayOfWeek` from a given date (e.g., `nextOrSame()`, which is helpful for the `TEENTH` case).
24+
25+
## Applying Adjustments
26+
27+
- A `TemporalAdjuster` (obtained from a static method in `TemporalAdjusters`) is typically used with the `.with(TemporalAdjuster)` method on a `LocalDate` instance. This method returns a *new* `LocalDate` reflecting the adjustment.

0 commit comments

Comments
 (0)