Rev 87 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 87 | Rev 89 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * UUID utils for PHP |
4 | * UUID utils for PHP |
5 | * Copyright 2011 - 2024 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2011 - 2024 Daniel Marschall, ViaThinkSoft |
6 | * Version 2024-04-03 |
6 | * Version 2024-04-05 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 813... | Line 813... | ||
813 | } |
813 | } |
814 | } |
814 | } |
815 | 815 | ||
816 | // END: OIDplus 2.0 Custom UUID Interpretation |
816 | // END: OIDplus 2.0 Custom UUID Interpretation |
817 | 817 | ||
- | 818 | // START: hayageek UUIDv8 Interpretation |
|
- | 819 | // https://github.com/hayageek/uuid-v8 |
|
- | 820 | // Example: 07e80404-1736-8934-8374-e63eb25babd2 |
|
- | 821 | ||
- | 822 | $year = hexdec(substr($uuid,0,4)); |
|
- | 823 | $month = hexdec(substr($uuid,4,2)); |
|
- | 824 | $day = hexdec(substr($uuid,6,2)); |
|
- | 825 | $hours = hexdec(substr($uuid,8,2)); |
|
- | 826 | $minutes = hexdec(substr($uuid,10,2)); |
|
- | 827 | $ver = hexdec(substr($uuid,12,1)); |
|
- | 828 | $rnd1 = substr($uuid,13,1); |
|
- | 829 | $seconds = hexdec(substr($uuid,14,2)); |
|
- | 830 | ||
- | 831 | // Diagram (WRONG): <2 variant 0b10> <8 msec> <6 random> |
|
- | 832 | // Actual Code: <2 variant 0b10> <2 zero> <12 msec 0..0x3E7> |
|
- | 833 | $tmp = hexdec(substr($uuid,16,4)); |
|
- | 834 | ||
- | 835 | $var = ($tmp >> 14) & 0b11; |
|
- | 836 | $zero = ($tmp >> 12) & 0b11; |
|
- | 837 | $milliseconds = $tmp & 0xFFF; |
|
- | 838 | ||
- | 839 | $rnd2 = substr($uuid,20,12); |
|
- | 840 | ||
- | 841 | $utc_time = |
|
- | 842 | str_pad("$year",4,'0',STR_PAD_LEFT).'-'. |
|
- | 843 | str_pad("$month",2,'0',STR_PAD_LEFT).'-'. |
|
- | 844 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
|
- | 845 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
|
- | 846 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
|
- | 847 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
|
- | 848 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
|
- | 849 | ||
- | 850 | $date_valid = checkdate($month, $day, $year); |
|
- | 851 | $time_valid = ($hours >= 0) && ($hours <= 23) && |
|
- | 852 | ($minutes >= 0) && ($minutes <= 59) && |
|
- | 853 | ($seconds >= 0) && ($seconds <= 59) && |
|
- | 854 | ($milliseconds >= 0) && ($milliseconds <= 999); /**@phpstan-ignore-line*/ |
|
- | 855 | ||
- | 856 | if (($ver == 8) && ($var == 2) && ($zero == 0) && $date_valid && $time_valid) { |
|
- | 857 | echo "\n<u>Interpretation of <a href=\"https://github.com/hayageek/uuid-v8\">hayageek UUIDv8</a></u>\n\n"; |
|
- | 858 | ||
- | 859 | echo sprintf("%-32s %s\n", "Date/Time:", "$utc_time UTC"); |
|
- | 860 | echo sprintf("%-32s %s\n", "Random Data:", "0x$rnd1$rnd2"); |
|
- | 861 | echo sprintf("%-32s %s\n", "Year:", sprintf("[0x%04x] %d", $year, $year)); |
|
- | 862 | echo sprintf("%-32s %s\n", "Month:", sprintf("[0x%02x] %d", $month, $month)); |
|
- | 863 | echo sprintf("%-32s %s\n", "Day:", sprintf("[0x%02x] %d", $day, $day)); |
|
- | 864 | echo sprintf("%-32s %s\n", "Hours:", sprintf("[0x%02x] %d", $hours, $hours)); |
|
- | 865 | echo sprintf("%-32s %s\n", "Minutes:", sprintf("[0x%02x] %d", $minutes, $minutes)); |
|
- | 866 | echo sprintf("%-32s %s\n", "Random 1:", sprintf("[0x%s]", $rnd1)); |
|
- | 867 | echo sprintf("%-32s %s\n", "Seconds:", sprintf("[0x%02x] %d", $seconds, $seconds)); |
|
- | 868 | echo sprintf("%-32s %s\n", "Milliseconds:", sprintf("[0x%03x] %d", $milliseconds, $milliseconds)); |
|
- | 869 | echo sprintf("%-32s %s\n", "Random 2:", sprintf("[0x%s]", $rnd2)); |
|
- | 870 | } |
|
- | 871 | ||
- | 872 | // END: hayageek UUIDv8 Interpretation |
|
- | 873 | ||
818 | break; |
874 | break; |
819 | default: |
875 | default: |
820 | echo sprintf("%-32s %s\n", "Version:", "[0x".dechex($version)."] Unknown"); |
876 | echo sprintf("%-32s %s\n", "Version:", "[0x".dechex($version)."] Unknown"); |
821 | break; |
877 | break; |
822 | } |
878 | } |
Line 864... | Line 920... | ||
864 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
920 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
865 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
921 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
866 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
922 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
867 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
923 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
868 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
924 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
869 | if (strpos($utc_time,'X') === false) { |
925 | if (checkdate($month, $day, $year) && (strpos($utc_time,'X') === false)) { |
870 | $deviation = "(deviation -2ms..2ms)"; |
926 | $deviation = "(deviation -2ms..2ms)"; |
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"; |
927 | 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"; |
872 | echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad("".base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT)); |
928 | echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad("".base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT)); |
873 | echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds $deviation"); |
929 | echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds $deviation"); |
874 | echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds"); |
930 | echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds"); |
Line 909... | Line 965... | ||
909 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
965 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
910 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
966 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
911 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
967 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
912 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
968 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
913 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
969 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
914 | if (strpos($local_time,'X') === false) { |
970 | if (checkdate($month, $day, $year) && (strpos($local_time,'X') === false)) { |
915 | $deviation = "(deviation -4ms..0ms)"; |
971 | $deviation = "(deviation -4ms..0ms)"; |
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"; |
972 | 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"; |
917 | echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad(base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT)); |
973 | echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad(base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT)); |
918 | echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds $deviation"); |
974 | echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds $deviation"); |
919 | echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds"); |
975 | echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds"); |