home *** CD-ROM | disk | FTP | other *** search
- class Timer
- {
- var intTimer;
- var blnCountUp;
- var intStartTime;
- var intEndTime;
- var blnPaused;
- var intPauseStart;
- var intPauseTime;
- function Timer()
- {
- this.intTimer = 0;
- this.blnCountUp = true;
- this.intStartTime = 0;
- this.intEndTime = 0;
- this.blnPaused = false;
- this.intPauseStart = 0;
- this.intPauseTime = 0;
- }
- function Run()
- {
- if(this.blnPaused == false)
- {
- if(this.blnCountUp == true)
- {
- this.intTimer = getTimer() - this.intStartTime - this.intPauseTime;
- }
- else
- {
- this.intTimer = this.intEndTime - this.intStartTime - (getTimer() - this.intStartTime + this.intPauseTime);
- }
- }
- else
- {
- this.intPauseTime += getTimer() - this.intPauseStart;
- this.intPauseStart = getTimer();
- }
- }
- function Pause()
- {
- if(this.blnPaused == false)
- {
- this.blnPaused = true;
- this.intPauseStart = getTimer();
- }
- }
- function UnPause()
- {
- if(this.blnPaused == true)
- {
- this.intPauseTime += getTimer() - this.intPauseStart;
- this.blnPaused = false;
- }
- }
- function GetTime()
- {
- return this.intTimer;
- }
- function GetTimeString()
- {
- return this.MillisecondsToTimeString(this.intTimer);
- }
- function Start()
- {
- this.SetCountUp();
- }
- function SetCountUp()
- {
- this.blnCountUp = true;
- this.Reset();
- }
- function SetCountDown(durationInMilliseconds)
- {
- this.blnCountUp = false;
- this.intEndTime = getTimer() + durationInMilliseconds;
- this.Reset();
- }
- function Reset()
- {
- this.intStartTime = getTimer();
- this.blnPaused = false;
- this.intPauseStart = 0;
- this.intPauseTime = 0;
- if(this.blnCountUp == true)
- {
- this.intTimer = 0;
- }
- else
- {
- this.intTimer = this.intEndTime - this.intStartTime;
- }
- }
- function MillisecondsToTimeString(intMilliSecs)
- {
- var _loc5_ = intMilliSecs;
- var _loc4_ = Math.floor(_loc5_ / 1000);
- if(_loc4_ >= 60)
- {
- var _loc1_ = _loc5_ / 1000;
- var _loc3_ = _loc1_ / 60;
- if(_loc1_ > 59)
- {
- _loc1_ -= Math.floor(_loc3_) * 60;
- }
- var _loc6_ = undefined;
- var _loc2_ = undefined;
- if(_loc3_ < 10)
- {
- _loc2_ = "0" + Math.floor(_loc3_);
- }
- else
- {
- _loc2_ = "" + Math.floor(_loc3_);
- }
- if(_loc1_ < 10)
- {
- _loc6_ = _loc2_ + ":0" + Math.floor(_loc1_);
- }
- else if(_loc1_ == 0)
- {
- _loc6_ = _loc2_ + ":00";
- }
- else
- {
- _loc6_ = _loc2_ + ":" + Math.floor(_loc1_);
- }
- return _loc6_;
- }
- if(_loc4_ < 10)
- {
- _loc6_ = "00:0" + Math.floor(_loc4_);
- }
- else
- {
- _loc6_ = "00:" + Math.floor(_loc4_);
- }
- return _loc6_;
- }
- }
-