You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Craig Ambrose <cr...@TastingRoom.com> on 2011/12/04 04:24:23 UTC

Do Intersection TemporalExpressions work?

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


Re: Do Intersection TemporalExpressions work?

Posted by Adrian Crum <ad...@sandglass-software.com>.
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
>

Re: Do Intersection TemporalExpressions work?

Posted by Adrian Crum <ad...@sandglass-software.com>.
Craig,

I spent some time writing a test of my own in Groovy and I can confirm 
there is a problem. It is not obvious to me where the problem is, 
because the Temporal Expression code looks correct and it passes unit 
tests. I will have time to explore this further during the weekend. If 
you find a fix before then, feel free to upload a patch to Jira.

-Adrian

On 12/4/2011 6:22 PM, Craig Ambrose wrote:
> Adrian, I really appreciate your help here. But I'm just not getting it to
> work how I would expect. Here is my scenario. Given a date input by a user,
> I want to find the next upcoming TE match. So, I would expect to be able to
> do something like this (in pseudo-code)
>
> Date input = UtilDateTime.toDate(parameters.inputDate);
> cal.setTime(input);
> return new Date(te.next(cal));
>
> If I am using the INDEPENDENCE_DAY TE and I input the date "07/01/2011
> 00:00:00" I get "07/04/2012" as a result. I would expect "07/04/2011". If I
> change the code to use te.first() instead of te.next() then I get unexpected
> results when I input "07/10/2011". I get "07/04/2011" which in my opinion is
> not the first date on or after 7/10/2011.
>
> So, I can first run te.first() check to see if it is less than the input
> date and then call te.next(). Is that the intended usage?
>
> Furthermore, here is the XML definition of the TE I'm really trying to use.
>
> 	<TemporalExpression tempExprId="2ND_SUNDAY_IN_MONTH"
> tempExprTypeId="DAY_IN_MONTH" integer1="1" integer2="2" description="Second
> Sunday of the month"/>
>
> 	<TemporalExpression tempExprId="JAN_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="JAN_END"
> toTempExprId="MONTH_RANGE_01"/>
> 	<TemporalExpressionAssoc fromTempExprId="JAN_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="FEB_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="FEB_END"
> toTempExprId="MONTH_RANGE_02"/>
> 	<TemporalExpressionAssoc fromTempExprId="FEB_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="MAR_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="MAR_END"
> toTempExprId="MONTH_RANGE_03"/>
> 	<TemporalExpressionAssoc fromTempExprId="MAR_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="APR_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="APR_END"
> toTempExprId="MONTH_RANGE_04"/>
> 	<TemporalExpressionAssoc fromTempExprId="APR_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="MAY_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="MAY_END"
> toTempExprId="MONTH_RANGE_05"/>
> 	<TemporalExpressionAssoc fromTempExprId="MAY_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="JUN_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="JUN_END"
> toTempExprId="MONTH_RANGE_06"/>
> 	<TemporalExpressionAssoc fromTempExprId="JUN_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="JUL_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="JUL_END"
> toTempExprId="MONTH_RANGE_07"/>
> 	<TemporalExpressionAssoc fromTempExprId="JUL_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="AUG_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="AUG_END"
> toTempExprId="MONTH_RANGE_08"/>
> 	<TemporalExpressionAssoc fromTempExprId="AUG_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="SEP_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="SEP_END"
> toTempExprId="MONTH_RANGE_09"/>
> 	<TemporalExpressionAssoc fromTempExprId="SEP_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="OCT_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="OCT_END"
> toTempExprId="MONTH_RANGE_10"/>
> 	<TemporalExpressionAssoc fromTempExprId="OCT_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="NOV_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="NOV_END"
> toTempExprId="MONTH_RANGE_11"/>
> 	<TemporalExpressionAssoc fromTempExprId="NOV_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="DEC_END" tempExprTypeId="INTERSECTION"/>
> 	<TemporalExpressionAssoc fromTempExprId="DEC_END"
> toTempExprId="MONTH_RANGE_12"/>
> 	<TemporalExpressionAssoc fromTempExprId="DEC_END"
> toTempExprId="2ND_SUNDAY_IN_MONTH"/>
>
> 	<TemporalExpression tempExprId="BI_MONTHLY_ONE" tempExprTypeId="UNION"
> description="Second Sunday of every odd month"/>
> 	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
> toTempExprId="JAN_END"/>
> 	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
> toTempExprId="MAR_END"/>
> 	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
> toTempExprId="MAY_END"/>
> 	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
> toTempExprId="JUL_END"/>
> 	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
> toTempExprId="SEP_END"/>
> 	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
> toTempExprId="NOV_END"/>
>
> I'm trying to model the second Sunday in every odd month (i.e. Jan, Mar,
> May, etc.). The 2ND_SUNDAY_IN_MONTH TE works great until I use it in an
> INTERSECTION or UNION.
>
> The te.first() method gives me very strange results. Perhaps I am defining
> the TE incorrectly, but it seems to give me any match in the union and not
> the first occurrence after the provided date. For example, using my
> BI_MONTHLY_ONE TemporalExpression I call the following pseudo code
>
> function nextOcc(te, inputDate)
> {
>      return te.next(inputDate);
> }
>
> And I get this
>
> nextOcc(te, "06/01/2011") ->  11/13/2011
>
> Where I would expect the next occurrence after 6/1/2011 would be 7/10/2011;
> the second Sunday in July.
>
> I'm sure I'm confusing something here. So, any guidance would be greatly
> appreciated.
>
> Thanks again
>
> -craig
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Do-Intersection-TemporalExpressions-work-tp4155989p4157599.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Do Intersection TemporalExpressions work?

Posted by Craig Ambrose <cr...@TastingRoom.com>.
Adrian, I really appreciate your help here. But I'm just not getting it to
work how I would expect. Here is my scenario. Given a date input by a user,
I want to find the next upcoming TE match. So, I would expect to be able to
do something like this (in pseudo-code)

Date input = UtilDateTime.toDate(parameters.inputDate);
cal.setTime(input);
return new Date(te.next(cal));

If I am using the INDEPENDENCE_DAY TE and I input the date "07/01/2011
00:00:00" I get "07/04/2012" as a result. I would expect "07/04/2011". If I
change the code to use te.first() instead of te.next() then I get unexpected
results when I input "07/10/2011". I get "07/04/2011" which in my opinion is
not the first date on or after 7/10/2011.

So, I can first run te.first() check to see if it is less than the input
date and then call te.next(). Is that the intended usage?

Furthermore, here is the XML definition of the TE I'm really trying to use.

	<TemporalExpression tempExprId="2ND_SUNDAY_IN_MONTH"
tempExprTypeId="DAY_IN_MONTH" integer1="1" integer2="2" description="Second
Sunday of the month"/>

	<TemporalExpression tempExprId="JAN_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="JAN_END"
toTempExprId="MONTH_RANGE_01"/>
	<TemporalExpressionAssoc fromTempExprId="JAN_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="FEB_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="FEB_END"
toTempExprId="MONTH_RANGE_02"/>
	<TemporalExpressionAssoc fromTempExprId="FEB_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="MAR_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="MAR_END"
toTempExprId="MONTH_RANGE_03"/>
	<TemporalExpressionAssoc fromTempExprId="MAR_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="APR_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="APR_END"
toTempExprId="MONTH_RANGE_04"/>
	<TemporalExpressionAssoc fromTempExprId="APR_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="MAY_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="MAY_END"
toTempExprId="MONTH_RANGE_05"/>
	<TemporalExpressionAssoc fromTempExprId="MAY_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="JUN_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="JUN_END"
toTempExprId="MONTH_RANGE_06"/>
	<TemporalExpressionAssoc fromTempExprId="JUN_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="JUL_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="JUL_END"
toTempExprId="MONTH_RANGE_07"/>
	<TemporalExpressionAssoc fromTempExprId="JUL_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="AUG_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="AUG_END"
toTempExprId="MONTH_RANGE_08"/>
	<TemporalExpressionAssoc fromTempExprId="AUG_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="SEP_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="SEP_END"
toTempExprId="MONTH_RANGE_09"/>
	<TemporalExpressionAssoc fromTempExprId="SEP_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="OCT_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="OCT_END"
toTempExprId="MONTH_RANGE_10"/>
	<TemporalExpressionAssoc fromTempExprId="OCT_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="NOV_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="NOV_END"
toTempExprId="MONTH_RANGE_11"/>
	<TemporalExpressionAssoc fromTempExprId="NOV_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="DEC_END" tempExprTypeId="INTERSECTION"/>
	<TemporalExpressionAssoc fromTempExprId="DEC_END"
toTempExprId="MONTH_RANGE_12"/>
	<TemporalExpressionAssoc fromTempExprId="DEC_END"
toTempExprId="2ND_SUNDAY_IN_MONTH"/>

	<TemporalExpression tempExprId="BI_MONTHLY_ONE" tempExprTypeId="UNION"
description="Second Sunday of every odd month"/>
	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
toTempExprId="JAN_END"/>
	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
toTempExprId="MAR_END"/>
	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
toTempExprId="MAY_END"/>
	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
toTempExprId="JUL_END"/>
	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
toTempExprId="SEP_END"/>
	<TemporalExpressionAssoc fromTempExprId="BI_MONTHLY_ONE"
toTempExprId="NOV_END"/>

I'm trying to model the second Sunday in every odd month (i.e. Jan, Mar,
May, etc.). The 2ND_SUNDAY_IN_MONTH TE works great until I use it in an
INTERSECTION or UNION.

The te.first() method gives me very strange results. Perhaps I am defining
the TE incorrectly, but it seems to give me any match in the union and not
the first occurrence after the provided date. For example, using my
BI_MONTHLY_ONE TemporalExpression I call the following pseudo code

function nextOcc(te, inputDate)
{
    return te.next(inputDate);
}

And I get this

nextOcc(te, "06/01/2011") -> 11/13/2011

Where I would expect the next occurrence after 6/1/2011 would be 7/10/2011;
the second Sunday in July.

I'm sure I'm confusing something here. So, any guidance would be greatly
appreciated.

Thanks again

-craig

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Do-Intersection-TemporalExpressions-work-tp4155989p4157599.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Do Intersection TemporalExpressions work?

Posted by Adrian Crum <ad...@sandglass-software.com>.
I believe the API documentation describes that as normal behavior. The 
first occurrence of July 4 on or after July 4 2011 is July 4 2011. If 
you want the next occurrence, then you need to call the next method.

-Adrian

On 12/4/2011 5:33 PM, Craig Ambrose wrote:
> Thanks again Adrian. But when I call te.first() with an initial calendar of
> "07/14/2011" it also returns "07/04/2011" not "07/04/2012" as I would
> expect. That was what I was trying to expose with the for loop; What would
> be the returned values for various input dates.
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Do-Intersection-TemporalExpressions-work-tp4155989p4157474.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Do Intersection TemporalExpressions work?

Posted by Craig Ambrose <cr...@TastingRoom.com>.
Thanks again Adrian. But when I call te.first() with an initial calendar of
"07/14/2011" it also returns "07/04/2011" not "07/04/2012" as I would
expect. That was what I was trying to expose with the for loop; What would
be the returned values for various input dates.

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Do-Intersection-TemporalExpressions-work-tp4155989p4157474.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Do Intersection TemporalExpressions work?

Posted by Adrian Crum <ad...@sandglass-software.com>.
I am not sure what you are trying to accomplish with your example code. 
If you want an event to repeat every Independence Day, then call the 
Independence Day temporal expression's first method, and then call the 
next method using the returned Calendar. You can call the next method 
for as many years as you like. There is no need to increment the date 
outside of the temporal expression.

So, calling the first method with a Calendar initialized to 06/01/2011 
will return 07/04/2011. Calling the next method with 07/04/2011 will 
return 07/04/2012, and so on...

In other words, the Calendar returned by the temporal expression is 
supposed to be used as a parameter for the expression's next method.

-Adrian

On 12/4/2011 4:17 PM, Craig Ambrose wrote:
> Thanks Adrian. But that doesn't seem to give the expected results either.
> Here is what I switched to:
>
>
> 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++)
> {
> 	com.ibm.icu.util.Calendar first = selectionDeadline.first(cal);
> 	Date nextDate = new Date(selectionDeadline.next(first).getTimeInMillis());
> 	Debug.logInfo(String.format("%s ->  %s ->  %s",
> 								UtilDateTime.toDateString(new Date(cal.getTimeInMillis())),
> 								UtilDateTime.toDateString(new Date(first.getTimeInMillis())),
> 								UtilDateTime.toDateString(nextDate)),
> 				  "Groovy");
>
> 	cal.add(com.ibm.icu.util.Calendar.DATE, 1);
> }
>
> With calling te.first() and passing the result to te.next(). It always
> outputs 7/4/2012.
>
> Perhaps I need to check the result of te.first() first? Like this:
>
>
> for (int index = 0; index<  60; index++)
> {
> 	com.ibm.icu.util.Calendar first = selectionDeadline.first(cal);
> 	com.ibm.icu.util.Calendar nextCal;
> 	if (first>  cal)
> 	{
> 		nextCal = first
> 	}
> 	else
> 	{
> 		nextCal = selectionDeadline.next(first);
> 	}
> 	Debug.logInfo(String.format("%s ->  %s ->  %s",
> 								UtilDateTime.toDateString(new Date(cal.getTimeInMillis())),
> 								UtilDateTime.toDateString(new Date(first.getTimeInMillis())),
> 								UtilDateTime.toDateString(new Date(nextCal.getTimeInMillis()))),
> 				  "Groovy");
>
> 	cal.add(com.ibm.icu.util.Calendar.DATE, 1);
> }
>
> Is that the intended use?
>
> Thanks for your timely response.
>
> -craig
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Do-Intersection-TemporalExpressions-work-tp4155989p4157247.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Do Intersection TemporalExpressions work?

Posted by Craig Ambrose <cr...@TastingRoom.com>.
Thanks Adrian. But that doesn't seem to give the expected results either.
Here is what I switched to:


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++)
{
	com.ibm.icu.util.Calendar first = selectionDeadline.first(cal);
	Date nextDate = new Date(selectionDeadline.next(first).getTimeInMillis());
	Debug.logInfo(String.format("%s -> %s -> %s",
								UtilDateTime.toDateString(new Date(cal.getTimeInMillis())),
								UtilDateTime.toDateString(new Date(first.getTimeInMillis())),
								UtilDateTime.toDateString(nextDate)),
				  "Groovy");

	cal.add(com.ibm.icu.util.Calendar.DATE, 1);
}

With calling te.first() and passing the result to te.next(). It always
outputs 7/4/2012.

Perhaps I need to check the result of te.first() first? Like this:


for (int index = 0; index < 60; index++)
{
	com.ibm.icu.util.Calendar first = selectionDeadline.first(cal);
	com.ibm.icu.util.Calendar nextCal;
	if (first > cal)
	{
		nextCal = first
	}
	else
	{
		nextCal = selectionDeadline.next(first);
	}
	Debug.logInfo(String.format("%s -> %s -> %s",
								UtilDateTime.toDateString(new Date(cal.getTimeInMillis())),
								UtilDateTime.toDateString(new Date(first.getTimeInMillis())),
								UtilDateTime.toDateString(new Date(nextCal.getTimeInMillis()))),
				  "Groovy");

	cal.add(com.ibm.icu.util.Calendar.DATE, 1);
}

Is that the intended use?

Thanks for your timely response.

-craig

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Do-Intersection-TemporalExpressions-work-tp4155989p4157247.html
Sent from the OFBiz - User mailing list archive at Nabble.com.