Rev 89 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 89 | Rev 90 | ||
---|---|---|---|
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-05 |
6 | * Version 2024-04-16 |
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 331... | Line 331... | ||
331 | if ($version <= 2) { |
331 | if ($version <= 2) { |
332 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] RFC 4122 (Leach-Mealling-Salz) / DCE 1.1"); |
332 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] RFC 4122 (Leach-Mealling-Salz) / DCE 1.1"); |
333 | } else if (($version >= 3) && ($version <= 5)) { |
333 | } else if (($version >= 3) && ($version <= 5)) { |
334 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] RFC 4122 (Leach-Mealling-Salz)"); |
334 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] RFC 4122 (Leach-Mealling-Salz)"); |
335 | } else if (($version >= 6) && ($version <= 8)) { |
335 | } else if (($version >= 6) && ($version <= 8)) { |
336 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] RFC draft-ietf-uuidrev-rfc4122bis (Davis-Peabody-Leach)"); // TODO: When new RFC is published, replace the RFC number |
336 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] RFC 9562 (Davis-Peabody-Leach)"); |
337 | } else { |
337 | } else { |
338 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] Unknown RFC"); |
338 | echo sprintf("%-32s %s\n", "Variant:", "[0b10_] Unknown RFC"); |
339 | } |
339 | } |
340 | 340 | ||
341 | switch ($version) { |
341 | switch ($version) { |
Line 920... | Line 920... | ||
920 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
920 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
921 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
921 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
922 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
922 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
923 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
923 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
924 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
924 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
925 | if (checkdate($month, $day, $year) && (strpos($utc_time,'X') === false)) { |
925 | if ((strpos($utc_time,'X') === false) && checkdate($month, $day, $year)) { |
926 | $deviation = "(deviation -2ms..2ms)"; |
926 | $deviation = "(deviation -2ms..2ms)"; |
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"; |
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"; |
928 | 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)); |
929 | 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"); |
930 | 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 965... | Line 965... | ||
965 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
965 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
966 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
966 | str_pad("$hours",2,'0',STR_PAD_LEFT).':'. |
967 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
967 | str_pad("$minutes",2,'0',STR_PAD_LEFT).':'. |
968 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
968 | str_pad("$seconds",2,'0',STR_PAD_LEFT)."'". |
969 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
969 | str_pad("$milliseconds",3/*ms*/,'0',STR_PAD_LEFT); |
970 | if (checkdate($month, $day, $year) && (strpos($local_time,'X') === false)) { |
970 | if ((strpos($local_time,'X') === false) && checkdate($month, $day, $year)) { |
971 | $deviation = "(deviation -4ms..0ms)"; |
971 | $deviation = "(deviation -4ms..0ms)"; |
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"; |
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"; |
973 | 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)); |
974 | 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"); |
975 | 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"); |
Line 1636... | Line 1636... | ||
1636 | // Then: Sort block 4, nibbles from left to right |
1636 | // Then: Sort block 4, nibbles from left to right |
1637 | if ($hickelUuidVersion == 1) { |
1637 | if ($hickelUuidVersion == 1) { |
1638 | $year = $dt->format('Y'); |
1638 | $year = $dt->format('Y'); |
1639 | $block4 = substr($year, 2, 2).substr($year, 0, 2); // Example: 0x2420 = 2024 |
1639 | $block4 = substr($year, 2, 2).substr($year, 0, 2); // Example: 0x2420 = 2024 |
1640 | } else { |
1640 | } else { |
1641 | $variant = 0x8; // First nibble needs to be 0b10_ (0x8-0xB) for "RFC 4122bis". We use it to store 2 more random bits. |
1641 | $variant = 0x8; // First nibble needs to be 0b10_ (0x8-0xB) for RFC 9562. We use it to store 2 more random bits. |
1642 | $unused2bits = 0; // Cannot be used for random, because it would affect the sorting |
1642 | $unused2bits = 0; // Cannot be used for random, because it would affect the sorting |
1643 | $year = $dt->format('Y'); |
1643 | $year = $dt->format('Y'); |
1644 | $block4 = sprintf('%01x%03x', $variant + ($unused2bits & 0x3), $year); |
1644 | $block4 = sprintf('%01x%03x', $variant + ($unused2bits & 0x3), $year); |
1645 | } |
1645 | } |
1646 | 1646 |