The expiry should be after 8 working hours (8 am to 5 pm UTC monday to Friday) for example the created date at 7 pm UTC time, the expiring time should be counted from next morning 8 am to 5 pm UTC time and expire. So it should expire at 4 pm UTC .
Another example, if broadcast happened at 4 pm SA time then expiry should be counted as 1 hour from today and 7 hours from next day (8 am to 5 pm time) so it should expire at 3 pm SA time . I have tried this solution but not working can anyone please help me out here
int workHourStartUtc = 6;
int workHourEndUtc = 15;
int expiryWindow = 8;
int currentHourUtc = LocalDateTime.now(ZoneOffset.UTC).getHour();
int hourCompletedToday = currentHourUtc - workHourStartUtc;
int offHours = LocalDate.now().getDayOfWeek() == 1 ? 72 : 24;
LocalDateTime yesterdayWorkEndUtc = LocalDateTime.now(ZoneOffset.UTC).toLocalDate().atTime(workHourEndUtc, 0).minusHours(offHours);
LocalDateTime expireDateBefore = hourCompletedToday >= expiryWindow ? LocalDateTime.now(ZoneOffset.UTC).minusHours(expiryWindow): yesterdayWorkEndUtc.minusHours(expiryWindow - hourCompletedToday);