Exemplo n.º 1
0
        public static string IduceVrijeme(IFirePlaySong song)
        {
            string default_end = "Z";

            int min = 0, sec = 0, millis = 0;

            //int index = -1;
            if (song.Trajanje.Contains("."))
            {
                int index = song.Trajanje.IndexOf(".");
                if (!(int.TryParse(new String(song.Trajanje.ToCharArray(), 0, index), out sec)))
                {
                    throw new IndexingErrorExeption("Index for dot missaligned");
                }
                if (!(int.TryParse(new String(song.Trajanje.ToCharArray(), index + 1, song.Trajanje.Length), out millis)))
                {
                    throw new IndexingErrorExeption("Index for dot missaligned");
                }

                if (sec > 59)
                {
                    min  = (int)(sec / 60);
                    sec -= (min * 60);
                    while (millis > 1000)
                    {
                        millis /= 10;
                    }
                    return(FPTime.Sum(new FPTime(song.Vrijeme), new FPTime(0, 0, 0, 0, min, sec, millis, default_end)).GetTimeString());
                }
            }
            else
            {
                if (!(int.TryParse(new String(song.Trajanje.ToCharArray(), 0, song.Trajanje.Length), out sec)))
                {
                    throw new IndexingErrorExeption("Index for dot missaligned");
                }
                if (sec > 59)
                {
                    min  = (int)(sec / 60);
                    sec -= (min * 60);
                    while (millis > 1000)
                    {
                        millis /= 10;
                    }
                    return(FPTime.Sum(new FPTime(song.Vrijeme), new FPTime(0, 0, 0, 0, min, sec, millis, default_end)).GetTimeString());
                }
            }


            return(string.Empty);
        }
Exemplo n.º 2
0
        public static string IduceVrijeme(FPTime time, string trajanje)
        {
            string default_end = "Z";

            /*int min = 0, sec = 0, millis = 0;
             * if (trajanje.Contains("."))
             * {
             *  try
             *  {
             *      int index = trajanje.IndexOf(".");
             *      if (index < 0) throw new IndexingErrorExeption("Index can't be less than zero");
             *      if (!(int.TryParse(new String(trajanje.ToCharArray(), 0, index), out sec))) throw new IndexingErrorExeption("Index for dot missaligned");
             *      if (!(int.TryParse(new String(trajanje.ToCharArray(), index + 1, trajanje.Length-index-1), out millis))) throw new IndexingErrorExeption("Index for dot missaligned");
             *  }
             *  catch
             *  {
             *      throw new Exception("WTF: trajanje" + trajanje + "   ::   vrijeme_string: " + time._theString);
             *  }
             *
             *  if (sec > 59)
             *  {
             *      min = (int)(sec / 60);
             *      sec -= (min * 60);
             *      while (millis > 1000) millis /= 10;
             *      return FPTime.Sum(time, new FPTime(2000, 0, 0, 0, min, sec, millis, default_end)).GetTimeString();
             *  }
             * }
             * else
             * {
             *  if (!(int.TryParse(new String(trajanje.ToCharArray(), 0, trajanje.Length), out sec))) throw new IndexingErrorExeption("Index for dot missaligned");
             *  if (sec > 59)
             *  {
             *      min = (int)(sec / 60);
             *      sec -= (min * 60);
             *      while (millis > 1000) millis /= 10;
             *  }
             *  return FPTime.Sum(time, new FPTime(0, 0, 0, 0, min, sec, millis, default_end)).GetTimeString();
             * }*/

            return(FPTime.Sum(time, new FPTime(2000, 1, 1, 0, 0, RegExTime.GetFromDuration(trajanje, RegExTime.REX.Seconds), RegExTime.GetFromDuration(trajanje, RegExTime.REX.Milliseconds), "Z")).GetTimeString());

            return(string.Empty);
        }
Exemplo n.º 3
0
 public static string IduceVrijeme(FPTime time, int sec, int millis)
 {
     return(FPTime.Sum(time, new FPTime(2000, 0, 0, 0, 0, sec, millis, "Z")).GetTimeString());
 }
Exemplo n.º 4
0
        public static FPTime Sum(FPTime a, FPTime b)
        {
            int    year, month, day, hours, minutes, seconds, milliseconds;
            string end;


            year         = a.Year > b.Year ? a.Year : b.Year;
            month        = a.Year > b.Year ? a.Month : (b.Year == a.Year ? (a.Month > b.Month ? a.Month : b.Month) : b.Month);
            day          = a.Year > b.Year ? a.Day : (b.Year == a.Year ? (a.Month > b.Month ? a.Day : (b.Month == a.Month ? (a.Day > b.Day ? a.Day : b.Day) : b.Day)) : b.Day);
            hours        = a.Hour + b.Hour;
            minutes      = a.Minutes + b.Minutes;
            seconds      = a.Seconds + b.Seconds;
            milliseconds = a.Milliseconds + b.Milliseconds;
            try
            {
                string temp_end = a.Ender.Length > b.Ender.Length ? a.Ender : b.Ender;
                end = temp_end == null ? "Z" : temp_end;
            }
            catch
            {
                throw new Exception("wtf again:" + a._theString + "  ______  " + b.Ender);
            }
            DateTime before = new DateTime(a.Year, a.Month, a.Day, a.Hour, a.Minutes, a.Seconds, a.Milliseconds, DateTimeKind.Local);

            if (milliseconds > 999)
            {
                milliseconds -= 1000; seconds++;
            }
            if (seconds > 59)
            {
                seconds -= 60; minutes++;
            }
            if (minutes > 59)
            {
                minutes -= 60; hours++;
            }
            if (hours > 23)
            {
                hours -= 24; day++;
            }
            if (day > 28)
            {
                if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && day > 31)
                {
                    day -= 31;
                    month++;
                }
                else if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30)
                {
                    day -= 30;
                    month++;
                }
                else if (month == 2 && day > 28)
                {
                    if (DateTime.IsLeapYear(year) && day > 29)
                    {
                        day -= 29;
                        month++;
                    }
                    else if (!DateTime.IsLeapYear(year) && day > 28)
                    {
                        day -= 28;
                        month++;
                    }
                }
                if (month > 12)
                {
                    month -= 12; year++;
                }
            }
            DateTime after = DateTime.Now;

            try
            {
                after = new DateTime(year, month, day, hours, minutes, seconds, milliseconds, DateTimeKind.Local);
            }
            catch
            {
                throw new Exception("Minute: " + minutes.ToString() + "  ::  Second: " + seconds.ToString());
            }

            if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(before) ^ TimeZone.CurrentTimeZone.IsDaylightSavingTime(after))
            {
                if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(before))
                {
                    hours--;
                }
                if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(after))
                {
                    hours++;
                }
            }
            return(new FPTime(year, month, day, hours, minutes, seconds, (a.milliseconds_flag && b.milliseconds_flag ? milliseconds / 10 : milliseconds), (a.milliseconds_flag && b.milliseconds_flag ? a.Ender : (a.Ender.Length > b.Ender.Length ? a.Ender : b.Ender))));
        }