OLE   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 8
Bugs 1 Features 0
Metric Value
wmc 4
c 8
b 1
f 0
lcom 0
cbo 0
dl 0
loc 57
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A asc2Ucs() 0 10 2
B localDate2OLE() 0 30 2
1
<?php
2
3
namespace Xls\OLE;
4
5
class OLE
6
{
7
    /**
8
     * Utility function to transform ASCII text to Unicode
9
     *
10
     * @param string $ascii The ASCII string to transform
11
     * @return string The string in Unicode
12
     */
13
    public static function asc2Ucs($ascii)
14
    {
15
        $rawname = '';
16
        $len = strlen($ascii);
17
        for ($i = 0; $i < $len; $i++) {
18
            $rawname .= $ascii{$i} . "\x00";
19
        }
20
21
        return $rawname;
22
    }
23
24
    /**
25
     * Returns a string for the OLE container with the date given
26
     *
27
     * @param integer $date A timestamp
28
     *
29
     * @return string The string for the OLE container
30
     */
31
    public static function localDate2OLE($date = null)
32
    {
33
        if (!isset($date)) {
34
            return str_repeat("\x00", 8);
35
        }
36
37
        // days from 1-1-1601 until the beggining of UNIX era
38
        $days = 134774;
39
        // calculate seconds
40
        $bigDate = $days * 24 * 3600 +
41
            gmmktime(
42
                date("H", $date),
43
                date("i", $date),
44
                date("s", $date),
45
                date("m", $date),
46
                date("d", $date),
47
                date("Y", $date)
48
            );
49
        $bigDate *= 10000000;
50
51
        // factor used for separating numbers into 4 bytes parts
52
        $factor = pow(2, 32);
53
54
        $div = $bigDate / $factor;
55
        $highPart = floor($div);
56
        // lower 4 bytes
57
        $lowPart = floor(($div - $highPart) * $factor);
58
59
        return pack('V2', $lowPart, $highPart);
60
    }
61
}
62