BF2Statistics.MedalData.Condition.Sec2hms C# (CSharp) Method

Sec2hms() public static method

Converts a Timespan of seconds into Hours, Minutes, and Seconds
public static Sec2hms ( int seconds ) : string
seconds int Seconds to convert
return string
        public static string Sec2hms(int seconds)
        {
            TimeSpan t = TimeSpan.FromSeconds(seconds);
            StringBuilder SB = new StringBuilder();
            char[] trim = new char[] { ',', ' ' };
            int Hours = t.Hours;

            // If we have more then 24 hours, then we need to
            // convert the days to hours
            if (t.Days > 0)
                Hours += t.Days * 24;

            // Format
            if (Hours > 0)
                SB.AppendFormat("{0} Hours, ", Hours);

            if (t.Minutes > 0)
                SB.AppendFormat("{0} Minutes, ", t.Minutes);

            if (t.Seconds > 0)
                SB.AppendFormat("{0} Seconds, ", t.Seconds);

            return SB.ToString().TrimEnd(trim);
        }

Usage Example

        /// <summary>
        /// Covnerts the conditions into a TreeNode
        /// </summary>
        /// <returns></returns>
        public override TreeNode ToTree()
        {
            string Name;
            string P2 = "";

            // Define start of description
            if (Params[0] == "global_stat")
            {
                Name = "Global " + StatsConstants.PythonGlobalVars[Params[1]];
            }
            else
            {
                Name = "Round " + StatsConstants.PythonPlayerVars[Params[1]];
            }

            // If we have 3 params, parse the last paramenter
            if (Params.Count == 3)
            {
                if (StatsConstants.IsTimeStat(Params[1]))
                {
                    P2 = Condition.Sec2hms(Int32.Parse(Params[2]));
                }
                else
                {
                    P2 = String.Format("{0:N0}", Int32.Parse(Params[2]));
                }

                Name += " Equal to or Greater Than " + P2;
            }

            TreeNode Me = new TreeNode(Name);

            Me.Tag = this;
            return(Me);
        }
All Usage Examples Of BF2Statistics.MedalData.Condition::Sec2hms