Exemplo n.º 1
0
    def test_holidays_between_dates(self):
        start_date = datetime.date(year=2017, month=1, day=1)
        end_date = datetime.date(year=2017, month=12, day=31)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 4)
        self.assertListEqual(holidays, [
            self.new_years.to_json(2017),
            self.christmas_eve.to_json(2017),
            self.christmas.to_json(2017),
            self.new_years_eve.to_json(2017),
        ])

        end_date = datetime.date(year=2018, month=12, day=24)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 6)
        self.assertListEqual(holidays, [
            self.new_years.to_json(2017),
            self.christmas_eve.to_json(2017),
            self.christmas.to_json(2017),
            self.new_years_eve.to_json(2017),
            self.new_years.to_json(2018),
            self.christmas_eve.to_json(2018),
        ])

        start_date = datetime.date(year=2016, month=1, day=2)
        end_date = datetime.date(year=2016, month=12, day=23)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 0)
Exemplo n.º 2
0
    def test_holidays_between_dates(self):
        start_date = datetime.date(year=2017, month=1, day=1)
        end_date = datetime.date(year=2017, month=12, day=31)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 3)
        self.assertListEqual(holidays, [
            self.mlkday.to_json(2017),
            self.laborday.to_json(2017),
            self.thanksgiving.to_json(2017),
        ])

        end_date = datetime.date(year=2018, month=9, day=4)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 5)
        self.assertListEqual(holidays, [
            self.mlkday.to_json(2017),
            self.laborday.to_json(2017),
            self.thanksgiving.to_json(2017),
            self.mlkday.to_json(2018),
            self.laborday.to_json(2018),
        ])

        start_date = datetime.date(year=2016, month=1, day=19)
        end_date = datetime.date(year=2016, month=9, day=4)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 0)
Exemplo n.º 3
0
    def test_holidays_between_dates(self):
        start_date = datetime.date(year=2017, month=3, day=16)
        end_date = datetime.date(year=2018, month=3, day=31)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 1)
        self.assertDictEqual(holidays[0], self.easter_2017.to_json())

        end_date = datetime.date(year=2018, month=4, day=1)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 2)
        self.assertListEqual(holidays, [self.easter_2017.to_json(), self.easter_2018.to_json()])

        start_date = datetime.date(year=2016, month=3, day=28)
        end_date = datetime.date(year=2017, month=3, day=15)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 0)
Exemplo n.º 4
0
    def test_holidays_between_dates(self):
        start_date = datetime.date(year=2017, month=1, day=1)
        end_date = datetime.date(year=2017, month=12, day=31)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 2)
        self.assertListEqual(holidays, [
            self.electionday.to_json(2017),
            self.blackfriday.to_json(2017),
        ])

        end_date = datetime.date(year=2018, month=11, day=6)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 3)
        self.assertListEqual(holidays, [
            self.electionday.to_json(2017),
            self.blackfriday.to_json(2017),
            self.electionday.to_json(2018),
        ])

        start_date = datetime.date(year=2016, month=1, day=19)
        end_date = datetime.date(year=2016, month=9, day=4)
        holidays = Holiday.holidays_between_dates(start_date, end_date)
        self.assertEqual(len(holidays), 0)
Exemplo n.º 5
0
    def set_cached_due_date(self):
        if self.fixed_due_date:
            self.cached_due_date = self.fixed_due_date
        else:
            delayed_days = self.relative_due_days_delta
            delta = 1 if self.relative_due_days_delta >= 0 else -1
            dates = [datetime.date.today(),
                datetime.date.today() + relativedelta(days=2*delayed_days)]
            holidays = Holiday.holidays_between_dates(min(dates), max(dates))
            
            if self.relative_due_date_ticket.cached_due_date is None:
                # we want to recursively call this to make sure everything is
                # up to date when we are setting a cached value
                self.relative_due_date_ticket.set_cached_due_date()

            due_date = self.relative_due_date_ticket.cached_due_date
            while delayed_days != 0:
                due_date = due_date + relativedelta(days=delta)
                if due_date not in holidays and due_date.weekday() < 5:
                    delayed_days  -= delta

            self.cached_due_date = due_date