Subversion Repositories uuid_mac_utils

Rev

Rev 83 | Rev 85 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83 Rev 84
Line 865... Line 865...
865
                        str_pad("$hours",2,'0',STR_PAD_LEFT).':'.
865
                        str_pad("$hours",2,'0',STR_PAD_LEFT).':'.
866
                        str_pad("$minutes",2,'0',STR_PAD_LEFT).':'.
866
                        str_pad("$minutes",2,'0',STR_PAD_LEFT).':'.
867
                        str_pad("$seconds",2,'0',STR_PAD_LEFT)."'".
867
                        str_pad("$seconds",2,'0',STR_PAD_LEFT)."'".
868
                        str_pad("$milliseconds",2,'0',STR_PAD_LEFT);
868
                        str_pad("$milliseconds",2,'0',STR_PAD_LEFT);
869
                if (strpos($utc_time,'X') === false) {
869
                if (strpos($utc_time,'X') === false) {
-
 
870
                        $deviation = "(deviation -2ms..2ms)";
870
                        echo "\n<u>Interpretation of <a href=\"https://gist.github.com/danielmarschall/7fafd270a3bc107d38e8449ce7420c25\">HickelSOFT \"SQL Server Sortable Custom UUID\", Version 2</a></u>\n\n";
871
                        echo "\n<u>Interpretation of <a href=\"https://gist.github.com/danielmarschall/7fafd270a3bc107d38e8449ce7420c25\">HickelSOFT \"SQL Server Sortable Custom UUID\", Version 2</a></u>\n\n";
871
                        echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad("".base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT));
872
                        echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad("".base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT));
872
                        echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds");
873
                        echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds $deviation");
873
                        echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds");
874
                        echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds");
874
                        echo sprintf("%-32s %s\n", "Minute of day:", "[0x".substr($uuid,8,4)."] $minuteOfDay (".str_pad("$hours",2,'0',STR_PAD_LEFT).":".str_pad("$minutes",2,'0',STR_PAD_LEFT).")");
875
                        echo sprintf("%-32s %s\n", "Minute of day:", "[0x".substr($uuid,8,4)."] $minuteOfDay (".str_pad("$hours",2,'0',STR_PAD_LEFT).":".str_pad("$minutes",2,'0',STR_PAD_LEFT).")");
875
                        echo sprintf("%-32s %s\n", "Day of year:", "[0x".substr($uuid,13,3)."] $dayOfYear (Day=$day, Month=$month)");
876
                        echo sprintf("%-32s %s\n", "Day of year:", "[0x".substr($uuid,13,3)."] $dayOfYear (Day=$day, Month=$month)");
876
                        echo sprintf("%-32s %s\n", "Random 2 bits:", "[$rnd2bits] 0b".str_pad("".base_convert("$rnd2bits", 16, 2), 2, '0', STR_PAD_LEFT));
877
                        echo sprintf("%-32s %s\n", "Random 2 bits:", "[$rnd2bits] 0b".str_pad("".base_convert("$rnd2bits", 16, 2), 2, '0', STR_PAD_LEFT));
877
                        echo sprintf("%-32s %s\n", "Year:", "[0x".substr($uuid,17,3)."] $year");
878
                        echo sprintf("%-32s %s\n", "Year:", "[0x".substr($uuid,17,3)."] $year");
878
                        echo sprintf("%-32s %s\n", "Signature:", "[0x".substr($uuid,20,12)."] HickelSOFT \"SQL Server Sortable Custom UUID\", Version 2 (very likely)");
879
                        echo sprintf("%-32s %s\n", "Signature:", "[0x".substr($uuid,20,12)."] HickelSOFT \"SQL Server Sortable Custom UUID\", Version 2 (very likely)");
879
                        echo sprintf("%-32s %s\n", "UTC Date Time:", $utc_time);
880
                        echo sprintf("%-32s %s\n", "UTC Date Time:", "$utc_time $deviation");
880
                }
881
                }
881
        } else if (strtolower($signature) == '000000000000') {
882
        } else if (strtolower($signature) == '000000000000') {
882
                // HickelSOFT "SQL Server sortable UUID in C#"
883
                // HickelSOFT "SQL Server sortable UUID in C#"
883
                // Version 1: Resolution of 1 milliseconds, random part of 16 bits, local timezone, NOT UUIDv8 conform.
884
                // Version 1: Resolution of 1 milliseconds, random part of 16 bits, local timezone, NOT UUIDv8 conform.
884
                // Example: ff38da51-1301-0903-2420-000000000000
885
                // Example: ff38da51-1301-0903-2420-000000000000
Line 909... Line 910...
909
                        str_pad("$hours",2,'0',STR_PAD_LEFT).':'.
910
                        str_pad("$hours",2,'0',STR_PAD_LEFT).':'.
910
                        str_pad("$minutes",2,'0',STR_PAD_LEFT).':'.
911
                        str_pad("$minutes",2,'0',STR_PAD_LEFT).':'.
911
                        str_pad("$seconds",2,'0',STR_PAD_LEFT)."'".
912
                        str_pad("$seconds",2,'0',STR_PAD_LEFT)."'".
912
                        str_pad("$milliseconds",2,'0',STR_PAD_LEFT);
913
                        str_pad("$milliseconds",2,'0',STR_PAD_LEFT);
913
                if (strpos($local_time,'X') === false) {
914
                if (strpos($local_time,'X') === false) {
-
 
915
                        $deviation = "(deviation -4ms..0ms)";
914
                        echo "\n<u>Interpretation of <a href=\"https://gist.github.com/danielmarschall/7fafd270a3bc107d38e8449ce7420c25\">HickelSOFT \"SQL Server Sortable Custom UUID\", Version 1</a></u>\n\n";
916
                        echo "\n<u>Interpretation of <a href=\"https://gist.github.com/danielmarschall/7fafd270a3bc107d38e8449ce7420c25\">HickelSOFT \"SQL Server Sortable Custom UUID\", Version 1</a></u>\n\n";
915
                        echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad(base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT));
917
                        echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad(base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT));
916
                        echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds");
918
                        echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds $deviation");
917
                        echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds");
919
                        echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds");
918
                        echo sprintf("%-32s %s\n", "Minutes:", "[0x".substr($uuid,8,2)."] $minutes");
920
                        echo sprintf("%-32s %s\n", "Minutes:", "[0x".substr($uuid,8,2)."] $minutes");
919
                        echo sprintf("%-32s %s\n", "Hours:", "[0x".substr($uuid,10,2)."] $hours");
921
                        echo sprintf("%-32s %s\n", "Hours:", "[0x".substr($uuid,10,2)."] $hours");
920
                        echo sprintf("%-32s %s\n", "Day:", "[0x".substr($uuid,12,2)."] $day");
922
                        echo sprintf("%-32s %s\n", "Day:", "[0x".substr($uuid,12,2)."] $day");
921
                        echo sprintf("%-32s %s\n", "Month:", "[0x".substr($uuid,14,2)."] $month");
923
                        echo sprintf("%-32s %s\n", "Month:", "[0x".substr($uuid,14,2)."] $month");
922
                        echo sprintf("%-32s %s\n", "Year:", "[0x".substr($uuid,16,4)."] $year");
924
                        echo sprintf("%-32s %s\n", "Year:", "[0x".substr($uuid,16,4)."] $year");
923
                        echo sprintf("%-32s %s\n", "Signature:", "[0x".substr($uuid,20,12)."] HickelSOFT \"SQL Server Sortable Custom UUID\", Version 1 (maybe)");
925
                        echo sprintf("%-32s %s\n", "Signature:", "[0x".substr($uuid,20,12)."] HickelSOFT \"SQL Server Sortable Custom UUID\", Version 1 (maybe)");
924
                        echo sprintf("%-32s %s\n", "Generator's Local Date Time:", $local_time);
926
                        echo sprintf("%-32s %s\n", "Generator's Local Date Time:", "$local_time $deviation");
925
                }
927
                }
926
        }
928
        }
927
 
929
 
928
        // END: HickelSOFT UUID
930
        // END: HickelSOFT UUID
929
 
931
 
Line 1601... Line 1603...
1601
                $minuteOfDay = (intval($dt->format('i')) + intval($dt->format('h')) * 60) + 1; // 1..1440
1603
                $minuteOfDay = (intval($dt->format('i')) + intval($dt->format('h')) * 60) + 1; // 1..1440
1602
                $block2 = sprintf('%04x', $minuteOfDay);
1604
                $block2 = sprintf('%04x', $minuteOfDay);
1603
        }
1605
        }
1604
 
1606
 
1605
        // Then: Sort block 1, bytes from right to left
1607
        // Then: Sort block 1, bytes from right to left
1606
        $millisecond8bits = ceil(($dt->format('v') / 999) * 255);
-
 
1607
        if ($hickelUuidVersion == 1) {
1608
        if ($hickelUuidVersion == 1) {
-
 
1609
                $millisecond8bits = ceil(($dt->format('v') / 999) * 255); // deviation -4ms..0ms
1608
                $rnd16bits = _random_int(0x0000, 0xFFFF-1);
1610
                $rnd16bits = _random_int(0x0000, 0xFFFF-1);
1609
                $block1 = sprintf('%04x%02x', $rnd16bits, $millisecond8bits).$dt->format('s');
1611
                $block1 = sprintf('%04x%02x', $rnd16bits, $millisecond8bits).$dt->format('s');
1610
        } else {
1612
        } else {
-
 
1613
                $millisecond8bits = round(($dt->format('v') / 999) * 255); // deviation -2ms..2ms
1611
                $rnd16bits = _random_int(0x0000, 0xFFFF);
1614
                $rnd16bits = _random_int(0x0000, 0xFFFF);
1612
                $block1 = sprintf('%04x%02x%02x', $rnd16bits, $millisecond8bits, $dt->format('s'));
1615
                $block1 = sprintf('%04x%02x%02x', $rnd16bits, $millisecond8bits, $dt->format('s'));
1613
        }
1616
        }
1614
 
1617
 
1615
        // Now build and parse UUID
1618
        // Now build and parse UUID