Esempio n. 1
0
    def test_check_dekad(self):

        dekad1 = dk.check_dekad(self.date1)
        dekad2 = dk.check_dekad(self.date2)
        dekad3 = dk.check_dekad(self.date3)

        assert dekad1 == datetime(2000, 2, 10)
        assert dekad2 == datetime(2000, 2, 20)
        assert dekad3 == datetime(2000, 2, 29)
Esempio n. 2
0
def check_period(interval, date):
    """
    Checks the containing interval of a date and returns the date of the
    interval.

    Parameters
    ----------
    interval : str
        Interval to check, one of (dekad, week, month).
    date : datetime
        Date to check.

    Returns
    -------
    date : datetime
        Date of the interval.
    """

    if interval in ['dekad', 'dekadal', 'decadal', 'decade']:
        date = check_dekad(date)
    elif interval in ['weekly', 'week', '7']:
        date = date - timedelta(date.weekday()) + timedelta(6)
    elif interval in ['monthly', 'month']:
        lday = calendar.monthrange(date.year, date.month)[1]
        date = datetime(date.year, date.month, lday)

    return date
Esempio n. 3
0
    def test_dekad_index(self):
        firstdate = datetime(2000, 1, 10)
        lastdate = datetime(2000, 3, 20)
        items = 8

        dkindex = dk.dekad_index(self.begin, self.end)
        assert dkindex[0] == firstdate
        assert dkindex[-1] == lastdate
        assert dkindex.size == items

        dkindex = dk.dekad_index(self.begin)
        assert dkindex[0] == firstdate
        assert (dkindex[-1] - dk.check_dekad(datetime.now())).days == 0

        dkindex = dk.dekad_index(datetime(2014, 1, 3), datetime(2014, 1, 5))
        assert dkindex[0] == datetime(2014, 1, 10)
        assert dkindex.size == 1

        dkindex = dk.dekad_index(datetime(2014, 1, 3), datetime(2014, 1, 15))
        assert dkindex[0] == datetime(2014, 1, 10)
        assert dkindex[1] == datetime(2014, 1, 20)

        dkindex = dk.dekad_index(datetime(2014, 1, 3), datetime(2014, 1, 25))
        assert dkindex[0] == datetime(2014, 1, 10)
        assert dkindex[2] == datetime(2014, 1, 31)

        dkindex = dk.dekad_index(datetime(2014, 1, 13), datetime(2014, 1, 15))
        assert dkindex[0] == datetime(2014, 1, 20)
        assert dkindex.size == 1

        dkindex = dk.dekad_index(datetime(2014, 1, 13), datetime(2014, 1, 25))
        assert dkindex[0] == datetime(2014, 1, 20)
        assert dkindex[1] == datetime(2014, 1, 31)

        dkindex = dk.dekad_index(datetime(2014, 1, 23), datetime(2014, 1, 25))
        assert dkindex[0] == datetime(2014, 1, 31)
        assert dkindex.size == 1

        dkindex = dk.dekad_index(datetime(2014, 1, 3), datetime(2014, 3, 5))
        assert dkindex[0] == datetime(2014, 1, 10)
        assert dkindex[-1] == datetime(2014, 3, 10)

        dkindex = dk.dekad_index(datetime(2014, 1, 13), datetime(2014, 3, 25))
        assert dkindex[0] == datetime(2014, 1, 20)
        assert dkindex[-1] == datetime(2014, 3, 31)