Domanda

I am running a simple Xquery on an XML repository, Xhive, and am having trouble with the value being returned for a date:

Xquery:

for $x in document('')[matches(xhive:metadata(., "docato-name"),"THOCEO")][xhive:metadata(., "docato-type") = 'XML_RESOURCE_TYPE']
return
<file>
      <filename>{xhive:metadata($x, "docato-name")}</filename>
      <validated>{xhive:metadata($x,"Last Modified")}</validated>
</file>

Result:

<result>
    <file>
        <filename>THOCEO</filename>
        <validated>1375875821721</validated>
    </file>
</result>

I would like the "Last Modified" date returned as a formatted date as it appears in the repository: "2013-08-07 12:43:41" not as a string as above ("1375875821721")

I have tried amending the query to "{xs:date(xhive:metadata($x,"Last Modified"))}" but this fails with error:

query:8:19:XQUERY_ERROR_VALUE: casting error, cannot cast '1375875821721' from xdt:untypedAtomic to {http://www.w3.org/2001/XMLSchema}date (FORG0001: Invalid value for cast/constructor.)

Any help to return the "Last modified" date as a formated date would be much appreciated!

Thanks!

È stato utile?

Soluzione

Yes I would say using xhive:last-modified(...) is the easiest way, but if you really want to use the timestamp then here is something that I've used in the past:

declare function local:timestamp-to-dateTime($v) as xs:dateTime { 
  xs:dateTime("1970-01-01T00:00:00-00:00") + xs:dayTimeDuration(concat("PT", $v idiv 1000, "S"))
};

local:timestamp-to-dateTime(number("1375875821721"))

Altri suggerimenti

I'm not sure what that number represents or how to parse it, but you could try xhive:last-modified() instead, which returns xs:dateTime:

<validated>{ xhive:last-modified(fn:document-uri($x)) }</validated>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top