1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
use strict;
use warnings;
use Test::More;
use MyNote;
use UUID 'uuid1';
ok 1, 'loaded';
my $sys_time = time;
my $u0 = uuid1();
note $u0;
my @cluster = split /-/, $u0;
my $f0 = substr $cluster[2], 1;
my $f1 = $cluster[1];
my $f2 = $cluster[0];
my $val = join '', $f0, $f1, $f2;
note $val;
my $uid_time = 0;
while (length $val) {
my $c = ord substr $val, 0, 1, '';
$c -= 48;
$c -= 7 if $c > 9;
$c -= 32 if $c > 9;
$uid_time = 16 * $uid_time + $c;
}
# uuid gregorian time since 14whenever.
# clock_reg += (((U64)0x01b21dd2) << 32) + 0x13814000;
# 122,192,928,000,000,000
$uid_time = $uid_time / 10000000 - 12219292800;
note 'uid time ', $uid_time;
note 'sys time ', $sys_time;
# sys time may be larger than actual due to rounding.
cmp_ok $sys_time, '<=' , $uid_time+1, 'compare ok';
cmp_ok $sys_time - $uid_time, '<=', 2, 'interval ok';
# relaxing, this one seems to be a problem on the smokers.
cmp_ok $uid_time - $sys_time, '<=', 20, 'rollover ok';
done_testing;
|