error with bind expression on dates

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

error with bind expression on dates

ilango_g
Hi
I am trying out the following bind to calculate a person's age:

<xforms:bind nodeset="instance('taskoutput')/fe:my_age" type="xs:integer" calculate="if((instance('taskoutput')/fe:my_dob) castable as xs:date) then (current-date() - xs:date(instance('taskoutput')/fe:my_dob)) div xdt:dayTimeDuration('P1D')
                                                                idiv 365.242199
                                                * xdt:yearMonthDuration('P1Y') else()"/>

my_dob -> my date of birth in xs:date format

When I run the code for a value of 01-01-1975 the result I get is:
P33Y.

I expect to see a number for "age" and what is this strange thing I see. Do I have to do a cast or something.

thanks for any suggestions
Reply | Threaded
Open this post in threaded view
|

Re: error with bind expression on dates

Hank Ratzesberger

Ilango,

If you have not tried the xpath sandbox, it really will help
you a long way.

The xdt: namespace is, I believe, deprecated and the
specification you want to look to for the function
names and types is:

http://www.w3.org/TR/xpath-functions/#duration-date-time-types

In any case, P33Y is an xs:yearMonthDuration.

I also have some difficulties with this function.

In the xpath sandbox, substituting '1960-02-29' for
your instance('taskoutput')/fe:my_dob)...

 - a basic if statement with parens:

if ( true() ) then (1) else (-1)

 - test that the value is a date:

if ( '1960-02-29' castable as xs:date  ) then ( 1 ) else (-1)

 - so far so good, now subtract date from current

if ( '1960-02-29' castable as xs:date  ) then
  ( current-date() - xs:date('1960-02-29') )
else
  (-1)

 - will yield P17598D now divide by a year...

if ( '1960-02-29' castable as xs:date  ) then
  ( (current-date() - xs:date('1960-02-29'))
    div xs:yearMonthDuration('P1Y') )
else
  (-1)

 - and I am stuck here.  In part, because when you subtract
dates, you get an xs:dayTimeDuration and I am unable to do
arithmetic on this with a xs:yearMonthDuration, even unable to
cast. xs:yearMonthDuration('P17598D') yields 'P0Y'

I really thought that these functions were intended to
handle these situations, but they come up short, or I
don't understand the necessary casting steps to make
this work.

Regards,
Hank



>
> Hi
> I am trying out the following bind to calculate a person's age:
>
> <xforms:bind nodeset="instance('taskoutput')/fe:my_age" type="xs:integer"
> calculate="if((instance('taskoutput')/fe:my_dob) castable as xs:date) then
> (current-date() - xs:date(instance('taskoutput')/fe:my_dob)) div
> xdt:dayTimeDuration('P1D')
> idiv 365.242199
> * xdt:yearMonthDuration('P1Y') else()"/>
>
> my_dob -> my date of birth in xs:date format
>
> When I run the code for a value of 01-01-1975 the result I get is:
> P33Y.
>
> I expect to see a number for "age" and what is this strange thing I see.
> Do
> I have to do a cast or something.
>
> thanks for any suggestions
> --
> View this message in context:
> http://www.nabble.com/error-with-bind-expression-on-dates-tp17071524p17071524.html
> Sent from the ObjectWeb OPS - Users mailing list archive at Nabble.com.
>
>



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws