Time Calculations Suite: Quick Framework
1. Modules
- Duration: end − start → normalize (d,h,m,s).
- Add/Subtract: sequential Date mutations.
- Date Info: derive ordinal day, week, quarter, leap.
- Timezone: convert via UTC pivot.
2. Selection Flow
- Define task (interval / shift / schedule / conversion).
- Gather minimal inputs (avoid redundant manual fields).
- Compute with canonical base (ms or seconds).
- Format outputs (human + decimal hours if relevant).
3. Sanity & Validation
- End >= start else warn.
- Leap year: divisible by 4 & (not 100 unless 400).
- Timezone offsets applied exactly once.
4. Shortcuts
- For comparisons use raw ms (skip formatting).
- Batch add offsets before constructing Date objects.
- Cache repeated Δx results for multi-field displays.
5. Pitfalls
- Manual month length assumptions.
- Double-adjusting DST transitions.
- Mixing local vs UTC when comparing times.
6. Micro Examples
2025-01-01 12:00 to 2025-01-03 15:30 → 2d 3h 30m
Add 1y 2m 10d to 2024-02-20 → 2025-04-30
NY 09:00 EST → IST = 19:30
7. Mini FAQ
- Why decimals? Payroll & SLA metrics.
- Large span accuracy? Use milliseconds; keep integer math.
- Milliseconds rounding? Only when displaying.
8. Action Tip
Keep one canonical base (ms). Derive every panel/summary from it to eliminate drift.