problem with time conversion

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

problem with time conversion

Alexander Žaťko
In my app I have a XSLT processor that prepares config XML for  
sql-processor. The stylesheet contains a piece of logic that converts  
the current datetime into miliseconds that passed since 1/1/1970. (I  
added the "line 181" text to tie this snippet with the error below):

                                 <xsl:apply-templates><!-- convert  
current date into milliseconds -->
                                     <xsl:with-param name="timestamp">
                                         <!-- express duration between  
current date and jan 1 1970 in format PxxxDTxxxHxxxMxxxS -->
                                         <xsl:variable name="dur">
                                             <xsl:value-of  
select='xs:dateTime(current-dateTime()) -  
xs:dateTime("1970-01-01T00:00:00")'/>
                                         </xsl:variable>
                                         <!-- convert variable dur into  
miliseconds -->
                                         <xsl:value-of  
select="1000*(60*(60*(24*xs:decimal(substring-before(substring-
after($dur, 'P'), 'D')) +
                                             
xs:decimal(substring-before(substring-after($dur, 'T'), 'H'))) +
                                             
xs:decimal(substring-before(substring-after($dur, 'H'), 'M'))) +
line 181                              
xs:decimal(substring-before(substring-after($dur, 'M'), 'S')))"/>
                                     </xsl:with-param>
                                 </xsl:apply-templates>


The code works most of the time, but every once a while OPS throws an  
exception like this:

2006-01-12 10:00:42,000 ERROR org.orbeon.oxf.pipeline.InitUtils null -  
Exception at oxf:/H3F/notice.xpl, line 181, column -1
; SystemID: oxf:/H3F/notice.xpl; Line#: 181; Column#: -1
org.orbeon.saxon.xpath.DynamicError: Cannot convert string "" to decimal
        at  
org.orbeon.saxon.expr.ComputedExpression.dynamicError(ComputedExpression
.java:465)
        at  
org.orbeon.saxon.expr.CastExpression.evaluateItem(CastExpression.java:
106)
        at  
org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateIte
m(ArithmeticExpression.java:386)
        at  
org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateIte
m(ArithmeticExpression.java:386)
        at  
org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateIte
m(ArithmeticExpression.java:376)
        at  
org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateIte
m(ArithmeticExpression.java:386)
        at  
org.orbeon.saxon.expr.ComputedExpression.iterate(ComputedExpression.java
:408)

Given that all input into this function is always present (right?) I  
have no clue what could ba causing this problem. Optionally, if there  
is a better method to generate this "miliseconds" string please let me  
know.

Alex.




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: problem with time conversion

Erik Bruchez
Administrator
Alex,

I would think that the error is not random, but due to incorrect input
data, because of what the error indicates. You may want to add types to
your XSLT variables (as="xs:integer", for example), which may allow you
to track down those errors earlier.

If you can identify one case that doesn't work and reproduce it, then
the solution should come out pretty easily.

-Erik

Alexander Zatko wrote:

> In my app I have a XSLT processor that prepares config XML for
> sql-processor. The stylesheet contains a piece of logic that converts
> the current datetime into miliseconds that passed since 1/1/1970. (I
> added the "line 181" text to tie this snippet with the error below):
>
>                                 <xsl:apply-templates><!-- convert
> current date into milliseconds -->
>                                     <xsl:with-param name="timestamp">
>                                         <!-- express duration between
> current date and jan 1 1970 in format PxxxDTxxxHxxxMxxxS -->
>                                         <xsl:variable name="dur">
>                                             <xsl:value-of
> select='xs:dateTime(current-dateTime()) -
> xs:dateTime("1970-01-01T00:00:00")'/>
>                                         </xsl:variable>
>                                         <!-- convert variable dur into
> miliseconds -->
>                                         <xsl:value-of
> select="1000*(60*(60*(24*xs:decimal(substring-before(substring-after($dur,
> 'P'), 'D')) +
>                                            
> xs:decimal(substring-before(substring-after($dur, 'T'), 'H'))) +
>                                            
> xs:decimal(substring-before(substring-after($dur, 'H'), 'M'))) +
> line 181                            
> xs:decimal(substring-before(substring-after($dur, 'M'), 'S')))"/>
>                                     </xsl:with-param>
>                                 </xsl:apply-templates>
>
>
> The code works most of the time, but every once a while OPS throws an
> exception like this:
>
> 2006-01-12 10:00:42,000 ERROR org.orbeon.oxf.pipeline.InitUtils null -
> Exception at oxf:/H3F/notice.xpl, line 181, column -1
> ; SystemID: oxf:/H3F/notice.xpl; Line#: 181; Column#: -1
> org.orbeon.saxon.xpath.DynamicError: Cannot convert string "" to decimal
>     at
> org.orbeon.saxon.expr.ComputedExpression.dynamicError(ComputedExpression.java:465)
>
>     at
> org.orbeon.saxon.expr.CastExpression.evaluateItem(CastExpression.java:106)
>     at
> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateItem(ArithmeticExpression.java:386)
>
>     at
> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateItem(ArithmeticExpression.java:386)
>
>     at
> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateItem(ArithmeticExpression.java:376)
>
>     at
> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateItem(ArithmeticExpression.java:386)
>
>     at
> org.orbeon.saxon.expr.ComputedExpression.iterate(ComputedExpression.java:408)
>
>
> Given that all input into this function is always present (right?) I
> have no clue what could ba causing this problem. Optionally, if there is
> a better method to generate this "miliseconds" string please let me know.
>
> Alex.



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: problem with time conversion

Alexander Žaťko
Erik,

The input to the variable is calculated from a static string  
"1970-01-01T00:00:00" and a value returned by current-dateTime()  
function. I can see that it works most of the time, so if the variable  
is receiving incorrect data - as you are proposing - then the only  
suspect is the current-dateTime() function. What makes you say that the  
error is not random?

I will try to type the variable.

Thanks

A.

On Jan 13, 2006, at 2:57 PM, Erik Bruchez wrote:

> Alex,
>
> I would think that the error is not random, but due to incorrect input  
> data, because of what the error indicates. You may want to add types  
> to your XSLT variables (as="xs:integer", for example), which may allow  
> you to track down those errors earlier.
>
> If you can identify one case that doesn't work and reproduce it, then  
> the solution should come out pretty easily.
>
> -Erik
>
> Alexander Zatko wrote:
>> In my app I have a XSLT processor that prepares config XML for  
>> sql-processor. The stylesheet contains a piece of logic that converts  
>> the current datetime into miliseconds that passed since 1/1/1970. (I  
>> added the "line 181" text to tie this snippet with the error below):
>>                                 <xsl:apply-templates><!-- convert  
>> current date into milliseconds -->
>>                                     <xsl:with-param name="timestamp">
>>                                         <!-- express duration between  
>> current date and jan 1 1970 in format PxxxDTxxxHxxxMxxxS -->
>>                                         <xsl:variable name="dur">
>>                                             <xsl:value-of  
>> select='xs:dateTime(current-dateTime()) -  
>> xs:dateTime("1970-01-01T00:00:00")'/>
>>                                         </xsl:variable>
>>                                         <!-- convert variable dur  
>> into miliseconds -->
>>                                         <xsl:value-of  
>> select="1000*(60*(60*(24*xs:decimal(substring-before(substring-
>> after($dur, 'P'), 'D')) +
>>                                              
>> xs:decimal(substring-before(substring-after($dur, 'T'), 'H'))) +
>>                                              
>> xs:decimal(substring-before(substring-after($dur, 'H'), 'M'))) +
>> line 181                              
>> xs:decimal(substring-before(substring-after($dur, 'M'), 'S')))"/>
>>                                     </xsl:with-param>
>>                                 </xsl:apply-templates>
>> The code works most of the time, but every once a while OPS throws an  
>> exception like this:
>> 2006-01-12 10:00:42,000 ERROR org.orbeon.oxf.pipeline.InitUtils null  
>> - Exception at oxf:/H3F/notice.xpl, line 181, column -1
>> ; SystemID: oxf:/H3F/notice.xpl; Line#: 181; Column#: -1
>> org.orbeon.saxon.xpath.DynamicError: Cannot convert string "" to  
>> decimal
>>     at  
>> org.orbeon.saxon.expr.ComputedExpression.dynamicError(ComputedExpressi
>> on.java:465)     at  
>> org.orbeon.saxon.expr.CastExpression.evaluateItem(CastExpression.java:
>> 106)
>>     at  
>> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateI
>> tem(ArithmeticExpression.java:386)     at  
>> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateI
>> tem(ArithmeticExpression.java:386)     at  
>> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateI
>> tem(ArithmeticExpression.java:376)     at  
>> org.orbeon.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateI
>> tem(ArithmeticExpression.java:386)     at  
>> org.orbeon.saxon.expr.ComputedExpression.iterate(ComputedExpression.ja
>> va:408) Given that all input into this function is always present  
>> (right?) I have no clue what could ba causing this problem.  
>> Optionally, if there is a better method to generate this  
>> "miliseconds" string please let me know.
>> Alex.
>
>
> --
> 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
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: problem with time conversion

Erik Bruchez
Administrator
Alexander Zatko wrote:
> Erik,
>
> The input to the variable is calculated from a static string
> "1970-01-01T00:00:00" and a value returned by current-dateTime()
> function. I can see that it works most of the time, so if the variable
> is receiving incorrect data - as you are proposing - then the only
> suspect is the current-dateTime() function. What makes you say that the
> error is not random?

Just the fact that usually, they are not ;-)

> I will try to type the variable.

And try also xsl:message to log the values such as the result of
current-dateTime(), to see if something out of the ordinary appears.

-Erik




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws