Reputation: 45
Here is the format
<Record>
<DateTime>2012-11-11T17:06:54</DateTime>
<Description>Date1</Description>
</Record>
<Record>
<DateTime>2012-11-11T17:06:54</DateTime>
<Description>Date2</Description>
</Record>
<Record>
<DateTime>2000-09-29T15:28:08</DateTime>
<Description>Date3</Description>
</Record>
<Record>
<DateTime>29-11-2012T14:35:53</DateTime>
<Description>Date4</Description>
</Record>
<Record>
<DateTime>2000-09-29T15:28:10</DateTime>
<Description>Date5</Description>
</Record>
I want them to parse into dateTime formats at once without using formats like "YY:MM:dd"...
I used before this format but I can't debug or send output because the fourth Record tag has different format as you can see in the example above <DateTime>29-11-2012T14:35:53</DateTime>
.
Does anyone know how can I solve this.. in the Activity input I used
$duration=xsd:dateTime(DateTime[1])
format-dateTime($duration,"[Y0001]-[M01]-[D01]")
But it doesn't show me anything because of the <DateTime>29-11-2012T14:35:53</DateTime>
.
I want output similar to this:
<Calendar>
<Record>
<DateTime>2000-09-29T15:28:07</DateTime>
<Description>Date4</Description>
<Difference>6476 Days 8 Hours 18 Minutes 48 Seconds</Difference>
</Record>
</Calendar>
Upvotes: 2
Views: 876
Reputation: 66723
The xsd:dateTime()
function can only parse valid ISO 8601 dateTime formatted values.
You could test whether the value is castable as
xsd:dateTime
, and for those that are not, use a regex to test whether it matches known formats, and replace()
with a regex and capture groups to construct a properly formatted ISO 8601 formatted dateTime value that can be parsed as xsd:dateTime
:
if (DateTime castable as xsd:dateTime ) then
xsd:dateTime(DateTime)
else
if (matches(DateTime, '\d\d-\d\d-\d\d\d\dT.*')) then
xsd:dateTime(replace(DateTime, '(\d+)-(\d+)-(\d+)(T.*)', '$3-$2-$1$4'))
else ()
You could add additional if/else blocks with other dateTime patterns that you want to support.
Once you can construct xsd:dateTime
objects, then you can perform the desired calculations.
Upvotes: 1