Rev 80 | Rev 82 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 80 | Rev 81 | ||
---|---|---|---|
Line 843... | Line 843... | ||
843 | // Example: 2088dc33-000d-8045-87e8-4849434b454c |
843 | // Example: 2088dc33-000d-8045-87e8-4849434b454c |
844 | // Block 4 |
844 | // Block 4 |
845 | $rnd2bits = hexdec(substr($uuid,16,1)) & 0x3; |
845 | $rnd2bits = hexdec(substr($uuid,16,1)) & 0x3; |
846 | $year = hexdec(substr($uuid,17,3)); |
846 | $year = hexdec(substr($uuid,17,3)); |
847 | // Block 3 |
847 | // Block 3 |
848 | $dayOfYear = hexdec(substr($uuid,13,3)); |
848 | $dayOfYear = hexdec(substr($uuid,13,3)); // 1..366 |
849 | $day = intval(getDateFromDay($year, $dayOfYear)->format('d')); |
849 | $day = (($dayOfYear < 1) || ($dayOfYear > 366)) ? "XX" : intval(getDateFromDay($year, $dayOfYear)->format('d')); |
850 | $month = intval(getDateFromDay($year, $dayOfYear)->format('m')); |
850 | $month = (($dayOfYear < 1) || ($dayOfYear > 366)) ? "XX" : intval(getDateFromDay($year, $dayOfYear)->format('m')); |
851 | // Block 2 |
851 | // Block 2 |
852 | $minuteOfDay = hexdec(substr($uuid,8,4)); |
852 | $minuteOfDay = hexdec(substr($uuid,8,4)); // 1..1440 |
853 | $minutes = $minuteOfDay % 60; |
853 | $minutes = (($minuteOfDay < 1) || ($minuteOfDay > 1440)) ? "XX" : ($minuteOfDay-1) % 60; |
854 | $hours = (int)floor($minuteOfDay / 60); |
854 | $hours = (($minuteOfDay < 1) || ($minuteOfDay > 1440)) ? "XX" : (int)floor(($minuteOfDay-1) / 60); |
855 | // Block 1 |
855 | // Block 1 |
856 | $rnd16bits = substr($uuid,0,4); |
856 | $rnd16bits = substr($uuid,0,4); |
857 | $millisecond8bits = hexdec(substr($uuid,4,2)); |
857 | $millisecond8bits = hexdec(substr($uuid,4,2)); |
858 | $milliseconds = round($millisecond8bits / 255 * 999); |
858 | $milliseconds = round($millisecond8bits / 255 * 999); |
859 | $seconds = hexdec(substr($uuid,6,2)); |
859 | $seconds = hexdec(substr($uuid,6,2)); |
Line 864... | Line 864... | ||
864 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
864 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
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 | 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"; |
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"; |
870 | echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad("".base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT)); |
871 | echo sprintf("%-32s %s\n", "Random 16 bits:", "[0x$rnd16bits] 0b".str_pad("".base_convert($rnd16bits, 16, 2), 16, '0', STR_PAD_LEFT)); |
871 | echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds"); |
872 | echo sprintf("%-32s %s\n", "Milliseconds:", "[0x".substr($uuid,4,2)."] $milliseconds"); |
872 | echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds"); |
873 | echo sprintf("%-32s %s\n", "Seconds:", "[0x".substr($uuid,6,2)."] $seconds"); |
873 | 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).")"); |
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).")"); |
874 | echo sprintf("%-32s %s\n", "Day of year:", "[0x".substr($uuid,13,3)."] $dayOfYear (Day=$day, Month=$month)"); |
875 | echo sprintf("%-32s %s\n", "Day of year:", "[0x".substr($uuid,13,3)."] $dayOfYear (Day=$day, Month=$month)"); |
875 | echo sprintf("%-32s %s\n", "Random 2 bits:", "[$rnd2bits] 0b".str_pad("".base_convert("$rnd2bits", 16, 2), 2, '0', STR_PAD_LEFT)); |
876 | echo sprintf("%-32s %s\n", "Random 2 bits:", "[$rnd2bits] 0b".str_pad("".base_convert("$rnd2bits", 16, 2), 2, '0', STR_PAD_LEFT)); |
876 | echo sprintf("%-32s %s\n", "Year:", "[0x".substr($uuid,17,3)."] $year)"); |
877 | echo sprintf("%-32s %s\n", "Year:", "[0x".substr($uuid,17,3)."] $year)"); |
877 | echo sprintf("%-32s %s\n", "Signature:", "[0x".substr($uuid,20,12)."] HICKEL"); |
878 | echo sprintf("%-32s %s\n", "Signature:", "[0x".substr($uuid,20,12)."] HICKEL"); |
878 | echo sprintf("%-32s %s\n", "UTC Date Time:", $utc_time); |
879 | echo sprintf("%-32s %s\n", "UTC Date Time:", $utc_time); |
- | 880 | } |
|
879 | } else if (strtolower($signature) == '000000000000') { |
881 | } else if (strtolower($signature) == '000000000000') { |
880 | // HickelSOFT "SQL Server sortable UUID in C#" |
882 | // HickelSOFT "SQL Server sortable UUID in C#" |
881 | // Version 1: Resolution of 1 milliseconds, random part of 16 bits, local timezone, NOT UUIDv8 conform. |
883 | // Version 1: Resolution of 1 milliseconds, random part of 16 bits, local timezone, NOT UUIDv8 conform. |
882 | // Example: ff38da51-1301-0903-2420-000000000000 |
884 | // Example: ff38da51-1301-0903-2420-000000000000 |
883 | // Block 4 |
885 | // Block 4 |
884 | $year = substr($uuid,18,2) . substr($uuid,16,2); |
886 | $year = substr($uuid,18,2) . substr($uuid,16,2); |
885 | if (!is_numeric($year) || ($year < 2000) || ($year > 2999)) $year = 'XXXX'; else $year = intval($year); |
887 | $year = (!is_numeric($year) || ($year < 2000) || ($year > 2999)) ? "XXXX" : $year = intval($year); |
886 | // Block 3 |
888 | // Block 3 |
887 | $day = substr($uuid,12,2); |
889 | $day = substr($uuid,12,2); |
888 | if (!is_numeric($day) || ($day < 0) || ($day >= 60)) $day = 'XX'; else $day = intval($day); |
890 | $day = (!is_numeric($day) || ($day < 0) || ($day >= 60)) ? "XX" : intval($day); |
889 | $month = substr($uuid,14,2); |
891 | $month = substr($uuid,14,2); |
890 | if (!is_numeric($month) || ($month < 0) || ($month >= 60)) $month = 'XX'; else $month = intval($month); |
892 | $month = (!is_numeric($month) || ($month < 0) || ($month >= 60)) ? "XX" : intval($month); |
891 | // Block 2 |
893 | // Block 2 |
892 | $minutes = substr($uuid,8,2); |
894 | $minutes = substr($uuid,8,2); |
893 | if (!is_numeric($minutes) || ($minutes < 0) || ($minutes >= 60)) $minutes = 'XX'; else $minutes = intval($minutes); |
895 | $minutes = (!is_numeric($minutes) || ($minutes < 0) || ($minutes >= 60)) ? "XX" : intval($minutes); |
894 | $hours = substr($uuid,10,2); |
896 | $hours = substr($uuid,10,2); |
895 | if (!is_numeric($hours) || ($hours < 0) || ($hours >= 60)) $hours = 'XX'; else $hours = intval($hours); |
897 | $hours = (!is_numeric($hours) || ($hours < 0) || ($hours >= 60)) ? "XX" : intval($hours); |
896 | // Block 1 |
898 | // Block 1 |
897 | $rnd16bits = substr($uuid,0,4); |
899 | $rnd16bits = substr($uuid,0,4); |
898 | $millisecond8bits = hexdec(substr($uuid,4,2)); |
900 | $millisecond8bits = hexdec(substr($uuid,4,2)); |
899 | $milliseconds = round($millisecond8bits / 255 * 999); |
901 | $milliseconds = round($millisecond8bits / 255 * 999); |
900 | $seconds = substr($uuid,6,2); |
902 | $seconds = substr($uuid,6,2); |
901 | if (!is_numeric($seconds) || ($seconds < 0) || ($seconds >= 60)) $seconds = 'XX'; else $seconds = intval($seconds); |
903 | $seconds = (!is_numeric($seconds) || ($seconds < 0) || ($seconds >= 60)) ? "XX" : intval($seconds); |
902 | // Verbose info |
904 | // Verbose info |
903 | $local_time = |
905 | $local_time = |
904 | str_pad("$year",4,'0',STR_PAD_LEFT).'-'. |
906 | str_pad("$year",4,'0',STR_PAD_LEFT).'-'. |
905 | str_pad("$month",2,'0',STR_PAD_LEFT).'-'. |
907 | str_pad("$month",2,'0',STR_PAD_LEFT).'-'. |
906 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |
908 | str_pad("$day",2,'0',STR_PAD_LEFT).' '. |