Ejemplo n.º 1
0
    def testHoliday(self):
        """ Look at holiday more carefully because of the smooth transition. """
        p = DateEncoderParameters()
        p.holiday_width = 5
        p.verbose = False
        e = DateEncoder(p)
        notholiday = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]  # Not a holiday
        holiday1 = [0, 0, 0, 1, 1, 1, 1, 1, 0, 0]  # day before holiday
        holiday = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]  # day of holiday
        holiday2 = [1, 1, 0, 0, 0, 0, 0, 1, 1, 1]  # day after holiday

        d = datetime.datetime(2011, 12, 24, 16,
                              00)  #day before holiday, approaching
        assert (all(e.encode(d).dense == holiday1))

        d = datetime.datetime(2010, 12, 25, 4,
                              55)  #Christmas day 25th Dec, a default holiday
        assert (all(e.encode(d).dense == holiday))

        d = datetime.datetime(1999, 12, 26, 8,
                              00)  #day after holiday, approaching
        assert (all(e.encode(d).dense == holiday2))

        d = datetime.datetime(2008, 12, 27, 4, 55)  #12/27 is not a holiday
        assert (all(e.encode(d).dense == notholiday))
Ejemplo n.º 2
0
    def testHolidayMultiple(self):
        """ Look at holiday more carefully because of the smooth transition. """
        p = DateEncoderParameters()
        p.holiday_width = 5
        p.holiday_dates = [[12, 25], [2018, 4, 1], [2017, 4, 16]]
        p.verbose = False
        e = DateEncoder(p)
        holiday = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
        notholiday = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]

        d = datetime.datetime(2011, 12, 25, 4, 55)
        assert (all(e.encode(d).dense == holiday))

        d = datetime.datetime(2007, 12, 2, 4, 55)
        assert (all(e.encode(d).dense == notholiday))

        d = datetime.datetime(2018, 4, 1, 16, 10)
        assert (all(e.encode(d).dense == holiday))

        d = datetime.datetime(2017, 4, 16, 16, 10)
        assert (all(e.encode(d).dense == holiday))