Beispiel #1
0
        /// <summary>
        /// Formats a duration in minutes to a string
        /// </summary>
        /// <param name="hours"></param>
        /// <param name="minutes"></param>
        /// <returns></returns>
        public static string FormatDuration(int?totalMinutes)
        {
            if (totalMinutes != null)
            {
                int?toatalSeconds = totalMinutes * 60;

                int?          days         = Math.Floor(toatalSeconds / 86400);
                int?          hours        = Math.Floor((toatalSeconds % 86400) / 3600);
                int?          minutes      = Math.Floor(((toatalSeconds % 86400) % 3600) / 60);
                int?          seconds      = ((toatalSeconds % 86400) % 3600) % 60;
                List <string> formatString = new List <string>();
                if (days > 0)
                {
                    ArrayEx.Add(formatString, "{0}d");
                }

                if (hours > 0)
                {
                    ArrayEx.Add(formatString, "{1}h");
                }

                if (minutes > 0)
                {
                    ArrayEx.Add(formatString, "{2}m");
                }


                return(String.Format(ArrayEx.Join((Array)formatString, " "), days, hours, minutes));
            }
            else
            {
                return("");
            }
        }
        /// <summary>
        /// Formats a duration in minutes to a string
        /// </summary>
        /// <param name="hours"></param>
        /// <param name="minutes"></param>
        /// <returns></returns>
        public static string FormatDuration(int?totalMinutes)
        {
            if (totalMinutes != null)
            {
                int?toatalSeconds = totalMinutes * 60;

                int?          days         = Math.Floor(toatalSeconds / 86400);
                int?          hours        = Math.Floor((toatalSeconds % 86400) / 3600);
                int?          minutes      = Math.Floor(((toatalSeconds % 86400) % 3600) / 60);
                int?          seconds      = ((toatalSeconds % 86400) % 3600) % 60;
                List <string> formatString = new List <string>();
                if (days > 0)
                {
                    ArrayEx.Add(formatString, "{0}d");
                }

                if (hours > 0)
                {
                    ArrayEx.Add(formatString, "{1}h");
                }

                if (minutes > 0)
                {
                    ArrayEx.Add(formatString, "{2}m");
                }

                // LED: 9/26/2013: If days and hours are 0 and minutes are 0 we want to at least show 0m so the value can be editited.
                if (days == 0 && hours == 0 && minutes == 0)
                {
                    ArrayEx.Add(formatString, "{2}m");
                }

                return(String.Format(ArrayEx.Join((Array)formatString, " "), days, hours, minutes));
            }
            else
            {
                return("");
            }
        }