Exemple #1
0
        public void TestDateUtilities()
        {
            Console.WriteLine("Testing Date Utilities\nDate Formats\n");
            // tests different forms of date inputs and makes sure they all convert to standard format "dd/mm/yyyy"
            String[] testQuery = { "12-08-2003",
                                   "12th August 2003",
                                   "2003-8-12",
                                   "August 12 2003",
                                   "2003/08/12",
                                   "12/8/2003",
                                   "August 12th 2003",
                                   "12th, August, 2003",
                                   "12-Aug-2003",
                                   "12-Aug-03",
                                   "Aug-12-03",
                                   "12-8-03",
                                   "12/08/03" };
            for (int i = 0; i < testQuery.Length; i++)
            {
                Console.Write(testQuery[i] + " >> " + DateUtilities.DateFormat(testQuery[i]));
                if (DateUtilities.DateFormat(testQuery[i]).Equals("12/08/2003"))
                {
                    Console.Write(" >> OK\n");
                }
                else
                {
                    Console.Write(" >> ERROR\n");
                }
            }
            Console.WriteLine("\nLeap Years\n");
            // Test different date formats and different years for leap years
            String[] leapQuery = { "12-08-2000", "1900/08/12", "12-Aug-04", "12-08-1975" };
            for (int i = 0; i < leapQuery.Length; i++)
            {
                Console.WriteLine(leapQuery [i] + " >> " + DateUtilities.IsLeapYear(leapQuery[i]));
            }
            Console.WriteLine("\nBirthdays\n");
            // Test the birthday utility isBirthday
            DateTime today = DateTime.Now;

            String[] birthdayQuery = { today.Day + "/" + today.Month + "/" + today.Year,
                                       today.Day + "/" + today.Month + "/2008",
                                       today.Day + "/01/" + today.Year,
                                       "1/" + today.Month + "/09" };
            for (int i = 0; i < birthdayQuery.Length; i++)
            {
                Console.WriteLine(birthdayQuery [i] + " >> " + DateUtilities.IsBirthday(birthdayQuery [i]));
            }
            Console.WriteLine("\nZodiac Signs\n");
            // Tests different date formats and the getZodiac method
            String[] zodiacQuery = { "01/01/2000", "01-02-1967", "23rd March 1952", "12-Sep-07" };
            for (int i = 0; i < zodiacQuery.Length; i++)
            {
                Console.WriteLine(zodiacQuery [i] + " >> " + DateUtilities.GetZodiac(zodiacQuery [i]));
            }
        }
Exemple #2
0
 // Method to display all customers born in a leap year and their zodiac signs
 internal static void GetLeapYearCustomers(Customer[] array)
 {
     DisplayTitle("Leap Years and Zodiac Signs");
     foreach (Customer customer in array)
     {
         if (DateUtilities.IsLeapYear(customer.AccessDob))
         {
             customer.DisplayInfo();
             Console.WriteLine(String.Format("{0,-15} {1}", "Zodiac:", DateUtilities.GetZodiac(customer.AccessDob)) + "\n");
         }
     }
     waitForKey();
 }