Ejemplo n.º 1
0
        public override string ToString()
        {
            string cultureFirstDay      = DateRangeFactory.GetCultureDayFrom(this._firstDate, this._currentCulture);
            string cultureLastDay       = DateRangeFactory.GetCultureDayFrom(this._lastDate, this._currentCulture);
            string firstDateWithoutYear = DateRangeFactory.GetDateWithoutYearFrom(this._formatStyle, this._firstDate,
                                                                                  this._dateSeparator, this._currentCulture);

            // Date formats: YY(YYYY)-M(MM)-D(DD)
            bool dateStartsFromYear = DateRangeFactory.IsDateFormatBeginsFromYear(this._currentCulture);

            if (dateStartsFromYear)
            {
                return($"{this._firstDate.Year}{this._dateSeparator}{firstDateWithoutYear}{this._hyphen}{cultureLastDay}");
            }

            // Date formats: M(MM)-D(DD)-YY(YYYY)
            bool dateStartsFromMonth = DateRangeFactory.IsDateFormatBeginsFromMonth(this._currentCulture);

            if (dateStartsFromMonth)
            {
                return($"{this._firstDate.Month}{this._dateSeparator}{cultureFirstDay}{this._hyphen}" +
                       $"{cultureLastDay}{this._dateSeparator}{this._firstDate.Year}");
            }

            // Date formats: D(DD)-M(MM)-YY(YYYY)
            return($"{cultureFirstDay}{this._hyphen}{this._lastDate.ToString(this._formatStyle, this._currentCulture)}");
        }
        public void Start(string[] inputArray)
        {
            CultureInfo currentCulture = CultureInfo.CurrentCulture;

            ValidationController validator = new ValidationController();

            try
            {
                DateRangeFactory dateRange = new DateRangeFactory(validator);
                IDateRange       result    = dateRange.From(inputArray, currentCulture);

                DisplayController.Display(DisplayController.SetMessageColor(MonitOperationSucceed,
                                                                            DisplayController.Color.DarkGreen));
                DisplayController.Display(result.ToString());
            }
            catch (Exception exception)
            {
                DisplayController.Display(exception.Message);
            }
            Console.ReadKey();
        }