From a8852a3997c78d3afdee5c23fbf366c1d0938727 Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Mon, 28 Apr 2025 19:36:52 -0400 Subject: [PATCH] Consider tenant timezone when determining "today" for overdue ILLDEV-52 --- ...imerCheckForOverdueSupplierRequestsService.groovy | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/service/grails-app/services/org/olf/rs/timers/TimerCheckForOverdueSupplierRequestsService.groovy b/service/grails-app/services/org/olf/rs/timers/TimerCheckForOverdueSupplierRequestsService.groovy index 24e4e1f3e..09281edb6 100644 --- a/service/grails-app/services/org/olf/rs/timers/TimerCheckForOverdueSupplierRequestsService.groovy +++ b/service/grails-app/services/org/olf/rs/timers/TimerCheckForOverdueSupplierRequestsService.groovy @@ -1,6 +1,9 @@ package org.olf.rs.timers; -import org.dmfs.rfc5545.DateTime; +import java.time.temporal.ChronoUnit; +import java.time.ZonedDateTime; +import java.time.ZoneId; +import org.olf.rs.OkapiSettingsService; import org.olf.rs.PatronRequest; import org.olf.rs.ReshareApplicationEventHandlerService; import org.olf.rs.statemodel.Status; @@ -26,12 +29,15 @@ where pr.parsedDueDateRS < :today and s.canTriggerOverdueRequest = true) """; + OkapiSettingsService okapiSettingsService; ReshareApplicationEventHandlerService reshareApplicationEventHandlerService; @Override public void performTask(String tenant, String config) { - // Only interested in the date segment and that it is in UTC - Date today = new Date((new DateTime(TimeZone.getTimeZone(TIME_ZONE_UTC), System.currentTimeMillis())).startOfDay().getTimestamp()); + // We need to take the tenant timezone into account when calculating the beginning of the day + Map localeSettings = okapiSettingsService.getLocaleSettings(); + ZoneId zoneId = ZoneId.of(localeSettings?.timezone ?: "UTC"); + Date today = Date.from(ZonedDateTime.now(zoneId).truncatedTo(ChronoUnit.DAYS).withLaterOffsetAtOverlap().toInstant()); // Now find all the incoming requests List requests = PatronRequest.findAll(OVERDUE_REQUESTS_QUERY, [ today : today ]);