Exemplo n.º 1
0
def get_exp_series(date, limit=const.NUM_SERIES):
    l = []
    dt = date
    for i in range(limit):
        y, m = dt.tm_year, dt.tm_mon
        last = get_last_day_of_month(y, m, 3)
        if last < dt.tm_mday:
            m = m + 1
            if m > 12:
                y = y + 1
                m = 1
            last = get_last_day_of_month(y, m, 3)

        exp = time.struct_time((y, m, last, 0, 0, 0, 3, 0, 0))
        if is_holiday(exp):
            exp = get_prev_date(exp)

        # We need to dump-load pytime to ensure that it works fine
        str_time = from_pytime_to_str(exp)
        exp = from_str_to_pytime(str_time)

        l.append(exp)
        dt = next_day(exp)

    return l
Exemplo n.º 2
0
def get_prev_date(date, skip_holidays=True):
    dt = datetime.fromtimestamp(time.mktime(date))
    delta = timedelta(days=1)
    while True:
        dt = dt - timedelta(days=1)
        if not skip_holidays:
            break
        _dt = dt.date().timetuple()
        if not is_holiday(_dt):
            break
    return dt.date().timetuple()
Exemplo n.º 3
0
def get_date_range(date):
    l = []
    series = get_exp_series(date, limit=1)
    expiry = series[0]
    dt = date
    l.append(dt)
    while True:
        dt = next_day(dt)
        if dt > expiry:
            break
        if is_holiday(dt):
            continue
        l.append(dt)
    return l
Exemplo n.º 4
0
def datetimeIterator(from_date,
                     to_date,
                     delta=timedelta(days=1),
                     skip_holidays=True):

    from_date = datetime.fromtimestamp(time.mktime(from_date))
    to_date = datetime.fromtimestamp(time.mktime(to_date))

    while from_date <= to_date:
        date = from_date.date().timetuple()

        if skip_holidays and is_holiday(date):
            pass
        else:
            yield date
        from_date = from_date + delta
Exemplo n.º 5
0
 def test_is_holiday(self):
     self.assertTrue(is_holiday(datetime.date(2012, 3, 8)))
     self.assertTrue(is_holiday(datetime.date(2012, 3, 31)))
     self.assertFalse(is_holiday(datetime.date(2012, 3, 11)))
     self.assertFalse(is_holiday(datetime.date(2012, 9, 3)))
Exemplo n.º 6
0
 def test_is_holiday(self):
     self.assertTrue(is_holiday(datetime.date(2012, 3, 8)))
     self.assertTrue(is_holiday(datetime.date(2012, 3, 31)))
     self.assertFalse(is_holiday(datetime.date(2012, 3, 11)))
     self.assertFalse(is_holiday(datetime.date(2012, 9, 3)))