示例#1
0
        /// <summary>
        /// Convert input time to Berlin Clock
        /// </summary>
        /// <param name="timeSpan">Time span</param>
        /// <param name="berlinClockViewFormat">View of Berlin clock</param>
        /// <param name="timeFormatProvider">Culture of time span convertation</param>
        /// <returns>Formatted Berlin Clock as string result</returns>
        public string ConvertTime(
            string timeSpan,
            IBerlinClockViewFormat berlinClockViewFormat,
            IFormatProvider timeFormatProvider = null)
        {
            if (string.IsNullOrEmpty(timeSpan))
            {
                throw new ArgumentException($"Argument {timeSpan} can't be null or empty");
            }
            if (berlinClockViewFormat == null)
            {
                throw new ArgumentNullException($"Argument {berlinClockViewFormat} can't be null");
            }

            IFormatProvider usedFormatProvider = timeFormatProvider ?? CultureInfo.InvariantCulture;
            TimeSpan        convertedTimeSpan;
            bool            parsed = TimeSpan.TryParse(timeSpan, usedFormatProvider, out convertedTimeSpan);

            if (!parsed)
            {
                throw new ArgumentException($"Argument {timeSpan} should be a time span and convertable to {typeof(TimeSpan)}");
            }

            return(this.GenerateTimeToViewFormat(convertedTimeSpan, berlinClockViewFormat));
        }
        public string ConvertTimeStringAndFormats_GetCorrectResultCases(
            string timeSpan, IBerlinClockViewFormat berlinClockViewFormat)
        {
            // Act
            string result = this._berlinClockTimeConverter.ConvertTime(timeSpan, berlinClockViewFormat);

            // Assert
            return(result);
        }
示例#3
0
        /// <summary>
        /// Convert input time to Berlin Clock
        /// </summary>
        /// <param name="timeSpan">Time span</param>
        /// <param name="berlinClockViewFormat">View of Berlin clock</param>
        /// <returns>Formatted Berlin Clock as string result</returns>
        public string ConvertTime(
            TimeSpan timeSpan,
            IBerlinClockViewFormat berlinClockViewFormat)
        {
            if (berlinClockViewFormat == null)
            {
                throw new ArgumentNullException($"Argument {berlinClockViewFormat} can't be null");
            }

            return(this.GenerateTimeToViewFormat(timeSpan, berlinClockViewFormat));
        }
        public void ConvertTimeSpanAndFormat_IncorrectCase_BerlinClockViewFormatNotCorrect()
        {
            TestDelegate testDelegate = () =>
            {
                // Arrange
                TimeSpan timeSpan = new TimeSpan();
                IBerlinClockViewFormat berlinClockViewFormat = null;

                // Act
                this._berlinClockTimeConverter.ConvertTime(timeSpan, berlinClockViewFormat);
            };

            // Assert
            Assert.Throws <ArgumentNullException>(testDelegate);
        }
示例#5
0
        private string GenerateTimeToViewFormat(
            TimeSpan timeSpan,
            IBerlinClockViewFormat berlinClockViewFormat)
        {
            int hour    = this.CalculateHour(timeSpan);
            int minutes = timeSpan.Minutes;
            int seconds = timeSpan.Seconds;

            BerlinClockModel berlinClockModel = new BerlinClockModel(
                evenSeconds: seconds % 2 == 0,
                countOf5Hours: hour / 5,
                countOfModHours: hour % 5,
                countOf5Minutes: minutes / 5,
                countOfModMinutes: minutes % 5
                );

            return(berlinClockViewFormat.MakeView(berlinClockModel));
        }