Yes, if you try to generate multiple document URIs during
the same request from fn:current-dateTime they will all have
the same exact time values.  Time is frozen during an XQuery
request.

   I mix both time and randomness to create unique URIs, like
the following.  This extracted code also has some handy time
normalization functions that may be generally useful.


xquery version '1.0-ml';

declare function local:dateTime-as-utc (
  $date as xs:dateTime
) as xs:dateTime
{
  fn:adjust-dateTime-to-timezone ($date, xs:dayTimeDuration ("PT0H"))
};


declare function local:current-as-utc (
) as xs:dateTime
{
 local:dateTime-as-utc (fn:current-dateTime())
};


declare function local:unique-doc-uri (
  $root as xs:string
) as xs:string
{
  fn:concat ($root, xdmp:strftime ("-%Y-%m-%d-%H-%M-%S-",
    local:current-as-utc()), (xdmp:random() mod 10000), ".xml")
};

for $i in (1 to 5)
return local:unique-doc-uri ("article")

=>

article-2013-05-29-21-05-30-4904.xml
article-2013-05-29-21-05-30-5570.xml
article-2013-05-29-21-05-30-111.xml
article-2013-05-29-21-05-30-7148.xml
article-2013-05-29-21-05-30-7944.xml

   Zero-filling the fractional seconds value is left as an
exercise for the reader, if it matters.


On May 29, 2013, at 5:15 PM, John Snelson <[email protected]> wrote:

> I think the number underneath is consistent, but the serialization is 
> changing according to the particular time. What about creating the 
> timestamp like this?
> 
> xs:string(
>   (current-dateTime() - xs:dateTime("0001-01-01T00:00:00.0Z"))
>     div xs:dayTimeDuration("PT0.000001S")
> )
> 
> John
> 
> On 29/05/13 17:07, Tim wrote:
>> Hi Folks,
>> 
>> I am using fn:current-dateTime() to create a unique timestamp for
>> creating archive filenames, e.g.,
>> 
>> *let **$dt*:= fn:/current-dateTime/() *cast as **xs:string*
>> *return */replace/(/substring/(*$dt*, 1, 22), "[:\-T\.]", "")
>> 
>> To make it truly unique I need to include part of the fraction of a
>> second, but I noticed that fn:current-dateTime() does not always  return
>> the same number of digits for fractions of a second.  I have seen
>> results with a range anywhere from 2 to 6 digits.  Is there a minimum
>> amount of digits that will be supplied in the fractions digits?
>> 
>> Thank you!
>> 
>> Tim Meagher
> 
> -- 
> John Snelson, Lead Engineer                    http://twitter.com/jpcs
> MarkLogic Corporation                         http://www.marklogic.com
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:[email protected]}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown




_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to