aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bennu/bennu.class.php
blob: f4bb219afb1becedb636b6597654c526c4fbaf56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php // $Id: bennu.class.php,v 1.1 2006/04/13 05:10:24 jablko Exp $

/**
 *  BENNU - PHP iCalendar library
 *  (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
 *
 *  Released under the LGPL.
 *
 *  See http://bennu.sourceforge.net/ for more information and downloads.
 *
 * @author Ioannis Papaioannou 
 * @version $Id: bennu.class.php,v 1.1 2006/04/13 05:10:24 jablko Exp $
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */

class Bennu {
    function timestamp_to_datetime($t = NULL) {
        if($t === NULL) {
            $t = time();
        }
        return gmstrftime('%Y%m%dT%H%M%SZ', $t);
    }

    function generate_guid() {
        // Implemented as per the Network Working Group draft on UUIDs and GUIDs
    
        // These two octets get special treatment
        $time_hi_and_version       = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits
        $clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits
    
        // Need another 14 random octects
        $pool = '';
        for($i = 0; $i < 7; ++$i) {
            $pool .= sprintf('%04x', mt_rand(0, 65535));
        }
    
        // time_low = 4 octets
        $random  = substr($pool, 0, 8).'-';
    
        // time_mid = 2 octets
        $random .= substr($pool, 8, 4).'-';
    
        // time_high_and_version = 2 octets
        $random .= $time_hi_and_version.substr($pool, 12, 2).'-';
    
        // clock_seq_high_and_reserved = 1 octet
        $random .= $clock_seq_hi_and_reserved;
    
        // clock_seq_low = 1 octet
        $random .= substr($pool, 13, 2).'-';
    
        // node = 6 octets
        $random .= substr($pool, 14, 12);
    
        return $random;
    }
}

?>

© 2014-2024 Faster IT GmbH | imprint | privacy policy