[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

# RE: [xsl] time differences

 Subject: RE: [xsl] time differences From: Date: Mon, 25 Feb 2013 08:56:37 +0000

```Hi Michael,

In most cases the times will be less than 24 hours. Except when we are dealing
with events like Tour de France where the total time is compiled of the times
from each stage. So those times can be far more than 24 hours.

Thanks for the help. I will look into this shortly.

Trond

-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: 25. februar 2013 00:21
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] time differences

Andrew's solution will work just fine provided your time values are always
less than 24 hours, and provided you always subtract the smaller time from the
greater. If you do it the other way around, e.g. 00:00:02
- 00:00:03 the answer will be PT23H59M59S (if I remember correctly).

Also note that 1:15.28 is not a valid xs:time value; you need to expand it to
00:01:15.28.

Michael Kay
Saxonica

On 24/02/2013 12:17, Andrew Welch wrote:
> On 24 February 2013 11:58,  <trond.huso@xxxxxx> wrote:
>> Dear list,
>>
>> I have a need for calculating differences in times. The times are from
sporting events and are in these formats:
>> <Totaltime>1:15.28</Totaltime>
>> <Totaltime>1:15.69</Totaltime>
>> Here it means one minute, 15 seconds and 28 hundreds of a second (or
>> 69 hundreds of a second) so the difference here is 41 hundreds of a
>> second (0.48 as it would say in my output)
>>
>> The format could also be:
>> <Totaltime>1:10:15.28</Totaltime>
>> <Totaltime>1:11:15.69</Totaltime>
>> where the time means one hour, 11 minutes, 15 seconds and 28 (or 69)
>> hundreds of a second. The difference her should then be one minute
>> and 41 hundreds of a second (1:00.41)
>>
>> Up until now I have done this in an external function in a program (windows
service (daemon)) that is doing all conversions for us. Problem is that a new
structure of the service has stopped the external functions from working. I
will not go back to the old structure because the new structure made the
service faster.
>>
>> I am using Saxon for transformations, and I have been in contact with
>> Mr. Michael Kay regarding problems with external functions (thanks
>> for all the help!, but we have not found a solution. (dll with
>> external functions has been put in the GAC even without luck)
>>
>> A complete solution is not necessary (although it would be nice), but some
pointers towards which direction I should go - how to solve this - would help
me a lot.
> Here you go:
>
> http://www.w3.org/TR/xpath-functions/#durations-dates-times
>
> Turn your values into xs:times, then substract one from the other to
> get a xs:dayTimeDuration, then format or use the various extractor
> functions.

```