Author: pawan
Date: Fri Sep  6 05:41:47 2019
New Revision: 1866499

URL: http://svn.apache.org/viewvc?rev=1866499&view=rev
Log:
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.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/service/entitydef/entitymodel.xml
    
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java

Modified: 
ofbiz/ofbiz-framework/trunk/framework/service/entitydef/entitymodel.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/entitydef/entitymodel.xml?rev=1866499&r1=1866498&r2=1866499&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/entitydef/entitymodel.xml 
(original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/entitydef/entitymodel.xml Fri 
Sep  6 05:41:47 2019
@@ -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"/>

Modified: 
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java?rev=1866499&r1=1866498&r2=1866499&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/job/PersistedServiceJob.java
 Fri Sep  6 05:41:47 2019
@@ -49,6 +49,7 @@ import org.apache.ofbiz.service.config.S
 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 @@ public class PersistedServiceJob extends
                 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);
                 }


Reply via email to