Exemplo n.º 1
0
    def test_datediff1(self):
        test_date_first = "02/06/1983"
        test_date_second = "22/06/1983"

        # Unpack user input into day, month and year separated by "/"
        first_d, first_m, first_y = test_date_first.split(sep='/')
        second_d, second_m, second_y = test_date_second.split(sep='/')

        # Create Date objects from the Date Class and convert inputs into integers
        date_f = Date(int(first_d), int(first_m), int(first_y))
        date_s = Date(int(second_d), int(second_m), int(second_y))

        result = day_difference(date_f, date_s)
        self.assertEqual(result, 19)
Exemplo n.º 2
0
    def test_datediff4(self):
        test_date_first = "03/01/1901"
        test_date_second = "03/08/2999"

        # Unpack user input into day, month and year separated by "/"
        first_d, first_m, first_y = test_date_first.split(sep='/')
        second_d, second_m, second_y = test_date_second.split(sep='/')

        # Create Date objects from the Date Class and convert inputs into integers
        date_f = Date(int(first_d), int(first_m), int(first_y))
        date_s = Date(int(second_d), int(second_m), int(second_y))

        date_format = "%d/%m/%Y"
        a = datetime.strptime(test_date_first, date_format)
        b = datetime.strptime(test_date_second, date_format)
        delta = b - a

        result = day_difference(date_f, date_s)
        self.assertEqual(result, abs(delta.days) - 1)
Exemplo n.º 3
0
            if first_date == 'q':
                break
            second_date = input(
                'Please enter Second Date using the DD/MM/YYYY format: ')
            if second_date == 'q':
                break

            # Unpack user input into day, month and year separated by "/"
            first_d, first_m, first_y = first_date.split(sep='/')
            second_d, second_m, second_y = second_date.split(sep='/')

            # Create Date objects from the Date Class and convert inputs into integers
            date_f = Date(int(first_d), int(first_m), int(first_y))
            date_s = Date(int(second_d), int(second_m), int(second_y))

            if not (1901 <= date_f.y <= 2999) or not (1901 <= date_s.y <= 2999):
                print("Dates must be between 01/01/1901 and 31/12/2999. Try again!")
                continue
        except:
            print("Make sure the dates are entered in the following format: DD/MM/YYYY")
        else:
            # Print resulting date difference
            if first_date == second_date:
                print("You entered the same First and Second dates. Goodbye")
            elif day_difference(date_f, date_s) == "Dates not valid":
                print("The dates entered are not valid. Goodbye!")
            else:
                print(f'\t{first_date} - {second_date} =',
                      day_difference(date_f, date_s), "days")
            break