/// <summary> /// Test every possible combination of date components' order /// </summary> /// <param name="input"></param> /// <param name="validationResult"></param> /// <returns>True when a proper combination is found, false if any possible date /// components order combinatios</returns> public void SetUpCorrectDate(int[] input, ref DateValidation validationResult) { // Auxiliary data structure used to generate permutations IEnumerable <int> increasingOrderIndices = new List <int>() { 0, 1, 2 }; // Auxiliary data structure holding any possible permutation IEnumerable <IEnumerable <int> > twoDimensionalIndices = DateComponentsOrder.GetPermutations(increasingOrderIndices, increasingOrderIndices.Count()); // Two dimensional array of integers used for the following calculations int[][] arrayOfPermutatedIndices = twoDimensionalIndices.Select(i => i.ToArray()).ToArray(); bool isLeapYear; // Test any possible permutation for (int index = 0; index < arrayOfPermutatedIndices.Count(); ++index) { // Assemble temporary object dateComponentsOrder = new DateComponentsOrder(arrayOfPermutatedIndices[index]); dateComponents = new DateComponents(input, dateComponentsOrder); isLeapYear = IsLeapYear(dateComponents.Year); // When data order is valid the results will be passed to DateBuilder with validation indicator if (IsDateValid(isLeapYear)) { validationResult.DateComponents = dateComponents; validationResult.IsValid = true; return; } } // Any of the permutations does not meet the assumptions. Exception will be thrown in DateBuilder validationResult.IsValid = false; }
/// <summary> /// Constructs an object by first converting date components to strings /// and then assigning result to properties /// </summary> /// <param name="dateComponents">DateComponents as integers</param> public DateComponentsAsStrings(DateComponents dateComponents) { Day = String.Format("{0:00}", dateComponents.Day); Month = String.Format("{0:00}", dateComponents.Month); Year = String.Format("{0:####;0:####;0000}", dateComponents.Year); }