4 * http://opencaps.atrc.utoronto.ca
\r
6 * Copyright 2009 Antonio Gamba Bari
\r
7 * Adaptive Technology Resource Centre, University of Toronto
\r
9 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
10 * You may not use this file except in compliance with this License.
\r
11 * http://www.opensource.org/licenses/ecl2.php
\r
19 function __construct($t, $milli=true) {
\r
22 $this->formatted = $this->timeFormatted($t);
\r
24 $this->ms = $this->timeMilli($t);
\r
25 $this->formatted = $t;
\r
31 * Functions written by Antonio for the conversion service
\r
35 * Converts milliseconds time mark into 00:00:00:000 format (QT native format)
\r
37 * @param int $miliSecTime A time format in miliseconds (e.g. 26070) 1000 = 1 second
\r
38 * @return String $qtTimeString A QT mark in 00:00:00:000 format
\r
40 static public function timeFormatted($miliSecTime)
\r
43 // milliseconds holder
\r
44 $myMiliSecTime = $miliSecTime;
\r
46 // basic constant knowledge, values in milliseconds
\r
47 $anHour = 3600000; // 60*60*1000
\r
48 $aMin = 60000; // 60*1000
\r
49 $aSec = 1000; // 1 * 1000
\r
51 // temp holders for to store equivalent hh, mm, sec, milisec
\r
55 //$myMsec = 0; /// not using it.!!!
\r
57 // initialize timeArray
\r
58 $timeArray = array();
\r
59 $timeArray['hour'] = '';
\r
60 $timeArray['min'] = '';
\r
61 $timeArray['sec'] = '';
\r
62 $timeArray['msec'] = '';
\r
64 // parsing millisecodns QT time format 00:00:00.000
\r
66 // is time mark at least an hour?
\r
67 if($miliSecTime>=$anHour)
\r
69 // get only the int value
\r
70 $myHours = intval($miliSecTime/$anHour);
\r
72 // set the tot milliseconds left after removing number of hour(s)
\r
73 $myMiliSecTime -= ($myHours*$anHour);
\r
75 // set the current hours add leading 0 if needed
\r
78 $timeArray['hour'] = '0'.$myHours;
\r
80 $timeArray['hour'] = ''.$myHours;
\r
83 $timeArray['hour'] = '00';
\r
86 // Is time mark at least a minute? or rather, how many minutes are left?
\r
87 if($myMiliSecTime>=$aMin-1)
\r
89 // get only the int value
\r
90 $myMins = intval($myMiliSecTime/$aMin);
\r
92 // set the milliseconds left after removing total of minute(s)
\r
93 $myMiliSecTime -= ($myMins*$aMin);
\r
95 // set the current minutes and add leading 0 if needed
\r
98 $timeArray['min'] = '0'.$myMins;
\r
100 $timeArray['min'] = ''. $myMins;
\r
103 $timeArray['min'] = '00';
\r
106 // does it have seconds, or rather, how many seconds are left
\r
107 if($myMiliSecTime>=$aSec)
\r
109 // get only the int value
\r
110 $mySec = intval($myMiliSecTime/$aSec);
\r
112 // set the milliseconds left after removing total of seconds
\r
113 $myMiliSecTime -= ($mySec*$aSec);
\r
115 // set the current number of seconds in time array, and add leading 0 if needed
\r
118 $timeArray['sec'] = '0'.$mySec;
\r
120 $timeArray['sec'] = ''.$mySec;
\r
123 $timeArray['sec'] = '00';
\r
126 // here a fix for adding leading zeros to milliseconds (e.g. 1=001, 10=010)
\r
127 if($myMiliSecTime>0)
\r
129 $tempMilliSec = 0 + (0.001 * $myMiliSecTime);
\r
130 $tempMilliSecArray = explode('.',$tempMilliSec); // split using '.' as separator
\r
131 $myMiliSecTimeString = ''. $tempMilliSecArray[1]; // get only the decimal value as a string
\r
133 // add one zero after the sting value if $myMiliSecTimeString has 2 character
\r
134 if (strlen($myMiliSecTimeString)==2)
\r
136 $myMiliSecTimeString .= '0';
\r
138 // add two zeros after the sting value if $myMiliSecTimeString has 1 character
\r
139 else if (strlen($myMiliSecTimeString)==1)
\r
141 $myMiliSecTimeString .= '00';
\r
144 // set millisecodns
\r
145 $timeArray['msec'] = $myMiliSecTimeString;
\r
147 $timeArray['msec'] = '000'; // no milliseconds left
\r
150 // concatenate values
\r
151 $qtTimeString = ''.$timeArray['hour'].':'.$timeArray['min'].':'.$timeArray['sec'].'.'.$timeArray['msec'];
\r
153 return $qtTimeString;
\r
155 } // end samiToQtTime()
\r
158 * Converts QT time to milliseconds format (Accepted by SAMI 1.0 and other CCformats)
\r
159 * @return int $samiTime Time in miliseconds format; 1000 = 1. sec
\r
160 * @param String $qtTime QT time Format; (e.g. "00:01:10.280")
\r
162 static public function timeMilli($qtTime)
\r
164 // Known patterns: 1, 2, or 3 decimals for millisecond definition
\r
165 $pattern_time_000 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})\]";
\r
166 $pattern_time_00 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})\]";
\r
167 $pattern_time_0 = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{1})\]";
\r
168 $pattern_selected = '';
\r
170 // If pattern is 3 digit
\r
171 if(preg_match('/'.$pattern_time_000.'/',$qtTime))
\r
173 $pattern_selected = $pattern_time_000;
\r
175 // If pattern is 2 digit
\r
176 if(preg_match('/'.$pattern_time_00.'/',$qtTime))
\r
178 $pattern_selected = $pattern_time_00;
\r
180 // If pattern is 1 digit
\r
181 if(preg_match('/'.$pattern_time_0.'/',$qtTime))
\r
183 $pattern_selected = $pattern_time_0;
\r
186 $t1 = 0; // hours (e.g. [01])
\r
187 $t2 = 0; // minutes (e.g. [12])
\r
188 $t3 = 0; // seconds (e.g. [01.123])
\r
190 $qtTimeParts = explode(':',$qtTime); // split QT time mark into an array
\r
192 $t1 += $qtTimeParts[0]; // adding hours
\r
193 $t2 += $qtTimeParts[1]; // adding minutes
\r
194 $t3 += $qtTimeParts[2]; // adding seconds and miliseconds
\r
196 // millisecond equivalents
\r
197 $t1 *= 3600000; // 1 hour = 60*60*1000
\r
198 $t2 *= 60000; // 1 minute = 60*1000
\r
199 $t3 *= 1000; // 1 second = 1*1000
\r
201 // get time in milliseconds
\r
202 $samiTime = $t1 + $t2 + $t3;
\r