Пример #1
0
 def test_last_weekday(self):
     # last monday in january 2013
     self.assertEquals(Calendar.get_last_weekday_in_month(2013, 1, MON),
                       date(2013, 1, 28))
     # last thursday
     self.assertEquals(Calendar.get_last_weekday_in_month(2013, 1, THU),
                       date(2013, 1, 31))
Пример #2
0
 def test_nth_weekday_start(self):
     # first thursday after 18th april
     start = date(2013, 4, 18)
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 4, THU, start=start), date(2013, 4, 18))
     # first friday after 18th april
     start = date(2013, 4, 18)
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 4, FRI, start=start), date(2013, 4, 19))
Пример #3
0
    def test_get_next_weekday_after(self):
        # the first monday after Apr 1 2015
        self.assertEquals(
            Calendar.get_first_weekday_after(date(2015, 4, 1), MON),
            date(2015, 4, 6))

        # the first tuesday after Apr 14 2015
        self.assertEquals(
            Calendar.get_first_weekday_after(date(2015, 4, 14), TUE),
            date(2015, 4, 14))
Пример #4
0
 def test_nth_weekday(self):
     # first monday in january 2013
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, MON), date(2013, 1, 7))
     # second monday in january 2013
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, MON, 2), date(2013, 1, 14))
     # let's test the limits
     # Jan 1st is a TUE
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, TUE), date(2013, 1, 1))
     # There's no 6th MONday
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, MON, 6), None)
Пример #5
0
 def test_last_weekday(self):
     # last monday in january 2013
     self.assertEquals(
         Calendar.get_last_weekday_in_month(2013, 1, MON),
         date(2013, 1, 28)
     )
     # last thursday
     self.assertEquals(
         Calendar.get_last_weekday_in_month(2013, 1, THU),
         date(2013, 1, 31)
     )
Пример #6
0
 def test_nth_weekday_start(self):
     # first thursday after 18th april
     start = date(2013, 4, 18)
     self.assertEquals(
         Calendar.get_nth_weekday_in_month(2013, 4, THU, start=start),
         date(2013, 4, 18))
     # first friday after 18th april
     start = date(2013, 4, 18)
     self.assertEquals(
         Calendar.get_nth_weekday_in_month(2013, 4, FRI, start=start),
         date(2013, 4, 19))
Пример #7
0
    def test_get_next_weekday_after(self):
        # the first monday after Apr 1 2015
        self.assertEquals(
            Calendar.get_first_weekday_after(date(2015, 4, 1), 0),
            date(2015, 4, 6)
        )

        # the first tuesday after Apr 14 2015
        self.assertEquals(
            Calendar.get_first_weekday_after(date(2015, 4, 14), 1),
            date(2015, 4, 14)
        )
Пример #8
0
 def test_nth_weekday(self):
     # first monday in january 2013
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, MON),
                       date(2013, 1, 7))
     # second monday in january 2013
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, MON, 2),
                       date(2013, 1, 14))
     # let's test the limits
     # Jan 1st is a TUE
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, TUE),
                       date(2013, 1, 1))
     # There's no 6th MONday
     self.assertEquals(Calendar.get_nth_weekday_in_month(2013, 1, MON, 6),
                       None)
Пример #9
0
    def add_year(self, year):
        """Given a year, this method appends all Holidays
        for that year to the list attribute 'holidays'.
        After loading, it appends the year number to the 'loaded_years'
        list attribute in order to keep a state of what years are already loaded.
        
        :param year: the year we want to load
        :type year: int
        """

        self.holidays.extend(cal.holidays(year))

        # Mothers day: 2nd Sunday of May.
        self.holidays.append(
            (Calendar.get_nth_weekday_in_month(year, 5, SUN,
                                               2), 'Mothers day'))
        # Fathers day: 3rd Sunday of June
        self.holidays.append(
            (Calendar.get_nth_weekday_in_month(year, 6, SUN,
                                               3), 'Mothers day'))
        # Halloween: Oct 31
        self.holidays.append((date(year, 10, 31), 'Halloween'))
        # Velitas 7 Dic
        self.holidays.append((date(year, 12, 7), 'Día de las Velitas'))
        # Amor y amistad
        self.holidays.append(
            (Calendar.get_nth_weekday_in_month(year, 9, SAT,
                                               3), 'Amor y amistad'))
        # San valentín
        self.holidays.append((date(year, 2, 14), 'Día de San Valentín'))
        # Día del Hombre
        self.holidays.append((date(year, 3, 19), 'Día del Hombre'))
        # Día de la Mujer
        self.holidays.append((date(year, 3, 8), 'Día de la Mujer'))

        self.loaded_years.append(year)
Пример #10
0
# call loop function
start_time_ns = time.time_ns()
retrieve_nth_weekday_loop(date_table, nth_weekday)
elapsed_time_ns = time.time_ns() - start_time_ns
print("loop_return_date_only in {} nenoseconds".format(elapsed_time_ns))

# call map function
start_time_ns = time.time_ns()
retrieve_nth_weekday_map(date_table, nth_weekday)
elapsed_time_ns = time.time_ns() - start_time_ns
print("map_function_return_list in {} nenoseconds".format(elapsed_time_ns))

# call list comprehension function
start_time_ns = time.time_ns()
retrieve_nth_weekday_list_comp(date_table, nth_weekday)
elapsed_time_ns = time.time_ns() - start_time_ns
print("list_comperehension_return_list in {} nenoseconds".format(elapsed_time_ns))


# call all fields function
start_time_ns = time.time_ns()
retrieve_nth_weekday_all_fields(date_table, nth_weekday)
elapsed_time_ns = time.time_ns() - start_time_ns
print("all_fields_related to nth_weekday_index in {} nenoseconds".format(elapsed_time_ns))

# call workalendar main nth_weekday function
start_time_ns = time.time_ns()
Calendar.get_nth_weekday_in_month(2010, 2, FRI, 3)
elapsed_time_ns = time.time_ns() - start_time_ns
print("Calendar built-in function return date in {} nenoseconds".format(elapsed_time_ns))