home *** CD-ROM | disk | FTP | other *** search
- var min = 60;
- var hour = min*60;
- var day = hour*24;
-
- function getHours(time)
- {
- var index = time.indexOf(":");
-
- return time.slice(0, index);
- }
-
- function getMinutes(time)
- {
- var index = time.indexOf(":");
-
- return time.slice(index+1, 10);
- }
-
- function isPeriod(period)
- {
- var numExp = /^[0-9]+(s|m|d|h|$)$/
-
- return (period.search(numExp) != -1);
- }
-
- function isTime(time)
- {
- var index = time.indexOf(":");
-
- if (index<=0 || index==time.length-1)
- return false;
-
- if (time.indexOf(".")>=0)
- return false;
-
- var hours = time.slice(0, index);
- var mins = time.slice(index+1, 10);
-
- var numExp=/^[0-9]+$/
-
- if (hours<0||hours>23||mins<0||mins>59||hours.search(numExp)==-1||mins.search(numExp)==-1)
- return false;
-
- return true;
- }
-
- function toNicePeriod(period)
- {
- if (period==0)
- return 0;
- else if (period/day==Math.floor(period/day))
- return (period/day)+"d";
- else if (period/hour==Math.floor(period/hour))
- return (period/hour)+"h";
- else if (period/min==Math.floor(period/min))
- return (period/min)+"m";
- else
- return period+"s";
- }
-
- function fromNicePeriod(period)
- {
- var c = period.charAt(period.length-1);
-
- if (c=="d" || c=="h" || c=="m" || c=="s")
- period = period.substr(0, period.length-1);
-
- if (c=="d")
- return eval(period)*day;
- else if (c=="h")
- return eval(period)*hour;
- else if (c=="m")
- return eval(period)*min;
- else
- return eval(period);
- }
-
- function fromNiceTime(time)
- {
- var min = 60;
- var hour = min*60;
- var day = hour*24;
-
- return getHours(time)*hour+getMinutes(time)*min;
- }
-
- function toNiceTime(time)
- {
- var hours=Math.floor(time/hour);
- var mins=Math.floor((time-hours*hour)/min);
-
- if (hours<10)
- time="0"+hours+":";
- else
- time=hours+":";
-
- if (mins<10)
- time=time+"0"+mins;
- else
- time+=mins;
-
- return time;
- }
-