Spring Boot 4 / Java 17 / Postgres. Masters and serving (A), Agmarknet and climate ingestion (B), feature store with 14 derivations (C), SpEL rule engine and risk scoring (D). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
31 lines
915 B
Java
31 lines
915 B
Java
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());
|
||
}
|
||
}
|