svn commit: r718373 - in /ofbiz/trunk/framework: service/data/ service/src/org/ofbiz/service/calendar/ webtools/webapp/webtools/tempexpr/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r718373 - in /ofbiz/trunk/framework: service/data/ service/src/org/ofbiz/service/calendar/ webtools/webapp/webtools/tempexpr/

adrianc
Author: adrianc
Date: Mon Nov 17 12:42:16 2008
New Revision: 718373

URL: http://svn.apache.org/viewvc?rev=718373&view=rev
Log:
More Temporal Expression work:

1. Fixed a bug in the TimeOfDayRange class where it didn't calculate properly across a daylight saving transition.
2. Added interval and count to TimeOfDayRange. Now the next() method will increment according to the new fields.

Modified:
    ofbiz/trunk/framework/service/data/ServiceDemoData.xml
    ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressions.java
    ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMacros.ftl
    ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMaint.ftl

Modified: ofbiz/trunk/framework/service/data/ServiceDemoData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/data/ServiceDemoData.xml?rev=718373&r1=718372&r2=718373&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/data/ServiceDemoData.xml (original)
+++ ofbiz/trunk/framework/service/data/ServiceDemoData.xml Mon Nov 17 12:42:16 2008
@@ -171,7 +171,7 @@
         tempExprTypeId       integer1       integer2        date1  date2  string1    string2
         ==================== ============== =============== ====== ====== ========== ========
         DATE_RANGE                                          start  end
-        TIME_OF_DAY_RANGE                                                 start [1]  end [1]
+        TIME_OF_DAY_RANGE    interval [9]   count [7]                     start [1]  end [1]
         DAY_OF_WEEK_RANGE    start [2]      end [2]
         MONTH_RANGE          start [3]      end [3]
         DAY_OF_MONTH_RANGE   start [4]      end [4]
@@ -186,6 +186,7 @@
         [6] Second = 13, Minute = 12, Hour = 11, Day = 5, Month = 2, Year = 1
         [7] Positive integer, zero excluded
         [8] If null, defaults to system date when the expression was retrieved from storage.
+        [9] Second = 13, Minute = 12, Hour = 11 (default)
     -->
     
 </entity-engine-xml>

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java?rev=718373&r1=718372&r2=718373&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java Mon Nov 17 12:42:16 2008
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.service.calendar;
 
+import java.util.Calendar;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -96,7 +97,17 @@
         } else if (MonthRange.equals(tempExprTypeId)) {
             return new TemporalExpressions.MonthRange(exprValue.getLong("integer1").intValue(), exprValue.getLong("integer2").intValue());
         } else if (TimeOfDayRange.equals(tempExprTypeId)) {
-            return new TemporalExpressions.TimeOfDayRange(exprValue.getString("string1"), exprValue.getString("string2"));
+            int interval = Calendar.HOUR_OF_DAY;
+            int count = 1;
+            Long longObj = exprValue.getLong("integer1");
+            if (longObj != null) {
+                interval = longObj.intValue();
+            }
+            longObj = exprValue.getLong("integer2");
+            if (longObj != null) {
+                count = longObj.intValue();
+            }
+            return new TemporalExpressions.TimeOfDayRange(exprValue.getString("string1"), exprValue.getString("string2"), interval, count);
         } else if (Union.equals(tempExprTypeId)) {
             return new TemporalExpressions.Union(getChildExpressions(delegator, tempExprId));
         }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressions.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressions.java?rev=718373&r1=718372&r2=718373&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressions.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressions.java Mon Nov 17 12:42:16 2008
@@ -429,6 +429,8 @@
     public static class TimeOfDayRange extends TemporalExpression {
         protected final String startStr;
         protected final String endStr;
+        protected final int interval;
+        protected final int count;
         protected final int startSecs;
         protected final int startMins;
         protected final int startHrs;
@@ -439,16 +441,27 @@
         /**
          * @param start A time String in the form of hh:mm:ss (24 hr clock)
          * @param end A time String in the form of hh:mm:ss (24 hr clock)
+         * @param interval The range interval - must be one of <code>
+         * Calendar.SECOND Calendar.MINUTE Calendar.HOUR_OF_DAY</code>
+         * @param count The interval count - must be greater than zero
          */
-        public TimeOfDayRange(String start, String end) {
+        public TimeOfDayRange(String start, String end, int interval, int count) {
             if (start == null || start.length() == 0) {
                 throw new IllegalArgumentException("start argument cannot be null or empty");
             }
             if (end == null || end.length() == 0) {
                 throw new IllegalArgumentException("end argument cannot be null or empty");
             }
+            if (interval != Calendar.SECOND && interval != Calendar.MINUTE && interval != Calendar.HOUR_OF_DAY) {
+                throw new IllegalArgumentException("invalid interval argument");
+            }
+            if (count < 1) {
+                throw new IllegalArgumentException("invalid count argument");
+            }
             this.startStr = start;
             this.endStr = end;
+            this.interval = interval;
+            this.count = count;
             String strArray[] = this.startStr.split(":");
             if (strArray.length == 0 || strArray.length > 3) {
                 throw new IllegalArgumentException("Invalid start time argument");
@@ -488,14 +501,19 @@
         }
 
         public String toString() {
-            return super.toString() + ", start = " + this.startStr + ", end = " + this.endStr;
+            return super.toString() + ", start = " + this.startStr + ", end = " + this.endStr
+            + ", interval = " + this.interval + ", count = " + this.count;
         }
 
         public boolean includesDate(Calendar cal) {
             long millis = cal.getTimeInMillis();
             Calendar startCal = setStart(cal);
+            Calendar endCal = setEnd(startCal);
+            if (endCal.before(startCal)) {
+                endCal.add(Calendar.DAY_OF_MONTH, 1);
+            }
             long startMillis = startCal.getTimeInMillis();
-            long endMillis = setEnd(startCal).getTimeInMillis();
+            long endMillis = endCal.getTimeInMillis();
             return millis >= startMillis && millis <= endMillis;
         }
 
@@ -503,11 +521,24 @@
             if (includesDate(cal)) {
                 return cal;
             }
-            return setStart(cal);
+            return next(cal);
         }
 
         public Calendar next(Calendar cal) {
-            return first(cal);
+            Calendar next = (Calendar) cal.clone();
+            next.add(this.interval, this.count);
+            if (!includesDate(next)) {
+                Calendar last = next;
+                next = setStart(next);
+                if (next.before(last)) {
+                    next.add(Calendar.DAY_OF_MONTH, 1);
+                }
+            }
+            return next;
+        }
+
+        public int getCount() {
+            return this.count;
         }
 
         public int getEndHours() {
@@ -522,6 +553,10 @@
             return this.endSecs;
         }
 
+        public int getInterval() {
+            return this.interval;
+        }
+
         public int getStartHours() {
             return this.startHrs;
         }
@@ -538,33 +573,21 @@
             visitor.visit(this);
         }
 
-        protected Calendar advanceCalendar(Calendar cal, int hrs, int mins, int secs) {
-            Calendar advance = (Calendar) cal.clone();
-            advance.set(Calendar.MILLISECOND, 0);
-            int adjust = secs - advance.get(Calendar.SECOND);
-            if (adjust < 0) {
-                adjust += 60;
-            }
-            advance.add(Calendar.SECOND, adjust);
-            adjust = mins - advance.get(Calendar.MINUTE);
-            if (adjust < 0) {
-                adjust += 60;
-            }
-            advance.add(Calendar.MINUTE, adjust);
-            adjust = hrs - advance.get(Calendar.HOUR_OF_DAY);
-            if (adjust < 0) {
-                adjust += 24;
-            }
-            advance.add(Calendar.HOUR_OF_DAY, adjust);
-            return advance;
+        protected Calendar setCalendar(Calendar cal, int hrs, int mins, int secs) {
+            Calendar newCal = (Calendar) cal.clone();
+            newCal.set(Calendar.MILLISECOND, 0);
+            newCal.set(Calendar.SECOND, secs);
+            newCal.set(Calendar.MINUTE, mins);
+            newCal.set(Calendar.HOUR_OF_DAY, hrs);
+            return newCal;
         }
 
         protected Calendar setStart(Calendar cal) {
-            return advanceCalendar(cal, this.startHrs, this.startMins, this.startSecs);
+            return setCalendar(cal, this.startHrs, this.startMins, this.startSecs);
         }
 
         protected Calendar setEnd(Calendar cal) {
-            return advanceCalendar(cal, this.endHrs, this.endMins, this.endSecs);
+            return setCalendar(cal, this.endHrs, this.endMins, this.endSecs);
         }
     }
 

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMacros.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMacros.ftl?rev=718373&r1=718372&r2=718373&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMacros.ftl (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMacros.ftl Mon Nov 17 12:42:16 2008
@@ -129,7 +129,7 @@
   </tr>
 </#macro>
 
-<#macro TimeOfDayRange fromTime="" toTime="">
+<#macro TimeOfDayRange fromTime="" toTime="" freqType=11 freqValue=1>
   <tr>
     <td class="label">${uiLabelMap.CommonFrom}</td>
     <td><input type="text" name="string1" value="${fromTime}" maxlength="8" size="8"/><span class="tooltip">${uiLabelMap.TemporalExpressionTimeFormat}</span></td>
@@ -138,4 +138,18 @@
     <td class="label">${uiLabelMap.CommonTo}</td>
     <td><input type="text" name="string2" value="${toTime}" maxlength="8" size="8"/><span class="tooltip">${uiLabelMap.TemporalExpressionTimeFormat}</span></td>
   </tr>
+  <tr>
+    <td class="label">${uiLabelMap.TemporalExpressionFreqType}</td>
+    <td>
+      <select name="integer1">
+        <option value="13"<#if freqType == 13> selected="selected"</#if>>${uiLabelMap.CommonSecond}</option>
+        <option value="12"<#if freqType == 12> selected="selected"</#if>>${uiLabelMap.CommonMinute}</option>
+        <option value="11"<#if freqType == 11> selected="selected"</#if>>${uiLabelMap.CommonHour}</option>
+      </select>
+    </td>
+  </tr>
+  <tr>
+    <td class="label">${uiLabelMap.TemporalExpressionFreqCount}</td>
+    <td><input type="text" name="integer2" value="${freqValue}" maxlength="8" size="8"/></td>
+  </tr>
 </#macro>

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMaint.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMaint.ftl?rev=718373&r1=718372&r2=718373&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMaint.ftl (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/tempexpr/tempExprMaint.ftl Mon Nov 17 12:42:16 2008
@@ -47,7 +47,7 @@
     <#elseif temporalExpression.tempExprTypeId == "MONTH_RANGE">
       <@MonthRange fromMonth=temporalExpression.integer1 toMonth=temporalExpression.integer2/>
     <#elseif temporalExpression.tempExprTypeId == "TIME_OF_DAY_RANGE">
-      <@TimeOfDayRange fromTime=temporalExpression.string1 toTime=temporalExpression.string2/>
+      <@TimeOfDayRange fromTime=temporalExpression.string1 toTime=temporalExpression.string2 freqType=temporalExpression.integer1 freqValue=temporalExpression.integer2/>
     <#elseif "INTERSECTION.UNION.DIFFERENCE"?contains(temporalExpression.tempExprTypeId)>
       <#assign candidateIdList = Static["org.ofbiz.service.calendar.ExpressionUiHelper"].getCandidateIncludeIds(delegator, temporalExpression.tempExprId)/>
       <#if "INTERSECTION.UNION"?contains(temporalExpression.tempExprTypeId)>