-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubparser.class.php
81 lines (63 loc) · 2.3 KB
/
subparser.class.php
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
<?php
/**
* Parser napisów.
* @author: Wojciech.Bajon{gmail}
*/
class SubParser{
protected static $dateBase = '2000-01-01';
/**
* Convert formated time to timestamp with miliseconds
* @param: string $time eg: 00:01:20,700
* @param: char(1) $mDelim - miliseconds delim
* @return: double timestamp with miliseconds (not microseconds)
*/
public function time2stamp($time, $mDelim='.'){
$t = explode($mDelim, $time);
if(count($t)!=2)
throw new SubParserException('Time to stamp conversion error.');
$x = (strtotime(SubParser::$dateBase.' '.$t[0]) + ($t[1]/100));
//print "\n".$time.' '.date('G:i:s',floor($x)).' '.$x.' '.floor($x)."\n";
return $x;
}
/**
* Convert timestamp with miliseconds to time
* @param: double $stamp enchanted unix timestamp (double)
* @param: char(1) $mDelim - miliseconds delim
* @return: string time with miliseconds
*/
public function stamp2time($stamp, $mDelim='.'){
return date('G:i:s',
floor($stamp)).$mDelim.round(($stamp-floor($stamp))*100);
}
/**
* Calc time difference form 2 times. Used in: move time to time
* @param: string $current base time, eg: 00:01:20,700
* @param: string $target target time
* @return: double time difference - to add for time
*/
public function diffTime($current, $target){
return $this->time2stamp($target)-$this->time2stamp($current);
}
/**
* Add xx seconds to time.
* @param: string $current current time, eg: 00:01:20,700
* @param: double $add seconds.miliseconds to add to time.
* @return: string formated time
*/
public function add2Time($current, $add){
return $this->stamp2time($this->time2stamp($current) + $add);
}
/**
* Add xx seconds to timestamp.
* @param: double $current current timestamp
* @param: double $add seconds.miliseconds to add to time.
* @return: string formated time
*/
public function add2Stamp($current, $add){
return $this->stamp2time($current + $add);
}
/**
* Speacial equal - with equal range.
* @param: double $x seconds.miliseconds
*/
}