Datetime/Date/Time format for relevance expressions

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I can't seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

From the source code,
https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128
there are two functions that might be useful.

relevant="q176 < date('2012-07-06T14:00:00-0400')"

would convert the string to a date and compare it to the date. This is
probably preferable.

Or,

relevant="dateStr(q176,'yyy-MM-dd'T'hh:mm:ssZ') <
'2012-07-06T14:00:00-0400'"

would convert the date to a string and do a string compare. I'm not sure on
how to express the escaping of the single quote.

Mitch

··· On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth wrote:

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I can't seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Thanks!

··· On 6 July 2012 12:37, Mitch S wrote: > From the source code, > https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128 > there are two functions that might be useful. > > relevant="q176 < date('2012-07-06T14:00:00-0400')" > > would convert the string to a date and compare it to the date. This is > probably preferable. > > Or, > > relevant="dateStr(q176,'yyy-MM-dd\'T\'hh:mm:ssZ') < > '2012-07-06T14:00:00-0400'" > > would convert the date to a string and do a string compare. I'm not sure on > how to express the escaping of the single quote. > > Mitch > > > On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth wrote: >> >> Does anyone know the syntax for comparing dates in a relevance >> expression? I've tried several incantations of xpath but I can't seem >> to get it to work. >> >> Currently I have something like this: >> >> relevant="q176 < '2012-07-06T14:00:00-0400'" >> >> But it's obviously not working. >> >> Thanks > > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitchellsundt@gmail.com

Hmm, none of these seem to be working. I tried:

and

and a variety of others. (Note that I think you meant format-date(
instead of dateStr( -- the latter is the Java function. Also the date
formatter in org.javarosa.core.model.utils.DateFormat seems to use the
% notation. Let me know if I'm wrong on this).

··· On 6 July 2012 12:48, Thomas Smyth wrote: > Thanks! > > On 6 July 2012 12:37, Mitch S wrote: >> From the source code, >> https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128 >> there are two functions that might be useful. >> >> relevant="q176 < date('2012-07-06T14:00:00-0400')" >> >> would convert the string to a date and compare it to the date. This is >> probably preferable. >> >> Or, >> >> relevant="dateStr(q176,'yyy-MM-dd\'T\'hh:mm:ssZ') < >> '2012-07-06T14:00:00-0400'" >> >> would convert the date to a string and do a string compare. I'm not sure on >> how to express the escaping of the single quote. >> >> Mitch >> >> >> On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth wrote: >>> >>> Does anyone know the syntax for comparing dates in a relevance >>> expression? I've tried several incantations of xpath but I can't seem >>> to get it to work. >>> >>> Currently I have something like this: >>> >>> relevant="q176 < '2012-07-06T14:00:00-0400'" >>> >>> But it's obviously not working. >>> >>> Thanks >> >> >> >> >> -- >> Mitch Sundt >> Software Engineer >> University of Washington >> mitchellsundt@gmail.com

Update on this:

I got it to work for datetime and date (turns out I just should have
been putting /data/q179 instead of just q179.

But time doesn't work...

If I try for example:

relevant="format-date(/data/q181, '%H%M') &gt; '0830'"

internally, the format-date expression is returning "0000" instead of
"1330" or whatever as it should be. (I found this out by putting some
printlns in the javarosa core code.

So is this a bug? Or am I doing something wrong?

Note that doing it the other way, using "/data/q181 > date('8:30')"
or something like that doesn't work since 8:30 doesn't work for the
date conversion function.

··· On 6 July 2012 13:32, Thomas Smyth wrote: > Hmm, none of these seem to be working. I tried: > > > > > > and > > > > > > and a variety of others. (Note that I think you meant format-date( > instead of dateStr( -- the latter is the Java function. Also the date > formatter in org.javarosa.core.model.utils.DateFormat seems to use the > % notation. Let me know if I'm wrong on this). > > > On 6 July 2012 12:48, Thomas Smyth wrote: >> Thanks! >> >> On 6 July 2012 12:37, Mitch S wrote: >>> From the source code, >>> https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128 >>> there are two functions that might be useful. >>> >>> relevant="q176 < date('2012-07-06T14:00:00-0400')" >>> >>> would convert the string to a date and compare it to the date. This is >>> probably preferable. >>> >>> Or, >>> >>> relevant="dateStr(q176,'yyy-MM-dd\'T\'hh:mm:ssZ') < >>> '2012-07-06T14:00:00-0400'" >>> >>> would convert the date to a string and do a string compare. I'm not sure on >>> how to express the escaping of the single quote. >>> >>> Mitch >>> >>> >>> On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth wrote: >>>> >>>> Does anyone know the syntax for comparing dates in a relevance >>>> expression? I've tried several incantations of xpath but I can't seem >>>> to get it to work. >>>> >>>> Currently I have something like this: >>>> >>>> relevant="q176 < '2012-07-06T14:00:00-0400'" >>>> >>>> But it's obviously not working. >>>> >>>> Thanks >>> >>> >>> >>> >>> -- >>> Mitch Sundt >>> Software Engineer >>> University of Washington >>> mitchellsundt@gmail.com

ALSO, datetime comparisons other than equals/not-equals aren't working either.

I think this is because javarosa converts a Date to a number for these
comparisons, and it doesn't properly support datetime values. So the
time value is getting truncated and coming back as 0000. This also
explains the Time problem.

So I'm guessing that if I want this to work I'm going to have to do it
myself. Has anyone even touched the javarosa codebase in the last few
years? Yuck.

··· On 12 July 2012 14:05, Thomas Smyth wrote: > Update on this: > > I got it to work for datetime and date (turns out I just should have > been putting /data/q179 instead of just q179. > > But time doesn't work... > > If I try for example: > > relevant="format-date(/data/q181, '%H%M') > '0830'" > > internally, the format-date expression is returning "0000" instead of > "1330" or whatever as it should be. (I found this out by putting some > printlns in the javarosa core code. > > So is this a bug? Or am I doing something wrong? > > Note that doing it the other way, using "/data/q181 > date('8:30')" > or something like that doesn't work since 8:30 doesn't work for the > date conversion function. > > > On 6 July 2012 13:32, Thomas Smyth wrote: >> Hmm, none of these seem to be working. I tried: >> >> >> >> >> >> and >> >> >> >> >> >> and a variety of others. (Note that I think you meant format-date( >> instead of dateStr( -- the latter is the Java function. Also the date >> formatter in org.javarosa.core.model.utils.DateFormat seems to use the >> % notation. Let me know if I'm wrong on this). >> >> >> On 6 July 2012 12:48, Thomas Smyth wrote: >>> Thanks! >>> >>> On 6 July 2012 12:37, Mitch S wrote: >>>> From the source code, >>>> https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128 >>>> there are two functions that might be useful. >>>> >>>> relevant="q176 < date('2012-07-06T14:00:00-0400')" >>>> >>>> would convert the string to a date and compare it to the date. This is >>>> probably preferable. >>>> >>>> Or, >>>> >>>> relevant="dateStr(q176,'yyy-MM-dd\'T\'hh:mm:ssZ') < >>>> '2012-07-06T14:00:00-0400'" >>>> >>>> would convert the date to a string and do a string compare. I'm not sure on >>>> how to express the escaping of the single quote. >>>> >>>> Mitch >>>> >>>> >>>> On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth wrote: >>>>> >>>>> Does anyone know the syntax for comparing dates in a relevance >>>>> expression? I've tried several incantations of xpath but I can't seem >>>>> to get it to work. >>>>> >>>>> Currently I have something like this: >>>>> >>>>> relevant="q176 < '2012-07-06T14:00:00-0400'" >>>>> >>>>> But it's obviously not working. >>>>> >>>>> Thanks >>>> >>>> >>>> >>>> >>>> -- >>>> Mitch Sundt >>>> Software Engineer >>>> University of Washington >>>> mitchellsundt@gmail.com

I put this in a bug report
http://code.google.com/p/opendatakit/issues/detail?id=630

FYI: ODK Collect 1.2 uses this fork of javarosa:
https://bitbucket.org/m.sundt/javarosa That fork is slightly updated from
KoBo Collect's javarosa library -- for example, it removes the use of
static variables for the secondary instance data, which breaks during
multithreaded operations (such as in ODK Collect). It includes a new
round(value,decimalplace) function to simplify rounding (like in Excel) and
it includes code to pass through all bind attributes and attributes on the
question declarations. The later are primarily to support rapid prototyping
by undergrads at the UW. These last changes are unlikely to find their way
into the core JR code.

Mitch

··· On Thu, Jul 12, 2012 at 11:15 AM, Thomas Smyth wrote:

ALSO, datetime comparisons other than equals/not-equals aren't working
either.

I think this is because javarosa converts a Date to a number for these
comparisons, and it doesn't properly support datetime values. So the
time value is getting truncated and coming back as 0000. This also
explains the Time problem.

So I'm guessing that if I want this to work I'm going to have to do it
myself. Has anyone even touched the javarosa codebase in the last few
years? Yuck.

On 12 July 2012 14:05, Thomas Smyth thomas.smyth@gatech.edu wrote:

Update on this:

I got it to work for datetime and date (turns out I just should have
been putting /data/q179 instead of just q179.

But time doesn't work...

If I try for example:

relevant="format-date(/data/q181, '%H%M') &gt; '0830'"

internally, the format-date expression is returning "0000" instead of
"1330" or whatever as it should be. (I found this out by putting some
printlns in the javarosa core code.

So is this a bug? Or am I doing something wrong?

Note that doing it the other way, using "/data/q181 > date('8:30')"
or something like that doesn't work since 8:30 doesn't work for the
date conversion function.

On 6 July 2012 13:32, Thomas Smyth thomas.smyth@gatech.edu wrote:

Hmm, none of these seem to be working. I tried:

and

and a variety of others. (Note that I think you meant format-date(
instead of dateStr( -- the latter is the Java function. Also the date
formatter in org.javarosa.core.model.utils.DateFormat seems to use the
% notation. Let me know if I'm wrong on this).

On 6 July 2012 12:48, Thomas Smyth thomas.smyth@gatech.edu wrote:

Thanks!

On 6 July 2012 12:37, Mitch S mitchellsundt@gmail.com wrote:

From the source code,

https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128

there are two functions that might be useful.

relevant="q176 < date('2012-07-06T14:00:00-0400')"

would convert the string to a date and compare it to the date. This
is

probably preferable.

Or,

relevant="dateStr(q176,'yyy-MM-dd'T'hh:mm:ssZ') <
'2012-07-06T14:00:00-0400'"

would convert the date to a string and do a string compare. I'm not
sure on

how to express the escaping of the single quote.

Mitch

On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth <thomas.smyth@gatech.edu wrote:

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I can't seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Ok that's good to know.

I found a fix for the time comparison stuff. On line 550 of
org.javarosa.xpath.expr.XPathFuncExpr.java, for some reason they're
rounding the date object, which kills the time values.

 DateUtils.roundDate((Date)o);

If I change this to just return o; it works fine. I can't imagine any
adverse effects of this, but I stand to be corrected..

The best way to write the xml then is like so:

    <bind nodeset="/data/q179" type="dateTime" />
    <bind nodeset="/data/q180" relevant="format-date(/data/q179,

'%Y%m%d%H%M') > '201207121200'" type="date" />

Should I check this in to the fork you mentioned? I can't believe
nobody has ever had to use this functionality before...

··· On 12 July 2012 14:35, Mitch S wrote: > I put this in a bug report > http://code.google.com/p/opendatakit/issues/detail?id=630 > > FYI: ODK Collect 1.2 uses this fork of javarosa: > https://bitbucket.org/m.sundt/javarosa That fork is slightly updated from > KoBo Collect's javarosa library -- for example, it removes the use of static > variables for the secondary instance data, which breaks during multithreaded > operations (such as in ODK Collect). It includes a new > round(value,decimalplace) function to simplify rounding (like in Excel) and > it includes code to pass through all bind attributes and attributes on the > question declarations. The later are primarily to support rapid prototyping > by undergrads at the UW. These last changes are unlikely to find their way > into the core JR code. > > Mitch > > > On Thu, Jul 12, 2012 at 11:15 AM, Thomas Smyth wrote: >> >> ALSO, datetime comparisons other than equals/not-equals aren't working >> either. >> >> I think this is because javarosa converts a Date to a number for these >> comparisons, and it doesn't properly support datetime values. So the >> time value is getting truncated and coming back as 0000. This also >> explains the Time problem. >> >> So I'm guessing that if I want this to work I'm going to have to do it >> myself. Has anyone even touched the javarosa codebase in the last few >> years? Yuck. >> >> >> On 12 July 2012 14:05, Thomas Smyth wrote: >> > Update on this: >> > >> > I got it to work for datetime and date (turns out I just should have >> > been putting /data/q179 instead of just q179. >> > >> > But time doesn't work... >> > >> > If I try for example: >> > >> > relevant="format-date(/data/q181, '%H%M') > '0830'" >> > >> > internally, the format-date expression is returning "0000" instead of >> > "1330" or whatever as it should be. (I found this out by putting some >> > printlns in the javarosa core code. >> > >> > So is this a bug? Or am I doing something wrong? >> > >> > Note that doing it the other way, using "/data/q181 > date('8:30')" >> > or something like that doesn't work since 8:30 doesn't work for the >> > date conversion function. >> > >> > >> > On 6 July 2012 13:32, Thomas Smyth wrote: >> >> Hmm, none of these seem to be working. I tried: >> >> >> >> >> >> >> >> >> >> >> >> and >> >> >> >> >> >> >> >> >> >> >> >> and a variety of others. (Note that I think you meant format-date( >> >> instead of dateStr( -- the latter is the Java function. Also the date >> >> formatter in org.javarosa.core.model.utils.DateFormat seems to use the >> >> % notation. Let me know if I'm wrong on this). >> >> >> >> >> >> On 6 July 2012 12:48, Thomas Smyth wrote: >> >>> Thanks! >> >>> >> >>> On 6 July 2012 12:37, Mitch S wrote: >> >>>> From the source code, >> >>>> >> >>>> https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128 >> >>>> there are two functions that might be useful. >> >>>> >> >>>> relevant="q176 < date('2012-07-06T14:00:00-0400')" >> >>>> >> >>>> would convert the string to a date and compare it to the date. This >> >>>> is >> >>>> probably preferable. >> >>>> >> >>>> Or, >> >>>> >> >>>> relevant="dateStr(q176,'yyy-MM-dd\'T\'hh:mm:ssZ') < >> >>>> '2012-07-06T14:00:00-0400'" >> >>>> >> >>>> would convert the date to a string and do a string compare. I'm not >> >>>> sure on >> >>>> how to express the escaping of the single quote. >> >>>> >> >>>> Mitch >> >>>> >> >>>> >> >>>> On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth wrote: >> >>>>> >> >>>>> Does anyone know the syntax for comparing dates in a relevance >> >>>>> expression? I've tried several incantations of xpath but I can't >> >>>>> seem >> >>>>> to get it to work. >> >>>>> >> >>>>> Currently I have something like this: >> >>>>> >> >>>>> relevant="q176 < '2012-07-06T14:00:00-0400'" >> >>>>> >> >>>>> But it's obviously not working. >> >>>>> >> >>>>> Thanks >> >>>> >> >>>> >> >>>> >> >>>> >> >>>> -- >> >>>> Mitch Sundt >> >>>> Software Engineer >> >>>> University of Washington >> >>>> mitchellsundt@gmail.com > > > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitchellsundt@gmail.com

Actually, the roundDate hack is to allow date calculations to work
correctly, so the fix should not be there.

Basically, the problem is that the Date values are hard to interpret
properly because JR emits them without any timezone information. So doing
tests for "same date as today" were problematic. the rounding hack was to
mostly handle this.

You probably want to define a new function like dateTimeDiff(arg1, arg2)
that would preserve the time. Probably adding this to DateUtils then adding
a new function to XPathFuncExpr.

This is a small enough change that if you attach the changed DateUtils and
XPathFuncExpr classes, I'll look at it and figure out where it would go.

You should do your own build of ODK Collect with these changes, as I don't
know when I will fold them into a new release. I am shifting gears to work
on 2.0 planning and development. We'll be updating 1.2, but hopefully at a
slower pace than we have with 1.x

Mitch

··· On Thu, Jul 12, 2012 at 11:47 AM, Thomas Smyth wrote:

Ok that's good to know.

I found a fix for the time comparison stuff. On line 550 of
org.javarosa.xpath.expr.XPathFuncExpr.java, for some reason they're
rounding the date object, which kills the time values.

 DateUtils.roundDate((Date)o);

If I change this to just return o; it works fine. I can't imagine any
adverse effects of this, but I stand to be corrected..

The best way to write the xml then is like so:

    <bind nodeset="/data/q179" type="dateTime" />
    <bind nodeset="/data/q180" relevant="format-date(/data/q179,

'%Y%m%d%H%M') > '201207121200'" type="date" />

Should I check this in to the fork you mentioned? I can't believe
nobody has ever had to use this functionality before...

On 12 July 2012 14:35, Mitch S mitchellsundt@gmail.com wrote:

I put this in a bug report
http://code.google.com/p/opendatakit/issues/detail?id=630

FYI: ODK Collect 1.2 uses this fork of javarosa:
https://bitbucket.org/m.sundt/javarosa That fork is slightly updated
from
KoBo Collect's javarosa library -- for example, it removes the use of
static
variables for the secondary instance data, which breaks during
multithreaded
operations (such as in ODK Collect). It includes a new
round(value,decimalplace) function to simplify rounding (like in Excel)
and
it includes code to pass through all bind attributes and attributes on
the
question declarations. The later are primarily to support rapid
prototyping
by undergrads at the UW. These last changes are unlikely to find their
way
into the core JR code.

Mitch

On Thu, Jul 12, 2012 at 11:15 AM, Thomas Smyth thomas.smyth@gatech.edu wrote:

ALSO, datetime comparisons other than equals/not-equals aren't working
either.

I think this is because javarosa converts a Date to a number for these
comparisons, and it doesn't properly support datetime values. So the
time value is getting truncated and coming back as 0000. This also
explains the Time problem.

So I'm guessing that if I want this to work I'm going to have to do it
myself. Has anyone even touched the javarosa codebase in the last few
years? Yuck.

On 12 July 2012 14:05, Thomas Smyth thomas.smyth@gatech.edu wrote:

Update on this:

I got it to work for datetime and date (turns out I just should have
been putting /data/q179 instead of just q179.

But time doesn't work...

If I try for example:

relevant="format-date(/data/q181, '%H%M') &gt; '0830'"

internally, the format-date expression is returning "0000" instead of
"1330" or whatever as it should be. (I found this out by putting some
printlns in the javarosa core code.

So is this a bug? Or am I doing something wrong?

Note that doing it the other way, using "/data/q181 > date('8:30')"
or something like that doesn't work since 8:30 doesn't work for the
date conversion function.

On 6 July 2012 13:32, Thomas Smyth thomas.smyth@gatech.edu wrote:

Hmm, none of these seem to be working. I tried:

and

and a variety of others. (Note that I think you meant format-date(
instead of dateStr( -- the latter is the Java function. Also the date
formatter in org.javarosa.core.model.utils.DateFormat seems to use
the

% notation. Let me know if I'm wrong on this).

On 6 July 2012 12:48, Thomas Smyth thomas.smyth@gatech.edu wrote:

Thanks!

On 6 July 2012 12:37, Mitch S mitchellsundt@gmail.com wrote:

From the source code,

https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128

there are two functions that might be useful.

relevant="q176 < date('2012-07-06T14:00:00-0400')"

would convert the string to a date and compare it to the date.
This

is
probably preferable.

Or,

relevant="dateStr(q176,'yyy-MM-dd'T'hh:mm:ssZ') <
'2012-07-06T14:00:00-0400'"

would convert the date to a string and do a string compare. I'm not
sure on
how to express the escaping of the single quote.

Mitch

On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth thomas.smyth@gatech.edu wrote:

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I can't
seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Hello,

I am having troubles trying to do specify two or more relevance expression
for one question. Example, if i had 4 questions, then wanted to make
specify a relevance for q4 like: < bind
nodeset="/data/q4" relevant="/data/q1=1" relevant="data/q3=1" type="string">

Please assist.

··· On Thu, Jul 12, 2012 at 7:41 PM, Mitch S wrote:

Actually, the roundDate hack is to allow date calculations to work
correctly, so the fix should not be there.

Basically, the problem is that the Date values are hard to interpret
properly because JR emits them without any timezone information. So doing
tests for "same date as today" were problematic. the rounding hack was to
mostly handle this.

You probably want to define a new function like dateTimeDiff(arg1, arg2)
that would preserve the time. Probably adding this to DateUtils then adding
a new function to XPathFuncExpr.

This is a small enough change that if you attach the changed DateUtils and
XPathFuncExpr classes, I'll look at it and figure out where it would go.

You should do your own build of ODK Collect with these changes, as I don't
know when I will fold them into a new release. I am shifting gears to work
on 2.0 planning and development. We'll be updating 1.2, but hopefully at a
slower pace than we have with 1.x

Mitch

On Thu, Jul 12, 2012 at 11:47 AM, Thomas Smyth thomas.smyth@gatech.eduwrote:

Ok that's good to know.

I found a fix for the time comparison stuff. On line 550 of
org.javarosa.xpath.expr.XPathFuncExpr.java, for some reason they're
rounding the date object, which kills the time values.

 DateUtils.roundDate((Date)o);

If I change this to just return o; it works fine. I can't imagine any
adverse effects of this, but I stand to be corrected..

The best way to write the xml then is like so:

    <bind nodeset="/data/q179" type="dateTime" />
    <bind nodeset="/data/q180" relevant="format-date(/data/q179,

'%Y%m%d%H%M') > '201207121200'" type="date" />

Should I check this in to the fork you mentioned? I can't believe
nobody has ever had to use this functionality before...

On 12 July 2012 14:35, Mitch S mitchellsundt@gmail.com wrote:

I put this in a bug report
http://code.google.com/p/opendatakit/issues/detail?id=630

FYI: ODK Collect 1.2 uses this fork of javarosa:
https://bitbucket.org/m.sundt/javarosa That fork is slightly updated
from
KoBo Collect's javarosa library -- for example, it removes the use of
static
variables for the secondary instance data, which breaks during
multithreaded
operations (such as in ODK Collect). It includes a new
round(value,decimalplace) function to simplify rounding (like in Excel)
and
it includes code to pass through all bind attributes and attributes on
the
question declarations. The later are primarily to support rapid
prototyping
by undergrads at the UW. These last changes are unlikely to find their
way
into the core JR code.

Mitch

On Thu, Jul 12, 2012 at 11:15 AM, Thomas Smyth <thomas.smyth@gatech.edu wrote:

ALSO, datetime comparisons other than equals/not-equals aren't working
either.

I think this is because javarosa converts a Date to a number for these
comparisons, and it doesn't properly support datetime values. So the
time value is getting truncated and coming back as 0000. This also
explains the Time problem.

So I'm guessing that if I want this to work I'm going to have to do it
myself. Has anyone even touched the javarosa codebase in the last few
years? Yuck.

On 12 July 2012 14:05, Thomas Smyth thomas.smyth@gatech.edu wrote:

Update on this:

I got it to work for datetime and date (turns out I just should have
been putting /data/q179 instead of just q179.

But time doesn't work...

If I try for example:

relevant="format-date(/data/q181, '%H%M') &gt; '0830'"

internally, the format-date expression is returning "0000" instead of
"1330" or whatever as it should be. (I found this out by putting some
printlns in the javarosa core code.

So is this a bug? Or am I doing something wrong?

Note that doing it the other way, using "/data/q181 >
date('8:30')"

or something like that doesn't work since 8:30 doesn't work for the
date conversion function.

On 6 July 2012 13:32, Thomas Smyth thomas.smyth@gatech.edu wrote:

Hmm, none of these seem to be working. I tried:

and

and a variety of others. (Note that I think you meant format-date(
instead of dateStr( -- the latter is the Java function. Also the
date

formatter in org.javarosa.core.model.utils.DateFormat seems to use
the

% notation. Let me know if I'm wrong on this).

On 6 July 2012 12:48, Thomas Smyth thomas.smyth@gatech.edu wrote:

Thanks!

On 6 July 2012 12:37, Mitch S mitchellsundt@gmail.com wrote:

From the source code,

https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128

there are two functions that might be useful.

relevant="q176 < date('2012-07-06T14:00:00-0400')"

would convert the string to a date and compare it to the date.
This

is
probably preferable.

Or,

relevant="dateStr(q176,'yyy-MM-dd'T'hh:mm:ssZ') <
'2012-07-06T14:00:00-0400'"

would convert the date to a string and do a string compare. I'm
not

sure on
how to express the escaping of the single quote.

Mitch

On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth thomas.smyth@gatech.edu wrote:

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I can't
seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

You can only specify one relevant="" attribute. However, you can use the
AND construct to require two conditions to be both true (or use an OR
construct).

relevant="/data/q1=1 and /data/q3=1"

relevant="/data/q1=1 or /data/q3=1"

See http://opendatakit.org/help/form-design/binding/

Mitch

··· On Fri, Jul 13, 2012 at 2:41 AM, Mohammed Muntasir Nashiru < muntasirnashiru@gmail.com> wrote:

Hello,

I am having troubles trying to do specify two or more relevance expression
for one question. Example, if i had 4 questions, then wanted to make
specify a relevance for q4 like: < bind
nodeset="/data/q4" relevant="/data/q1=1" relevant="data/q3=1" type="string">

Please assist.

On Thu, Jul 12, 2012 at 7:41 PM, Mitch S mitchellsundt@gmail.com wrote:

Actually, the roundDate hack is to allow date calculations to work
correctly, so the fix should not be there.

Basically, the problem is that the Date values are hard to interpret
properly because JR emits them without any timezone information. So doing
tests for "same date as today" were problematic. the rounding hack was to
mostly handle this.

You probably want to define a new function like dateTimeDiff(arg1, arg2)
that would preserve the time. Probably adding this to DateUtils then adding
a new function to XPathFuncExpr.

This is a small enough change that if you attach the changed DateUtils
and XPathFuncExpr classes, I'll look at it and figure out where it would
go.

You should do your own build of ODK Collect with these changes, as I
don't know when I will fold them into a new release. I am shifting gears to
work on 2.0 planning and development. We'll be updating 1.2, but hopefully
at a slower pace than we have with 1.x

Mitch

On Thu, Jul 12, 2012 at 11:47 AM, Thomas Smyth thomas.smyth@gatech.eduwrote:

Ok that's good to know.

I found a fix for the time comparison stuff. On line 550 of
org.javarosa.xpath.expr.XPathFuncExpr.java, for some reason they're
rounding the date object, which kills the time values.

 DateUtils.roundDate((Date)o);

If I change this to just return o; it works fine. I can't imagine any
adverse effects of this, but I stand to be corrected..

The best way to write the xml then is like so:

    <bind nodeset="/data/q179" type="dateTime" />
    <bind nodeset="/data/q180" relevant="format-date(/data/q179,

'%Y%m%d%H%M') > '201207121200'" type="date" />

Should I check this in to the fork you mentioned? I can't believe
nobody has ever had to use this functionality before...

On 12 July 2012 14:35, Mitch S mitchellsundt@gmail.com wrote:

I put this in a bug report
http://code.google.com/p/opendatakit/issues/detail?id=630

FYI: ODK Collect 1.2 uses this fork of javarosa:
https://bitbucket.org/m.sundt/javarosa That fork is slightly updated
from
KoBo Collect's javarosa library -- for example, it removes the use of
static
variables for the secondary instance data, which breaks during
multithreaded
operations (such as in ODK Collect). It includes a new
round(value,decimalplace) function to simplify rounding (like in
Excel) and
it includes code to pass through all bind attributes and attributes on
the
question declarations. The later are primarily to support rapid
prototyping
by undergrads at the UW. These last changes are unlikely to find their
way
into the core JR code.

Mitch

On Thu, Jul 12, 2012 at 11:15 AM, Thomas Smyth < thomas.smyth@gatech.edu> wrote:

ALSO, datetime comparisons other than equals/not-equals aren't working
either.

I think this is because javarosa converts a Date to a number for these
comparisons, and it doesn't properly support datetime values. So the
time value is getting truncated and coming back as 0000. This also
explains the Time problem.

So I'm guessing that if I want this to work I'm going to have to do it
myself. Has anyone even touched the javarosa codebase in the last few
years? Yuck.

On 12 July 2012 14:05, Thomas Smyth thomas.smyth@gatech.edu wrote:

Update on this:

I got it to work for datetime and date (turns out I just should have
been putting /data/q179 instead of just q179.

But time doesn't work...

If I try for example:

relevant="format-date(/data/q181, '%H%M') &gt; '0830'"

internally, the format-date expression is returning "0000" instead
of

"1330" or whatever as it should be. (I found this out by putting
some

printlns in the javarosa core code.

So is this a bug? Or am I doing something wrong?

Note that doing it the other way, using "/data/q181 >
date('8:30')"

or something like that doesn't work since 8:30 doesn't work for the
date conversion function.

On 6 July 2012 13:32, Thomas Smyth thomas.smyth@gatech.edu wrote:

Hmm, none of these seem to be working. I tried:

and

and a variety of others. (Note that I think you meant format-date(
instead of dateStr( -- the latter is the Java function. Also the
date

formatter in org.javarosa.core.model.utils.DateFormat seems to use
the

% notation. Let me know if I'm wrong on this).

On 6 July 2012 12:48, Thomas Smyth thomas.smyth@gatech.edu wrote:

Thanks!

On 6 July 2012 12:37, Mitch S mitchellsundt@gmail.com wrote:

From the source code,

https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128

there are two functions that might be useful.

relevant="q176 < date('2012-07-06T14:00:00-0400')"

would convert the string to a date and compare it to the date.
This

is
probably preferable.

Or,

relevant="dateStr(q176,'yyy-MM-dd'T'hh:mm:ssZ') <
'2012-07-06T14:00:00-0400'"

would convert the date to a string and do a string compare. I'm
not

sure on
how to express the escaping of the single quote.

Mitch

On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth thomas.smyth@gatech.edu wrote:

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I can't
seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Thanks

··· On Fri, Jul 13, 2012 at 4:38 PM, Mitch S wrote:

You can only specify one relevant="" attribute. However, you can use the
AND construct to require two conditions to be both true (or use an OR
construct).

relevant="/data/q1=1 and /data/q3=1"

relevant="/data/q1=1 or /data/q3=1"

See http://opendatakit.org/help/form-design/binding/

Mitch

On Fri, Jul 13, 2012 at 2:41 AM, Mohammed Muntasir Nashiru < muntasirnashiru@gmail.com> wrote:

Hello,

I am having troubles trying to do specify two or more relevance
expression for one question. Example, if i had 4 questions, then wanted to
make specify a relevance for q4 like: < bind
nodeset="/data/q4" relevant="/data/q1=1" relevant="data/q3=1" type="string">

Please assist.

On Thu, Jul 12, 2012 at 7:41 PM, Mitch S mitchellsundt@gmail.com wrote:

Actually, the roundDate hack is to allow date calculations to work
correctly, so the fix should not be there.

Basically, the problem is that the Date values are hard to interpret
properly because JR emits them without any timezone information. So doing
tests for "same date as today" were problematic. the rounding hack was to
mostly handle this.

You probably want to define a new function like dateTimeDiff(arg1, arg2)
that would preserve the time. Probably adding this to DateUtils then adding
a new function to XPathFuncExpr.

This is a small enough change that if you attach the changed DateUtils
and XPathFuncExpr classes, I'll look at it and figure out where it would
go.

You should do your own build of ODK Collect with these changes, as I
don't know when I will fold them into a new release. I am shifting gears to
work on 2.0 planning and development. We'll be updating 1.2, but hopefully
at a slower pace than we have with 1.x

Mitch

On Thu, Jul 12, 2012 at 11:47 AM, Thomas Smyth thomas.smyth@gatech.eduwrote:

Ok that's good to know.

I found a fix for the time comparison stuff. On line 550 of
org.javarosa.xpath.expr.XPathFuncExpr.java, for some reason they're
rounding the date object, which kills the time values.

 DateUtils.roundDate((Date)o);

If I change this to just return o; it works fine. I can't imagine any
adverse effects of this, but I stand to be corrected..

The best way to write the xml then is like so:

    <bind nodeset="/data/q179" type="dateTime" />
    <bind nodeset="/data/q180" relevant="format-date(/data/q179,

'%Y%m%d%H%M') > '201207121200'" type="date" />

Should I check this in to the fork you mentioned? I can't believe
nobody has ever had to use this functionality before...

On 12 July 2012 14:35, Mitch S mitchellsundt@gmail.com wrote:

I put this in a bug report
http://code.google.com/p/opendatakit/issues/detail?id=630

FYI: ODK Collect 1.2 uses this fork of javarosa:
https://bitbucket.org/m.sundt/javarosa That fork is slightly
updated from
KoBo Collect's javarosa library -- for example, it removes the use of
static
variables for the secondary instance data, which breaks during
multithreaded
operations (such as in ODK Collect). It includes a new
round(value,decimalplace) function to simplify rounding (like in
Excel) and
it includes code to pass through all bind attributes and attributes
on the
question declarations. The later are primarily to support rapid
prototyping
by undergrads at the UW. These last changes are unlikely to find
their way
into the core JR code.

Mitch

On Thu, Jul 12, 2012 at 11:15 AM, Thomas Smyth < thomas.smyth@gatech.edu> wrote:

ALSO, datetime comparisons other than equals/not-equals aren't
working

either.

I think this is because javarosa converts a Date to a number for
these

comparisons, and it doesn't properly support datetime values. So the
time value is getting truncated and coming back as 0000. This also
explains the Time problem.

So I'm guessing that if I want this to work I'm going to have to do
it

myself. Has anyone even touched the javarosa codebase in the last few
years? Yuck.

On 12 July 2012 14:05, Thomas Smyth thomas.smyth@gatech.edu wrote:

Update on this:

I got it to work for datetime and date (turns out I just should
have

been putting /data/q179 instead of just q179.

But time doesn't work...

If I try for example:

relevant="format-date(/data/q181, '%H%M') &gt; '0830'"

internally, the format-date expression is returning "0000" instead
of

"1330" or whatever as it should be. (I found this out by putting
some

printlns in the javarosa core code.

So is this a bug? Or am I doing something wrong?

Note that doing it the other way, using "/data/q181 >
date('8:30')"

or something like that doesn't work since 8:30 doesn't work for the
date conversion function.

On 6 July 2012 13:32, Thomas Smyth thomas.smyth@gatech.edu wrote:

Hmm, none of these seem to be working. I tried:

and

and a variety of others. (Note that I think you meant format-date(
instead of dateStr( -- the latter is the Java function. Also the
date

formatter in org.javarosa.core.model.utils.DateFormat seems to
use the

% notation. Let me know if I'm wrong on this).

On 6 July 2012 12:48, Thomas Smyth thomas.smyth@gatech.edu wrote:

Thanks!

On 6 July 2012 12:37, Mitch S mitchellsundt@gmail.com wrote:

From the source code,

https://bitbucket.org/javarosa/javarosa/src/tip/core/src/org/javarosa/xpath/expr/XPathFuncExpr.java#cl-128

there are two functions that might be useful.

relevant="q176 < date('2012-07-06T14:00:00-0400')"

would convert the string to a date and compare it to the date.
This

is
probably preferable.

Or,

relevant="dateStr(q176,'yyy-MM-dd'T'hh:mm:ssZ') <
'2012-07-06T14:00:00-0400'"

would convert the date to a string and do a string compare. I'm
not

sure on
how to express the escaping of the single quote.

Mitch

On Fri, Jul 6, 2012 at 9:00 AM, Thomas Smyth thomas.smyth@gatech.edu wrote:

Does anyone know the syntax for comparing dates in a relevance
expression? I've tried several incantations of xpath but I
can't

seem
to get it to work.

Currently I have something like this:

relevant="q176 < '2012-07-06T14:00:00-0400'"

But it's obviously not working.

Thanks

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com