Add a Duration to DateTime in XSLT

24,188

Okay, now I found a function that wasn't listed in the function reference that I used before.

add-dayTimeDuration-to-dateTime(xs:dateTime, xs:dayTimeDuration)

This could also be written, for example, as:

xs:dateTime($begin) + xs:dayTimeDuration($duration)
Share:
24,188
slhck
Author by

slhck

Video quality guy and researcher, PhD student in computer science. Founder/CEO of AVEQ. I offer personal consulting and help with video encoding, especially with FFmpeg. Send a mail to werner.robitza at gmail.com. More info on my website.

Updated on March 12, 2020

Comments

  • slhck
    slhck about 4 years

    In an XSLT, I want to convert an XML document to another one. The old document has some dates and times that aren't really easy to use. For example:

    <foo date="20110310" time="002000" duration="001500"/>
    

    Now I extracted all the information and was able to convert these to ISO 8601 dates:

    <xsl:variable name="begin" select='concat($begin_date_year, "-", $begin_date_month, "-", $begin_date_day, "T", $begin_time_hour, ":", $begin_time_minutes, ":", $begin_time_seconds)'/>
    --> $begin = 2011-03-10T00:20:00
    

    And for the duration:

    <xsl:variable name="duration" select='concat("PT", $dur_hour, ":", $dur_minutes, ":", $dur_seconds)'/>
    --> $duration = PT00:15:00
    

    How can I add the duration to the DateTime in order to find out the end (in a DateTime format)?

    I already thought about adding the individual components, but this would involve a lot of fiddling around with moduli, for example if I added 15 minutes to 23:50 and then had to adjust the day accordingly, etc.