ofbiz-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Crum <adrian.c...@sandglass-software.com>
Subject Re: Do Intersection TemporalExpressions work?
Date Sun, 04 Dec 2011 11:41:26 GMT
Technically, you are correct - the next date being returned is wrong, 
but partly because the class is being used incorrectly. If you provide a 
starting calendar to the expression's first method, and then pass the 
returned date to the next method, the dates returned will be correct.

The temporal expressions should provide an iterator instead of the 
having the first and next methods - that would eliminate the problem you 
encountered.

-Adrian


On 12/4/2011 3:24 AM, Craig Ambrose wrote:
> Hello,
>
> I seem to be having problems getting TemporalExpressions to work. They seem to work fine
for some expressions. But not for INTERSECTION types. I am using the TE definition from the
sample data in ServiceDemoData.xml for INDEPENDENCE_DAY, specifically this:
>
>      <TemporalExpression tempExprId="INDEPENDENCE_DAY" tempExprTypeId="INTERSECTION"/>
>      <TemporalExpressionAssoc fromTempExprId="INDEPENDENCE_DAY" toTempExprId="MONTH_RANGE_07"/>
>      <TemporalExpressionAssoc fromTempExprId="INDEPENDENCE_DAY" toTempExprId="DAYOFMONTH_04"/>
>
> And I'm using the following code to iterate over a number of days to see when the next
Independence Day will occur:
>
> com.ibm.icu.util.Calendar cal = new com.ibm.icu.util.GregorianCalendar();
> java.util.Date start = UtilDateTime.toDate("06/01/2011 00:00:00");
> cal.setTime(start);
>
> GenericValue temporalExpression = delegator.findOne("TemporalExpression", UtilMisc.toMap("tempExprId",
"INDEPENDENCE_DAY"), true);
> TemporalExpression selectionDeadline = TemporalExpressionWorker.makeTemporalExpression(delegator,
temporalExpression);
>
> for (int index = 0; index<  60; index++)
> {
> 	Date nextDate = new Date(selectionDeadline.next(cal).getTimeInMillis());
> 	Debug.logInfo(String.format("%s ->  %s", new Date(cal.getTimeInMillis()), nextDate),
"Groovy");
>
> 	cal.add(com.ibm.icu.util.Calendar.DATE, 1);
> }
>
> It doesn't do the right thing for the first 4 days of July. It says for 7/1/2011 that
the next occurrence is 7/4/2012. Here is the output:
>
> 2011-12-03 19:14:52,254 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jun 01 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,256 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jun 02 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,256 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jun 03 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,256 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jun 04 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,257 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jun 05 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,257 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jun 06 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,257 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jun 07 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,258 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jun 08 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,258 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jun 09 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,259 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jun 10 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,260 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jun 11 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,260 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jun 12 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,260 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jun 13 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,260 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jun 14 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,261 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jun 15 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,261 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jun 16 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,261 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jun 17 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,262 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jun 18 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,262 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jun 19 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,262 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jun 20 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,263 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jun 21 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,263 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jun 22 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,263 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jun 23 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,264 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jun 24 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,264 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jun 25 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,264 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jun 26 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,265 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jun 27 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,265 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jun 28 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,266 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jun 29 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,275 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jun 30 00:00:00
PDT 2011 ->  Mon Jul 04 00:00:00 PDT 2011
> 2011-12-03 19:14:52,276 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jul 01 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,277 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jul 02 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,277 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jul 03 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,278 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jul 04 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,279 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jul 05 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,280 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jul 06 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,281 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jul 07 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,282 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jul 08 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,283 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jul 09 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,284 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jul 10 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,289 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jul 11 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,290 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jul 12 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,291 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jul 13 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,292 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jul 14 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,292 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jul 15 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,295 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jul 16 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,313 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jul 17 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,314 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jul 18 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,322 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jul 19 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,323 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jul 20 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,324 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jul 21 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,325 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jul 22 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,326 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jul 23 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,327 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sun Jul 24 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,327 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Mon Jul 25 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,328 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Tue Jul 26 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,329 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Wed Jul 27 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,336 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Thu Jul 28 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,337 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Fri Jul 29 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
> 2011-12-03 19:14:52,338 (http-0.0.0.0-8080-1) [Test.groovy:23 :INFO ] Sat Jul 30 00:00:00
PDT 2011 ->  Wed Jul 04 00:00:00 PDT 2012
>
> I also tried the TE.first() method and it gave different results that were also wrong.
I think it must be a bug. I haven't found a fix yet and I'm hesitant to change this code as
I know at least the job scheduler relies on TemporalExpressions.
>
> Thanks for any guidance.
>
> -craig
>

Mime
View raw message