Merge branch 'MDL-71860-master' of git://github.com/lameze/moodle
[moodle.git] / lib / bennu / bennu.class.php
blobd5c7f414b549cfa067b1837c10a67209c03cb4a8
1 <?php
3 /**
4 * BENNU - PHP iCalendar library
5 * (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
7 * Released under the LGPL.
9 * See http://bennu.sourceforge.net/ for more information and downloads.
11 * @author Ioannis Papaioannou
12 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
15 class Bennu {
16 static function timestamp_to_datetime($t = NULL) {
17 if($t === NULL) {
18 $t = time();
20 return gmstrftime('%Y%m%dT%H%M%SZ', $t);
23 static function timestamp_to_date($t = NULL) {
24 if ($t === NULL) {
25 $t = time();
27 return gmstrftime('%Y%m%d', $t);
30 static function generate_guid() {
31 // Implemented as per the Network Working Group draft on UUIDs and GUIDs
33 // These two octets get special treatment
34 $time_hi_and_version = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits
35 $clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits
37 // Need another 14 random octects
38 $pool = '';
39 for($i = 0; $i < 7; ++$i) {
40 $pool .= sprintf('%04x', mt_rand(0, 65535));
43 // time_low = 4 octets
44 $random = substr($pool, 0, 8).'-';
46 // time_mid = 2 octets
47 $random .= substr($pool, 8, 4).'-';
49 // time_high_and_version = 2 octets
50 $random .= $time_hi_and_version.substr($pool, 12, 2).'-';
52 // clock_seq_high_and_reserved = 1 octet
53 $random .= $clock_seq_hi_and_reserved;
55 // clock_seq_low = 1 octet
56 $random .= substr($pool, 13, 2).'-';
58 // node = 6 octets
59 $random .= substr($pool, 14, 12);
61 return $random;