Skip to content
Permalink
Browse files

Add timezone support to recurring job temporal expressions

(OFBIZ-11035)

When try to define a temporal expression for a recurring job where the temporal expression should be evaluated using a timezone other than whatever the default timezone is for the system.

The use case is having a system that runs on UTC time but needs to send a report at 5 pm Pacific Time every day regardless of whether or not daylight savings is in effect.

To do this:

Added a new field to JobSandbox such as recurrenceTimeZone and modified code to use this timeZone if available.

Thanks: Scott Gray for reporting and Nicolas Malin for the review.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1866499 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Pawan Verma
Pawan Verma committed Sep 6, 2019
1 parent 8cc48ec commit 968515cf07252a666fcf50d498b883d4812b989d
@@ -65,6 +65,7 @@ under the License.
<field name="finishDateTime" type="date-time"></field>
<field name="cancelDateTime" type="date-time"></field>
<field name="jobResult" type="value"></field>
<field name="recurrenceTimeZone" type="id-long"/>
<prim-key field="jobId"/>
<relation type="one" fk-name="JOB_SNDBX_RECINFO" rel-entity-name="RecurrenceInfo">
<key-map field-name="recurrenceInfoId"/>
@@ -49,6 +49,7 @@
import org.xml.sax.SAXException;

import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.TimeZone;

/**
* A {@link Job} that is backed by the entity engine. Job data is stored
@@ -175,7 +176,9 @@ protected void init() throws InvalidJobException {
if (recurrence != null) {
recurrence.incrementCurrentCount();
}
Calendar next = expr.next(Calendar.getInstance());
TimeZone timeZone = jobValue.get("recurrenceTimeZone") != null ? TimeZone.getTimeZone(jobValue.getString("recurrenceTimeZone")) : TimeZone.getDefault();
Calendar next = expr.next(Calendar.getInstance(timeZone));

if (next != null) {
createRecurrence(next.getTimeInMillis(), false);
}

0 comments on commit 968515c

Please sign in to comment.
You can’t perform that action at this time.