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);
For sure there are much more elegant solutions but this could be one. I also added a break during lunch(12 to 13 o'clock) so for example if the start is at 12:30 the end will be at 13:30 (Lunchtime = no usage).
public static void main(String[] args) {
For example:
Input: 05.01.2023 15:32
Output: 06.01.2023 16:32
Input: 06.01.2023 08:37
Output: 09.01.2023 09:37