示例#1
0
def get_dates(dt):
    if is_period_id(dt):
        start = start_of_period(dt)
        end =end_of_period(dt)
    elif type(dt) in [str, unicode] and dt[-4:]=='_YTD':
        end = parse(dt[:-4])
        start = datetime.date(end.year, 1, 1)
    elif type(dt) in [str, unicode] and dt[0] == 'D':
        d = parse(dt[1:]).date()
        start = prev_busday(d)+datetime.timedelta(days=1)
        end = d
    elif dt=='today':
        start = settings.DATE_EARLY
        end = datetime.datetime.now().date()
    else:
        start = settings.DATE_EARLY
        if type(dt)==str:
            end = parse(dt).date()
        else:
            end = dt
    return start, end
示例#2
0
def get_dates(dt):
    if is_period_id(dt):
        start = start_of_period(dt)
        end =end_of_period(dt)
    elif type(dt) in [str, unicode] and dt[-4:]=='_YTD':
        end = parse(dt[:-4])
        start = datetime.date(end.year, 1, 1)
    elif type(dt) in [str, unicode] and dt[0] == 'D':
        d = parse(dt[1:]).date()
        start = prev_busday(d)+datetime.timedelta(days=1)
        end = d
    elif dt=='today':
        start = settings.DATE_EARLY
        end = datetime.datetime.now().date()
    else:
        start = settings.DATE_EARLY
        if type(dt)==str:
            end = parse(dt).date()
        else:
            end = dt
    return start, end
示例#3
0
def end_of_period(period_id):
    assert is_period_id(period_id)
    pid = period_id
    year = int(period_id[0:4])
    if len(pid) > 5: 
        part2 = int(pid[5:])  #month, week, quarter
        sep = pid[4]
    else:
        part2 = None
        sep = 'Y'
    if sep == 'W':        
        import isoweek
        return isoweek.Week(year, part2).sunday()
    elif sep == 'M':
        return end_of_month(part2, year)
    elif sep == 'Q':
        return end_of_quarter(part2*3, year)
    elif sep == 'H':
        return end_of_half(part2*6, year)
    elif sep == 'Y':
        return datetime.date(year, 12, 31)
    else:
        raise ValueError("Unexpected date identifier %s" % id)
示例#4
0
def end_of_period(period_id):
    assert is_period_id(period_id)
    pid = period_id
    year = int(period_id[0:4])
    if len(pid) > 5: 
        part2 = int(pid[5:])  #month, week, quarter
        sep = pid[4]
    else:
        part2 = None
        sep = 'Y'
    if sep == 'W':        
        import isoweek
        return isoweek.Week(year, part2).sunday()
    elif sep == 'M':
        return end_of_month(part2, year)
    elif sep == 'Q':
        return end_of_quarter(part2, year)
    elif sep == 'H':
        return end_of_half(part2, year)
    elif sep == 'Y':
        return datetime.date(year, 12, 31)
    else:
        raise ValueError("Unexpected date identifier %s" % id)
示例#5
0
def start_of_period(period_id):
    pid = period_id
    assert is_period_id(pid)
    year = int(pid[0:4])
    if len(pid) > 5: 
        part2 = int(pid[5:])  #month, week, quarter
        sep = pid[4]
    else:
        part2 = None
        sep = 'Y'
    if sep == 'W':        
        import isoweek
        return isoweek.Week(year, part2).monday()
    elif sep == 'M':
        return datetime.date(year, part2, 1)
    elif sep == 'Q':
        month_id = (part2 - 1) * 3 + 1
        return datetime.date(year, month_id, 1)
    elif sep == 'H':
        return start_of_half(date(year, (part2*6), 1))
    elif sep == 'Y':
        return datetime.date(year, 1, 1)
    else:
        raise ValueError("Unexpected date identifier %s" % id)
示例#6
0
def start_of_period(period_id):
    pid = period_id
    assert is_period_id(pid)
    year = int(pid[0:4])
    if len(pid) > 5: 
        part2 = int(pid[5:])  #month, week, quarter
        sep = pid[4]
    else:
        part2 = None
        sep = 'Y'
    if sep == 'W':        
        import isoweek
        return isoweek.Week(year, part2).monday()
    elif sep == 'M':
        return datetime.date(year, part2, 1)
    elif sep == 'Q':
        month_id = (part2 - 1) * 3 + 1
        return datetime.date(year, month_id, 1)
    elif sep == 'H':
        return start_of_half(part2, year)
    elif sep == 'Y':
        return datetime.date(year, 1, 1)
    else:
        raise ValueError("Unexpected date identifier %s" % id)