コード例 #1
0
            static void Main(string[] args)
            {
                BerlinClock berlinClock = new BerlinClock();

                Console.WriteLine(berlinClock.convertTime("13:15:40"));
                Console.ReadLine();
            }
コード例 #2
0
        public BerlinClock Run(DateTime time)
        {
            var dt = Convert.ToDateTime(time);

            var berlin = new BerlinClock();
            berlin.SingleMinutes = SingleMinutes(dt.Minute);
            berlin.FiveMinutes = FiveMinutes(dt.Minute);
            berlin.SingleHours = SingleHours(dt.Hour);
            berlin.FiveHours = FiveHours(dt.Hour);
            berlin.Seconds = Seconds(dt.Second);

            return berlin;
        }
コード例 #3
0
        public string ConvertTime(string aTime)
        {
            ValidateTime(aTime);

            var splitTime = aTime.Split(':');

            var hour   = Convert.ToInt32(splitTime[0]);
            var minute = Convert.ToInt32(splitTime[1]);
            var second = Convert.ToInt32(splitTime[2]);

            var berlinClock = new BerlinClock(hour, minute, second);

            return(berlinClock.GetBerlinTime());
        }
コード例 #4
0
        /// <inheritdoc/>
        public string ConvertTime(string aTime)
        {
            if (String.IsNullOrEmpty(aTime))
            {
                throw new ArgumentNullException("aTime");
            }

            Time time = Time.Parse(aTime);

            IClock <Time> clock = new BerlinClock();

            clock.Set(time);

            return(clock.ToString());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: mascor1331/BerlinClock
        public static void Main(string[] args)
        {
            String offIndicator = "O";

//			Customizations start
            Console.WriteLine("Press Enter to continue with default colors.");
            Console.WriteLine("Enter the color for off indicator. Default is O");
            string enteredOffInd = Console.ReadLine();

            if (!(enteredOffInd == null || enteredOffInd == String.Empty))
            {
                offIndicator = enteredOffInd;
            }
            Console.WriteLine("Enter the color for seconds indicator. Default is Y");
            string enteredSecInd = Console.ReadLine();

            Console.WriteLine("Enter the color for hours indicator. Default is R");
            string enteredHrInd = Console.ReadLine();

            Console.WriteLine("Enter the color for quarter hour indicator. Default is R");
            string enteredQtrInd = Console.ReadLine();

            Console.WriteLine("Enter the color for minutes indicator Default is Y");
            string enteredMinInd = Console.ReadLine();
//			Customizations end

            BerlinClock <String> bc = new BerlinClock <String> (offIndicator);

            //check whether to apply custom colors or run with default colors
            if (!(enteredSecInd == null || enteredSecInd == String.Empty))
            {
                bc.SecondsIndicator = enteredSecInd;
            }
            if (!(enteredHrInd == null || enteredHrInd == String.Empty))
            {
                bc.HoursIndicator = enteredHrInd;
            }
            if (!(enteredQtrInd == null || enteredQtrInd == String.Empty))
            {
                bc.QuarterIndicator = enteredQtrInd;
            }
            if (!(enteredMinInd == null || enteredMinInd == String.Empty))
            {
                bc.MinutesIndicator = enteredMinInd;
            }

            //instantiate TimeReader to read user's time input
            TimeReader tr     = new TimeReader();
            Boolean    isRead = false;          //flag variable indicated read status

            while (isRead == false)             // run until user enters time in correct format
            {
                try {
                    Console.WriteLine("Enter time e.g. 04/18/2017 12:00:00 PM, 11 am, 11:45 am, 5 pm, 11:59 PM");
                    String   enteredTime = Console.ReadLine();
                    DateTime timeValue   = Convert.ToDateTime(enteredTime);
                    Console.WriteLine("Interpreted time in HH:mm:ss format is {0}", timeValue.ToString("HH:mm:ss"));
                    String dateTimeString = timeValue.ToString("HH:mm:ss");
                    tr.readTime(dateTimeString);       //call to readTime function
                    isRead = true;                     //break out of while loop
                } catch (FormatException e) {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("An error has occured parsing the time. Please check your input and try again");
                    Console.WriteLine();
                    isRead = false;
                }
            }
            bc.buildClock(tr);              //call buildClock function to build the BerlinClock
            Console.Write("Output: ");
            Console.WriteLine(bc);          // Display the output in a single line as required
        }