Ejemplo n.º 1
0
        public string calcularHorasVuelo(Aeronave aeronave, double kmDistancia)
        {
            double velocidad = double.Parse(aeronave.Kmh.Substring(0, aeronave.Kmh.Length - 5));
            double horavuelo = Math.Round(kmDistancia / velocidad, 1);

            Sesion.SetValue("horavuelo", horavuelo);
            decimal t  = Convert.ToDecimal(horavuelo);
            var     ts = TimeSpan.FromHours((double)t);

            if (ts.Hours.Equals(0) && ts.Minutes.ToString().Length == 1)
            {
                return(string.Format("0{0}", ts.Minutes));
            }
            if (ts.Hours.Equals(0))
            {
                return(string.Format("{0}", ts.Minutes));
            }
            else if (ts.Hours.ToString().Length == 1 && ts.Minutes.ToString().Length == 1)
            {
                return(string.Format("0{0}:0{1}", ts.Hours, ts.Minutes));
            }
            else if (ts.Hours.ToString().Length == 1)
            {
                return(string.Format("0{0}:{1}", ts.Hours, ts.Minutes));
            }
            else if (ts.Minutes.ToString().Length == 1)
            {
                return(string.Format("{0}:0{1}", ts.Hours, ts.Minutes));
            }
            else
            {
                return(string.Format("{0}:{1}", ts.Hours, ts.Minutes));
            }
        }
Ejemplo n.º 2
0
        public string calcularHoraLLegada()
        {
            double   horavuelo    = Sesion.GetValue <double>("horavuelo");
            string   horaPartida  = Sesion.GetValue <string>("horaPartida");
            double   horaLLegada  = Convert.ToDouble(horaPartida) + horavuelo;
            DateTime fechaPartida = Sesion.GetValue <DateTime>("fechaPartida");
            DateTime fechaLlegada = new DateTime();

            if (horaLLegada >= 24)
            {
                double  dias   = horaLLegada / 24;
                decimal d      = Convert.ToDecimal(dias);
                var     tsDias = TimeSpan.FromDays((double)d); // calcular cuanto dias pasaron
                fechaLlegada = fechaPartida.AddDays(tsDias.Days);
                Sesion.SetValue("fechaLlegada", fechaLlegada);
                horaLLegada = horaLLegada - 24;
                decimal h  = Convert.ToDecimal(horaLLegada);
                var     ts = TimeSpan.FromHours((double)h);
                if (ts.Hours.Equals(0) && ts.Minutes.ToString().Length == 1)
                {
                    return(string.Format("00:0{0}", ts.Minutes));
                }
                if (ts.Hours.Equals(0))
                {
                    return(string.Format("00:{0}", ts.Minutes));
                }
                else if (ts.Hours.ToString().Length == 1 && ts.Minutes.ToString().Length == 1)
                {
                    return(string.Format("0{0}:0{1}", ts.Hours, ts.Minutes));
                }
                else if (ts.Hours.ToString().Length == 1)
                {
                    return(string.Format("0{0}:{1}", ts.Hours, ts.Minutes));
                }
                else if (ts.Minutes.ToString().Length == 1)
                {
                    return(string.Format("{0}:0{1}", ts.Hours, ts.Minutes));
                }
                else
                {
                    return(string.Format("{0}:{1}", ts.Hours, ts.Minutes));
                }
            }
            else
            {
                fechaLlegada = fechaPartida;
                Sesion.SetValue("fechaLlegada", fechaLlegada);
                decimal h  = Convert.ToDecimal(horaLLegada);
                var     ts = TimeSpan.FromHours((double)h);
                if (ts.Hours.Equals(0) && ts.Minutes.ToString().Length == 1)
                {
                    return(string.Format("0{0}", ts.Minutes));
                }
                if (ts.Hours.Equals(0))
                {
                    return(string.Format("{0}", ts.Minutes));
                }
                else if (ts.Hours.ToString().Length == 1 && ts.Minutes.ToString().Length == 1)
                {
                    return(string.Format("0{0}:0{1}", ts.Hours, ts.Minutes));
                }
                else if (ts.Hours.ToString().Length == 1)
                {
                    return(string.Format("0{0}:{1}", ts.Hours, ts.Minutes));
                }
                else if (ts.Minutes.ToString().Length == 1)
                {
                    return(string.Format("{0}:0{1}", ts.Hours, ts.Minutes));
                }
                else
                {
                    return(string.Format("{0}:{1}", ts.Hours, ts.Minutes));
                }
            }
        }