package com.lincfusion.udyamlinc.ingestion; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.WeekFields; /** * Everything upstream reports daily; everything downstream reads weekly. One * definition of "week" for both signal tables, so a mandi price and a rainfall * figure for the same period actually line up. */ public final class Weeks { private Weeks() {} /** Monday of the ISO week the date falls in. */ public static LocalDate startOf(LocalDate date) { return date.with(DayOfWeek.MONDAY); } /** ISO week number, 1–53. */ public static int isoWeek(LocalDate date) { return date.get(WeekFields.ISO.weekOfWeekBasedYear()); } /** ISO week-based year — not always the calendar year at a year boundary. */ public static int isoYear(LocalDate date) { return date.get(WeekFields.ISO.weekBasedYear()); } }