You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: datetime.md
+87Lines changed: 87 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -254,6 +254,93 @@ dates.stream()
254
254
255
255
---
256
256
257
+
## 🃏 Daylight Saving Time "Fall Back" Calculations
258
+
259
+
**Rule:** When DST ends ("fall back"), the **same local time occurs twice**, creating a 25-hour day where time calculations must account for the repeated hour.
260
+
261
+
**Timeline Visualization for November 5, 2023 DST End in America/Chicago:**
262
+
263
+
```
264
+
Regular Timeline: DST "Fall Back" Timeline:
265
+
12:00 AM ──────────────► 12:00 AM ──────────────►
266
+
01:00 AM ──────────────► 01:00 AM ──────────────►
267
+
02:00 AM ──────────────► 02:00 AM (first occurrence) ──┐
268
+
03:00 AM ──────────────► │ Clock jumps back
269
+
04:00 AM ──────────────► 01:00 AM (after fall back) ──┘
270
+
02:00 AM (second occurrence) ──►
271
+
03:00 AM ──────────────►
272
+
```
273
+
274
+
**The Problem:** When calculating time between 3:00 AM and 1:00 AM on DST end day:
275
+
276
+
```java
277
+
importjava.time.*;
278
+
importjava.time.temporal.ChronoUnit;
279
+
280
+
// DST ends November 5, 2023 at 2:00 AM in America/Chicago
281
+
// Clock "falls back" from 2:00 AM to 1:00 AM
282
+
283
+
LocalDateTime morning =LocalDateTime.of(2023, Month.NOVEMBER, 5, 3, 0); // 3:00 AM
long minutesDiff =ChronoUnit.MINUTES.between(berlinBreakfast, berlinMidnight);
318
+
System.out.println("Minutes from 4:30 AM to 2:15 AM: "+ minutesDiff); // -195
319
+
320
+
// Breakdown: 4:30 AM → 2:15 AM = -2 hours 15 minutes = -135 minutes
321
+
// But DST adds an extra hour, so -135 - 60 = -195 minutes
322
+
```
323
+
324
+
**Visual Timeline for the Calculation:**
325
+
```
326
+
DST End Day (25-hour day):
327
+
├─ 12:00 AM
328
+
├─ 01:00 AM
329
+
├─ 02:00 AM (first time) ──┐
330
+
├─ 02:00 AM (repeated) ──┘ ← Extra hour here!
331
+
├─ 02:15 AM (our target) ────────┐
332
+
├─ 03:00 AM │
333
+
├─ 04:00 AM │ 195 minutes difference
334
+
└─ 04:30 AM (our start) ────────┘
335
+
```
336
+
337
+
**💡 Learning Tip:** Remember "FALL BACK = EXTRA HOUR" - When DST ends, one hour is repeated (1:00-2:00 AM happens twice), making time calculations longer than expected.
338
+
339
+
**Q:** On DST end day, if you calculate hours between 4:00 AM and 2:00 AM, why might the result be -3 instead of -2?
340
+
**A:** Because the 2:00 AM hour occurs twice on DST end day. Going from 4:00 AM to 2:00 AM crosses the repeated hour, requiring an extra hour: 4→3→2(first)→2(repeated) = 3 hours backward = -3.
341
+
342
+
---
343
+
257
344
## 🃏 Localization - Locale and Resource Bundles
258
345
259
346
**Rule:** Localization uses **Locale** for region/language and **ResourceBundle** for externalized text.
0 commit comments