Add Duration to DateTime in XSLT

In XSLT, I want to convert an XML document to another. There are several dates and times in the old document that are not very easy to use. For instance:

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

Now I extracted all the information and was able to convert them 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 a while:

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

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

I already thought about adding individual components, but this is due to a lot of messing with the modules, for example, if I added 15 minutes to 23:50, and then I had to adjust the day accordingly, etc.

+4
source share
2 answers

Ok, now I found a function that was not referenced in the function that I used before.

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

This can also be written, for example:

 xs:dateTime($begin) + xs:dayTimeDuration($duration) 
+6
source

Just for completeness, there is also an implementation at http://www.exslt.org/date/functions/add/date.add.html

See a similar question in xslt - subtracting days

0
source

Source: https://habr.com/ru/post/1343338/


All Articles