예제 #1
0
        public void Time_TestLoadTime()
        {
            String hours = "00";
            String minutes = "00";
            String seconds = "00";
            String aTimeString = hours + ":" + minutes + ":" + seconds;
            Time aTime = new Time();
            aTime = Time.ConvertStringToTime(aTimeString);
            Assert.AreEqual(hours, aTime.hours);
            Assert.AreEqual(minutes, aTime.minutes);
            Assert.AreEqual(seconds, aTime.seconds);

            hours = "01";
            minutes = "00";
            seconds = "00";
            aTimeString = hours + ":" + minutes + ":" + seconds;
            aTime = Time.ConvertStringToTime(aTimeString);
            Assert.AreEqual(hours, aTime.hours);
            Assert.AreEqual(minutes, aTime.minutes);
            Assert.AreEqual(seconds, aTime.seconds);

            hours = "03";
            minutes = "01";
            seconds = "03";
            aTimeString = hours + ":" + minutes + ":" + seconds;
            aTime = Time.ConvertStringToTime(aTimeString);
            Assert.AreEqual(hours, aTime.hours);
            Assert.AreEqual(minutes, aTime.minutes);
            Assert.AreEqual(seconds, aTime.seconds);

            hours = "300";
            minutes = "59";
            seconds = "59";
            aTimeString = hours + ":" + minutes + ":" + seconds;
            aTime = Time.ConvertStringToTime(aTimeString);
            Assert.AreEqual(hours, aTime.hours);
            Assert.AreEqual(minutes, aTime.minutes);
            Assert.AreEqual(seconds, aTime.seconds);
        }
예제 #2
0
        public void Time_TestSumString()
        {
            String timeString1 = "00:00:00";
            String timeString2 = "00:00:00";
            String expectedSum = "00:00:00";
            Time time1 = new Time();
            Time time2 = new Time();
            Time timeES = new Time();
            time1 = Time.ConvertStringToTime(timeString1);
            time2 = Time.ConvertStringToTime(timeString2);
            timeES = Time.ConvertStringToTime(expectedSum);
            time1 = Time.TimeSum(time1,time2);
            Assert.AreEqual(timeES.hours,time1.hours);
            Assert.AreEqual(timeES.minutes, time1.minutes);
            Assert.AreEqual(timeES.seconds, time1.seconds);

            timeString1 = "00:00:59";
            timeString2 = "00:00:01";
            expectedSum = "00:01:00";
            time1 = Time.ConvertStringToTime(timeString1);
            time2 = Time.ConvertStringToTime(timeString2);
            timeES = Time.ConvertStringToTime(expectedSum);
            time1 = Time.TimeSum(time1, time2);
            Assert.AreEqual(timeES.hours, time1.hours);
            Assert.AreEqual(timeES.minutes, time1.minutes);
            Assert.AreEqual(timeES.seconds, time1.seconds);

            timeString1 = "00:59:59";
            timeString2 = "00:00:01";
            expectedSum = "01:00:00";
            time1 = Time.ConvertStringToTime(timeString1);
            time2 = Time.ConvertStringToTime(timeString2);
            timeES = Time.ConvertStringToTime(expectedSum);
            time1 = Time.TimeSum(time1, time2);
            Assert.AreEqual(timeES.hours, time1.hours);
            Assert.AreEqual(timeES.minutes, time1.minutes);
            Assert.AreEqual(timeES.seconds, time1.seconds);

            timeString1 = "99:48:59";
            timeString2 = "02:10:04";
            expectedSum = "101:59:03";
            time1 = Time.ConvertStringToTime(timeString1);
            time2 = Time.ConvertStringToTime(timeString2);
            timeES = Time.ConvertStringToTime(expectedSum);
            time1 = Time.TimeSum(time1, time2);
            Assert.AreEqual(timeES.hours, time1.hours);
            Assert.AreEqual(timeES.minutes, time1.minutes);
            Assert.AreEqual(timeES.seconds, time1.seconds);
        }
예제 #3
0
        public void Time_TestCheckTimeFormat()
        {
            String aTimeString = "00:00:00";
            Time aTime = new Time();
            Boolean res = Time.CheckTimeFormat(aTimeString,99);
            Assert.AreEqual(true, res);

            aTimeString = "00:00:10";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(true, res);

            aTimeString = "00:00:59";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(true, res);

            aTimeString = "00:00:60";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(false, res);

            aTimeString = "00:01:00";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(true, res);

            aTimeString = "00:59:00";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(true, res);

            aTimeString = "00:60:00";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(false, res);

            aTimeString = "01:00:00";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(true, res);

            aTimeString = "60:00:00";
            res = Time.CheckTimeFormat(aTimeString, 99);
            Assert.AreEqual(true, res);

            aTimeString = "100:00:00";
            res = Time.CheckTimeFormat(aTimeString,100);
            Assert.AreEqual(true, res);

            aTimeString = "1000:00:00";
            res = Time.CheckTimeFormat(aTimeString,100);
            Assert.AreEqual(true, res);

            aTimeString = "1000:01:00";
            res = Time.CheckTimeFormat(aTimeString,1000);
            Assert.AreEqual(true, res);

            aTimeString = "1000:01:01";
            res = Time.CheckTimeFormat(aTimeString,1000);
            Assert.AreEqual(true, res);
        }
예제 #4
0
        public void Time_TestLoadString()
        {
            String hours = "00";
            String minutes = "00";
            String seconds = "00";
            String expectedTimeString = hours + ":" + minutes + ":" + seconds;
            Time aTime = new Time();
            aTime.hours = hours;
            aTime.minutes = minutes;
            aTime.seconds = seconds;
            String aTimeString = Time.ConvertTimeToString(aTime);
            Assert.AreEqual(expectedTimeString, aTimeString);

            hours = "01";
            minutes = "01";
            seconds = "01";
            expectedTimeString = hours + ":" + minutes + ":" + seconds;
            aTime.hours = hours;
            aTime.minutes = minutes;
            aTime.seconds = seconds;
            aTimeString = Time.ConvertTimeToString(aTime);
            Assert.AreEqual(expectedTimeString, aTimeString);

            hours = "10";
            minutes = "10";
            seconds = "10";
            expectedTimeString = hours + ":" + minutes + ":" + seconds;
            aTime.hours = hours;
            aTime.minutes = minutes;
            aTime.seconds = seconds;
            aTimeString = Time.ConvertTimeToString(aTime);
            Assert.AreEqual(expectedTimeString, aTimeString);

            hours = "100";
            minutes = "59";
            seconds = "59";
            expectedTimeString = hours + ":" + minutes + ":" + seconds;
            aTime.hours = hours;
            aTime.minutes = minutes;
            aTime.seconds = seconds;
            aTimeString = Time.ConvertTimeToString(aTime);
            Assert.AreEqual(expectedTimeString, aTimeString);
        }
예제 #5
0
        public void Time_ConvertToLong()
        {
            String hours = "00";
            String minutes = "00";
            String seconds = "00";
            long h = Convert.ToInt64(hours);
            long m = Convert.ToInt64(minutes);
            long s = Convert.ToInt64(seconds);
            long res = h * 60 * 60 + m * 60 + s;
            String aTimeString = hours + ":" + minutes + ":" + seconds;
            Time time = new Time();
            time = Time.ConvertStringToTime(aTimeString);
            long value = Time.ConvertTimeToLong(time);
            Assert.AreEqual(res,value);

            hours = "999999";
            minutes = "59";
            seconds = "59";
            h = Convert.ToInt64(hours);
            m = Convert.ToInt64(minutes);
            s = Convert.ToInt64(seconds);
            res = h * 60 * 60 + m * 60 + s;
            aTimeString = hours + ":" + minutes + ":" + seconds;
            time = Time.ConvertStringToTime(aTimeString);
            value = Time.ConvertTimeToLong(time);
            Assert.AreEqual(res, value);
        }
예제 #6
0
        public void Time_ConvertToTime()
        {
            //Prepare values
            String hours = "0";
            String minutes = "00";
            String seconds = "00";
            long h = Convert.ToInt64(hours);
            long m = Convert.ToInt64(minutes);
            long s = Convert.ToInt64(seconds);
            long res = h * 60 * 60 + m * 60 + s;
            String aTimeString = hours + ":" + minutes + ":" + seconds;
            Time timeExpected = new Time();
            Time timeNew = new Time();

            //convert to long
            timeExpected = Time.ConvertStringToTime(aTimeString);
            long value = Time.ConvertTimeToLong(timeExpected);
            Assert.AreEqual(res, value);

            //convert to time
            timeNew = Time.ConvertLongToTime(value);
            Assert.AreEqual(timeExpected.hours, timeNew.hours);
            Assert.AreEqual(timeExpected.minutes, timeNew.minutes);
            Assert.AreEqual(timeExpected.seconds, timeNew.seconds);

            //Prepare values
            hours = "999999";
            minutes = "59";
            seconds = "59";
            h = Convert.ToInt64(hours);
            m = Convert.ToInt64(minutes);
            s = Convert.ToInt64(seconds);
            res = h * 60 * 60 + m * 60 + s;
            aTimeString = hours + ":" + minutes + ":" + seconds;
            timeExpected = new Time();
            timeNew = new Time();

            //convert to long
            timeExpected = Time.ConvertStringToTime(aTimeString);
            value = Time.ConvertTimeToLong(timeExpected);
            Assert.AreEqual(res, value);

            //convert to time
            timeNew = Time.ConvertLongToTime(value);
            Assert.AreEqual(timeExpected.hours, timeNew.hours);
            Assert.AreEqual(timeExpected.minutes, timeNew.minutes);
            Assert.AreEqual(timeExpected.seconds, timeNew.seconds);
        }
예제 #7
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
 public static string ConvertTimeToString(Time aTime)
 {
     string result = aTime.hours + ":" + aTime.minutes + ":" + aTime.seconds;
     return result;
 }
예제 #8
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
        public static Time TimeSum(Time time1, Time time2)
        {
            //return the sum of time1 and time2
            Time result = new Time();
            int sec1 = Convert.ToInt16(time1.seconds);
            int sec2 = Convert.ToInt16(time2.seconds);
            int min1 = Convert.ToInt16(time1.minutes);
            int min2 = Convert.ToInt16(time2.minutes);
            int h1 = Convert.ToInt16(time1.hours);
            int h2 = Convert.ToInt16(time2.hours);

            //Sum the seconds
            int sumSec = sec1 + sec2;
            int resMin = 0;
            if (sumSec>59)
            {
                sumSec = sumSec - 60;
                resMin = 1;
            }

            //Sum the minutes
            int sumMin = min1 + min2 + resMin;
            int resH=0;
            if (sumMin > 59)
            {
                sumMin = sumMin - 60;
                resH = 1;
            }

            //Sum the hours
            int sumH = h1 + h2 + resH;

            //Pass the seconds to string and add a 0 to the right is length=1;
            string aux = sumSec.ToString();
            if (aux.Length == 1)
            {
                aux = "0" + aux;
            }
            result.seconds = aux;

            //Pass the minutes to string and add a 0 to the right is length=1;
            aux = sumMin.ToString();
            if (aux.Length == 1)
            {
                aux = "0" + aux;
            }
            result.minutes = aux;

            //Pass the hours to string and add a 0 to the right is length=1;
            aux = sumH.ToString();
            if (aux.Length == 1)
            {
                aux = "0" + aux;
            }
            result.hours = aux;

            return result;
        }
예제 #9
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
 public static Double ConvertTimeToDouble(Time aTime)
 {
     long h = Convert.ToInt64(aTime.hours);
     long m = Convert.ToInt64(aTime.minutes);
     long s = Convert.ToInt64(aTime.seconds);
     double res = (double)((h * 3600) + (m * 60) + s)/3600;
     return res;
 }
예제 #10
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
 public static long ConvertTimeToLong(Time aTime)
 {
     long h = Convert.ToInt64(aTime.hours);
     long m = Convert.ToInt64(aTime.minutes);
     long s = Convert.ToInt64(aTime.seconds);
     long res = h * 60 * 60 + m * 60 + s;
     return res;
 }
예제 #11
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
        public static Time ConvertStringToTime(string aString)
        {
            //Convert a string to format hh:mm:ss. If error return an exception error.
            Boolean result = true;
            Time aTime = new Time();

            //Verify if both : exists
            Exception aExceptMissingTimeSep = new Exception("Missing time separators ':'");
            Exception aExceptBadHour = new Exception("Bad hour entry");
            Exception aExceptBadMinute = new Exception("Bad minute entry");
            Exception aExceptBadSecond = new Exception("Bad second entry");
            int first = aString.IndexOf(":");
            int second = aString.LastIndexOf(":");
            if ((first == -1) || (second == -1))
            {
                result = false;
                throw (aExceptMissingTimeSep);
            }

            if (result)
            {
                string hoursPart = aString.Substring(0, first);
                string minutesPart = aString.Substring(first + 1, second - hoursPart.Length - 1);
                string secondsPart = aString.Substring(second + 1, aString.Length - hoursPart.Length - 1 - minutesPart.Length - 1);

                try
                {
                    long hours = Convert.ToInt64(hoursPart);
                    result = true;
                }
                catch (Exception)
                {
                    result = false;
                    throw(aExceptBadHour);
                }

                if (result)
                {
                    try
                    {
                        int minutes = Convert.ToInt16(minutesPart);
                        if ((minutes >= 0) && (minutes < 60))
                            result = true;
                        else
                            result = false;
                    }
                    catch (Exception)
                    {
                        result = false;
                        throw(aExceptBadMinute);
                    }
                }

                if (result)
                {
                    try
                    {
                        int seconds = Convert.ToInt16(secondsPart);
                        if ((seconds >= 0) && (seconds < 60))
                            result = true;
                        else
                            result = false;
                    }
                    catch (Exception)
                    {
                        result = false;
                        throw (aExceptBadSecond);
                    }
                }

                if (result)
                {
                    aTime.hours = hoursPart;
                    aTime.minutes =minutesPart;
                    aTime.seconds =secondsPart;
                }
            }
            return aTime;
        }
예제 #12
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
        public static long ConvertStringTimeToLong(string aString)
        {
            long result;
            Time aTime=new Time();

            aTime = ConvertStringToTime(aString);
            result = ConvertTimeToLong(aTime);

            return result;
        }
예제 #13
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
        public static double ConvertStringTimeToDouble(string aString)
        {
            double result;
            Time aTime = new Time();

            aTime = ConvertStringToTime(aString);
            result = ConvertTimeToDouble(aTime);

            return result;
        }
예제 #14
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
        public static Time ConvertLongToTime(long value)
        {
            long h = value / 3600;
            long hMod = value % 3600;
            long m = hMod / 60;
            long s = hMod % 60;

            Time aTime = new Time();
            aTime.hours = h.ToString();
            aTime.minutes = m.ToString();
            if (aTime.minutes.Length == 1)
                aTime.minutes = "0" + aTime.minutes;
            aTime.seconds = s.ToString();
            if (aTime.seconds.Length == 1)
                aTime.seconds = "0" + aTime.seconds;

            return aTime;
        }
예제 #15
0
파일: Time.cs 프로젝트: ugeHidalgo/TrainIt
        public static string ConvertLongToStringTime(long aLong)
        {
            string result = "";
            Time aTime = new Time();

            aTime = ConvertLongToTime(aLong);
            result = ConvertTimeToString(aTime);

            return result;
        }