示例#1
0
        /// <summary>
        /// Formats the WTTTime object based on the WTT Format Type and Delimiter passed.
        /// </summary>
        /// <param name="Format">WTTFormatType to determine how the WTTTime object should be formatted</param>
        /// <param name="Delimiter">The hour / minute delimiter. Defaults to ":"</param>
        /// <returns></returns>
        public string FormatTime(WTTTimeFormat Format, string Delimiter)
        {
            if (string.IsNullOrEmpty(Delimiter))
            {
                Delimiter = Globals.UserSettings.GetValueByKey("TIMEDELIMITER").ToString();
            }
            CultureInfo Culture             = Globals.UserSettings.GetCultureInfo();
            char        HalfChar            = (char)Convert.ToInt32(Globals.UserSettings.GetValueByKey("TIMEHALFCHAR"), Culture);
            TimeSpan    TimeDifference      = this._WTTStartDate.AddSeconds(this._Seconds).Subtract(this._WTTStartDate);
            int         TotalDays           = (int)Math.Floor((decimal)TimeDifference.TotalDays);
            int         TotalHours          = (int)Math.Floor((decimal)TimeDifference.TotalHours);
            int         Hours               = (int)Math.Floor((decimal)TimeDifference.Hours);
            int         Minutes             = (int)Math.Floor((decimal)TimeDifference.Minutes);
            int         Seconds             = (int)Math.Floor((decimal)TimeDifference.Seconds);
            string      HalfMinuteCharacter = Seconds == 0 ? "" : HalfChar.ToString(Culture);
            string      DisplayMinutes      = Minutes.ToString(Culture).Length == 1 ? string.Format(Culture, @"0{0}", Minutes) : Minutes.ToString(Culture);

            if (Format == WTTTimeFormat.ShortFormat)
            {
                string DisplayTotalHours = TotalHours.ToString(Culture).Length == 1 ? string.Format(Culture, @"0{0}", TotalHours) : TotalHours.ToString(Culture);
                return(string.Format(Culture, @"{0}{1}{2}{3}", DisplayTotalHours, Delimiter, DisplayMinutes, HalfMinuteCharacter));
            }
            else
            {
                string DisplayHours = Hours.ToString(Culture).Length == 1 ? string.Format(Culture, @"0{0}", Hours) : Hours.ToString(Culture);
                string DisplayDays  = FormatDays(TotalDays); //Get the Day format.
                return(string.Format(Culture, @"{0}{1}{2}{3}{4}", DisplayDays, DisplayHours, Delimiter, DisplayMinutes, HalfMinuteCharacter));
            }
        }
示例#2
0
 public void WTTTime_Method_FormattedTime(int Input, WTTTimeFormat Format, string Delimiter, string ExpectedValue)
 {
     GroundFrame.Core.Timetables.WTTTime TestTime = new Core.Timetables.WTTTime(Input);
     Assert.Equal(ExpectedValue, TestTime.FormatTime(Format, Delimiter));
 }