6 * Converts milliseconds time mark into 00:00:00:000 format (QT native format)
\r
8 * @param int $miliSecTime A time format in miliseconds (e.g. 26070) 1000 = 1 second
\r
9 * @return String $qtTimeString A QT mark in 00:00:00:000 format
\r
11 static public function timeSamiToQt($miliSecTime)
\r
14 // milliseconds holder
\r
15 $myMiliSecTime = $miliSecTime;
\r
17 // basic constant knowledge, values in milliseconds
\r
18 $anHour = 3600000; // 60*60*1000
\r
19 $aMin = 60000; // 60*1000
\r
20 $aSec = 1000; // 1 * 1000
\r
22 // temp holders for to store equivalent hh, mm, sec, milisec
\r
26 //$myMsec = 0; /// not using it.!!!
\r
28 // initialize timeArray
\r
29 $timeArray = array();
\r
30 $timeArray['hour'] = '';
\r
31 $timeArray['min'] = '';
\r
32 $timeArray['sec'] = '';
\r
33 $timeArray['msec'] = '';
\r
35 // parsing millisecodns QT time format 00:00:00.000
\r
37 // is time mark at least an hour?
\r
38 if($miliSecTime>=$anHour)
\r
40 // get only the int value
\r
41 $myHours = intval($miliSecTime/$anHour);
\r
43 // set the tot milliseconds left after removing number of hour(s)
\r
44 $myMiliSecTime -= ($myHours*$anHour);
\r
46 // set the current hours add leading 0 if needed
\r
49 $timeArray['hour'] = '0'.$myHours;
\r
51 $timeArray['hour'] = ''.$myHours;
\r
54 $timeArray['hour'] = '00';
\r
57 // Is time mark at least a minute? or rather, how many minutes are left?
\r
58 if($myMiliSecTime>=$aMin-1)
\r
60 // get only the int value
\r
61 $myMins = intval($myMiliSecTime/$aMin);
\r
63 // set the milliseconds left after removing total of minute(s)
\r
64 $myMiliSecTime -= ($myMins*$aMin);
\r
66 // set the current minutes and add leading 0 if needed
\r
69 $timeArray['min'] = '0'.$myMins;
\r
71 $timeArray['min'] = ''. $myMins;
\r
74 $timeArray['min'] = '00';
\r
77 // does it have seconds, or rather, how many seconds are left
\r
78 if($myMiliSecTime>=$aSec)
\r
80 // get only the int value
\r
81 $mySec = intval($myMiliSecTime/$aSec);
\r
83 // set the milliseconds left after removing total of seconds
\r
84 $myMiliSecTime -= ($mySec*$aSec);
\r
86 // set the current number of seconds in time array, and add leading 0 if needed
\r
89 $timeArray['sec'] = '0'.$mySec;
\r
91 $timeArray['sec'] = ''.$mySec;
\r
94 $timeArray['sec'] = '00';
\r
97 // here a fix for adding leading zeros to milliseconds (e.g. 1=001, 10=010)
\r
98 if($myMiliSecTime>0)
\r
100 $tempMilliSec = 0 + (0.001 * $myMiliSecTime);
\r
101 $tempMilliSecArray = explode('.',$tempMilliSec); // split using '.' as separator
\r
102 $myMiliSecTimeString = ''. $tempMilliSecArray[1]; // get only the decimal value as a string
\r
104 // add one zero after the sting value if $myMiliSecTimeString has 2 character
\r
105 if (strlen($myMiliSecTimeString)==2)
\r
107 $myMiliSecTimeString .= '0';
\r
109 // add two zeros after the sting value if $myMiliSecTimeString has 1 character
\r
110 else if (strlen($myMiliSecTimeString)==1)
\r
112 $myMiliSecTimeString .= '00';
\r
115 // set millisecodns
\r
116 $timeArray['msec'] = $myMiliSecTimeString;
\r
118 $timeArray['msec'] = '000'; // no milliseconds left
\r
121 // concatenate values
\r
122 $qtTimeString = ''.$timeArray['hour'].':'.$timeArray['min'].':'.$timeArray['sec'].'.'.$timeArray['msec'];
\r
124 return $qtTimeString;
\r
126 } // end samiToQtTime()
\r
129 * Converts QT time to miliseconds format (Accepted by SAMI 1.0 and other CCformats)
\r
130 * @return int $samiTime Time in miliseconds format; 1000 = 1. sec
\r
131 * @param String $qtTime QT time Format; (e.g. "00:01:10.280")
\r
133 static public function timeQtToSami($qtTime)
\r
135 // Known patterns: 1, 2, or 3 decimals for millisecond definition
\r
136 $pattern_time_000 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})\]";
\r
137 $pattern_time_00 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})\]";
\r
138 $pattern_time_0 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{1})\]";
\r
139 $pattern_selected = '';
\r
141 // If pattern is 3 digit
\r
142 if(preg_match('/'.$pattern_time_000.'/',$qtTime))
\r
144 $pattern_selected = $pattern_time_000;
\r
146 // If pattern is 2 digit
\r
147 if(preg_match('/'.$pattern_time_00.'/',$qtTime))
\r
149 $pattern_selected = $pattern_time_00;
\r
151 // If pattern is 1 digit
\r
152 if(preg_match('/'.$pattern_time_0.'/',$qtTime))
\r
154 $pattern_selected = $pattern_time_0;
\r
157 $t1 = 0; // hours (e.g. [01])
\r
158 $t2 = 0; // minutes (e.g. [12])
\r
159 $t3 = 0; // seconds (e.g. [01.123])
\r
161 $qtTimeParts = split(':',$qtTime); // split QT time mark into an array
\r
163 $t1 += $qtTimeParts[0]; // adding hours
\r
164 $t2 += $qtTimeParts[1]; // adding minutes
\r
165 $t3 += $qtTimeParts[2]; // adding seconds and miliseconds
\r
167 // millisecond equivalents
\r
168 $t1 *= 3600000; // 1 hour = 60*60*1000
\r
169 $t2 *= 60000; // 1 minute = 60*1000
\r
170 $t3 *= 1000; // 1 second = 1*1000
\r
172 // get time in milliseconds
\r
173 $samiTime = $t1 + $t2 + $t3;
\r
177 } // end timeQtToSami()
\r
181 /********************************
\r
182 * still working on more time functions
\r
183 *********************************/
\r