Actually according to XQuery specs,  current-dateTime() is supposed to return 
the exact same value no matter how many times you call it in the same run.
http://www.w3.org/TR/xpath-functions/#func-current-dateTime

MarkLogic seems to implement this correctly:

fn:current-dateTime(),
xdmp:sleep(1000),
fn:current-dateTime()

returns the same value both time.


I suggest xdmp:random() be used to generate unique names.

Yes I know it might *possibly* return the same value twice, but the chance of 
that are much smaller then the entire system collapsing into a black hole,.





-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 812-482-5224
Cell:  +1 812-630-7622
www.marklogic.com



-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Michael Blakeley
Sent: Wednesday, May 29, 2013 12:23 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Creating a unique timestamp using 
fn:current-dateTime()

Keep in mind that a string like that won't have any guarantee of uniqueness. 
With a multicore system you could easily have two timestamps generated with the 
same value. What will your code do when that happens?

Some of the previous discussion of UUIDs might be helpful:

http://markmail.org/message/mql6teskkwb574na
http://markmail.org/message/lpnvzugqg2awu3h2

-- Mike

On 29 May 2013, at 09:15 , 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
> 

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

Reply via email to