CommonClass.php
2.1 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @class CommonClass
* @brief Collection of some common function
* @details
*/
class CommonClass
{
/*
* @brief generate a random string
*/
public static function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++)
$randomString .= $characters[rand(0, strlen($characters) - 1)];
return $randomString;
}
/*
* @brief timestamp to DDTime conversion
*/
public static function timeStampToDDTime($timeStamp)
{
$y = date("Y",$timeStamp);
$d = date("z",$timeStamp);
if (strlen($d) == 0)
$d = "000";
else if (strlen($d) == 1)
$d = "00".$d;
else if (strlen($d) == 2)
$d = "0".$d;
$t = date("His",$timeStamp)."000";
return $y.$d.$t;
}
/*
* @brief DDTime to timestamp conversion
*/
public static function DDTimeToTimeStamp($DDTime)
{
date_default_timezone_set('UTC');
$date = DateTime::createFromFormat('YzHisu', $DDTime);
return strtotime($date->format("Y-m-d\TH:i:s"));
}
/*
* @brief DDTime to ISO conversion
*/
public static function DDTimeToIso($DDTime)
{
$date = DateTime::createFromFormat('YzHisu', $DDTime);
return $date->format("Y-m-d\TH:i:s");
}
/*
* @brief DDTime to ISO conversion
*/
public static function DDStartIntervalToStopIso($DDStart, $DDInterval)
{
$startStamp = self::DDTimeToTimeStamp($DDStart);
$intStamp = self::DDTimeToTimeStamp($DDInterval);
return date("Y-m-d\TH:i:s", $startStamp + $intStamp);
}
public static function rrmdir($dir)
{
if (is_dir($dir))
{
$objects = scandir($dir);
foreach ($objects as $object)
{ // Recursively delete a directory that is not empty and directorys in directory
if ($object != "." && $object != "..")
{ // If object isn't a directory recall recursively this function
if (filetype($dir."/".$object) == "dir")
self::rrmdir($dir."/".$object);
else
unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
}
?>