예제 #1
0
        public TimeConverter(ITimeParser timeParser, TimeValidator timeValidator)
        {
            _timeParser    = timeParser;
            _timeValidator = timeValidator;

            _lightParsers = new ITimePartParser[]
            {
                new TimePartParser(new List <string>
                {
                    LampState.Yellow
                }, time => time.Seconds % 2 == 0 ? 1 : 0),
                new TimePartParser(new List <string>
                {
                    LampState.Red, LampState.Red, LampState.Red, LampState.Red
                }, time => time.Hours / 5),
                new TimePartParser(new List <string>
                {
                    LampState.Red, LampState.Red, LampState.Red, LampState.Red
                }, time => time.Hours % 5),
                new TimePartParser(new List <string>
                {
                    LampState.Yellow, LampState.Yellow, LampState.Red,
                    LampState.Yellow, LampState.Yellow, LampState.Red,
                    LampState.Yellow, LampState.Yellow, LampState.Red,
                    LampState.Yellow, LampState.Yellow
                }, time => time.Minutes / 5),
                new TimePartParser(new List <string>
                {
                    LampState.Yellow, LampState.Yellow, LampState.Yellow, LampState.Yellow
                }, time => time.Minutes % 5)
            };
        }
예제 #2
0
 public TimeSpan Read(string timeToRead)
 {
     TimeValidator.Validate(timeToRead);
     if (timeToRead == Midnight)
     {
         return(new TimeSpan(24, 0, 0));
     }
     else
     {
         return(TimeSpan.Parse(DateTime.Parse(timeToRead).ToString(Format)));
     }
 }