File: v7.t

package info (click to toggle)
libuuid-perl 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,092 kB
  • sloc: ansic: 2,374; perl: 580; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
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
use strict;
use warnings;
use Test::More;
use MyNote;
use UUID 'uuid7';

ok 1, 'loaded';

my $sys_time = time;

my $u0 = uuid7();
note $u0;

my @cluster = split /-/, $u0;
my $f0 = $cluster[0];
my $f1 = $cluster[1];

my $val = join '', $f0, $f1;
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 / 1000;

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;