Ejemplo n.º 1
0
def test_Date_period():
    from did.base import Date
    today = did.base.TODAY
    did.base.TODAY = datetime.date(2015, 10, 3)
    # yesterday
    for argument in ["yesterday"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-10-02"
        assert unicode(until) == "2015-10-03"
        assert period == "yesterday"
    # This week
    for argument in ["", "week", "this week"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-28"
        assert unicode(until) == "2015-10-05"
        assert period == "this week"
    # Last week
    for argument in ["last", "last week"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-21"
        assert unicode(until) == "2015-09-28"
        assert period == "the last week"
    # This month
    for argument in ["month", "this month"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-10-01"
        assert unicode(until) == "2015-11-01"
        assert period == "this month"
    # Last month
    for argument in ["last month"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-01"
        assert unicode(until) == "2015-10-01"
        assert period == "the last month"
    # This quarter
    for argument in ["quarter", "this quarter"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-01"
        assert unicode(until) == "2015-12-01"
        assert period == "this quarter"
    # Last quarter
    for argument in ["last quarter"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-06-01"
        assert unicode(until) == "2015-09-01"
        assert period == "the last quarter"
    # This year
    for argument in ["year", "this year"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-03-01"
        assert unicode(until) == "2016-03-01"
        assert period == "this fiscal year"
    # Last year
    for argument in ["last year"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2014-03-01"
        assert unicode(until) == "2015-03-01"
        assert period == "the last fiscal year"
    did.base.TODAY = today
Ejemplo n.º 2
0
def test_Date_period():
    from did.base import Date
    today = did.base.TODAY
    did.base.TODAY = datetime.date(2015, 10, 3)
    # yesterday
    for argument in ["yesterday"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-10-02"
        assert unicode(until) == "2015-10-03"
        assert period == "yesterday"
    # This week
    for argument in ["", "week", "this week"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-28"
        assert unicode(until) == "2015-10-05"
        assert period == "this week"
    # Last week
    for argument in ["last", "last week"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-21"
        assert unicode(until) == "2015-09-28"
        assert period == "the last week"
    # This month
    for argument in ["month", "this month"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-10-01"
        assert unicode(until) == "2015-11-01"
        assert period == "this month"
    # Last month
    for argument in ["last month"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-01"
        assert unicode(until) == "2015-10-01"
        assert period == "the last month"
    # This quarter
    for argument in ["quarter", "this quarter"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-01"
        assert unicode(until) == "2015-12-01"
        assert period == "this quarter"
    # Last quarter
    for argument in ["last quarter"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-06-01"
        assert unicode(until) == "2015-09-01"
        assert period == "the last quarter"
    # This year
    for argument in ["year", "this year"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-03-01"
        assert unicode(until) == "2016-03-01"
        assert period == "this fiscal year"
    # Last year
    for argument in ["last year"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2014-03-01"
        assert unicode(until) == "2015-03-01"
        assert period == "the last fiscal year"
    did.base.TODAY = today
Ejemplo n.º 3
0
def test_Date_period():
    from did.base import Date
    today = did.base.TODAY
    did.base.TODAY = datetime.date(2015, 10, 3)
    # yesterday
    for argument in ["yesterday"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-10-02"
        assert unicode(until) == "2015-10-03"
        assert period == "yesterday"
    # This week
    for argument in ["", "week", "this week"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-28"
        assert unicode(until) == "2015-10-05"
        assert period == "the week 40"
    # Last week
    for argument in ["last", "last week"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-21"
        assert unicode(until) == "2015-09-28"
        assert period == "the week 39"
    # This month
    for argument in ["month", "this month"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-10-01"
        assert unicode(until) == "2015-11-01"
        assert period == "October"
    # Last month
    for argument in ["last month"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-01"
        assert unicode(until) == "2015-10-01"
        assert period == "September"
    # This quarter
    for argument in ["quarter", "this quarter"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-09-01"
        assert unicode(until) == "2015-12-01"
        assert period == "this quarter"
    # Last quarter
    for argument in ["last quarter"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-06-01"
        assert unicode(until) == "2015-09-01"
        assert period == "the last quarter"
    # This year
    for argument in ["year", "this year"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2015-03-01"
        assert unicode(until) == "2016-03-01"
        assert period == "this fiscal year"
    # Last year
    for argument in ["last year"]:
        since, until, period = Date.period(argument)
        assert unicode(since) == "2014-03-01"
        assert unicode(until) == "2015-03-01"
        assert period == "the last fiscal year"
    # Adding and subtracting days
    assert unicode(Date('2018-11-29') + 1) == '2018-11-30'
    assert unicode(Date('2018-11-29') + 2) == '2018-12-01'
    assert unicode(Date('2018-12-02') - 1) == '2018-12-01'
    assert unicode(Date('2018-12-02') - 2) == '2018-11-30'
    did.base.TODAY = today
Ejemplo n.º 4
0
def test_Date_period():
    from did.base import Date
    today = did.base.TODAY
    did.base.TODAY = datetime.date(2015, 10, 3)
    # yesterday
    for argument in ["yesterday"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-10-02"
        assert str(until) == "2015-10-03"
        assert period == "yesterday"
    # This week
    for argument in ["", "week", "this week"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-09-28"
        assert str(until) == "2015-10-05"
        assert period == "the week 40"
    # Last week
    for argument in ["last", "last week"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-09-21"
        assert str(until) == "2015-09-28"
        assert period == "the week 39"
    # Last Friday
    for argument in ["last friday"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-10-02"
        assert str(until) == "2015-10-03"
        assert period == "the last friday"
    # This month
    for argument in ["month", "this month"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-10-01"
        assert str(until) == "2015-11-01"
        assert period == "October"
    # Last month
    for argument in ["last month"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-09-01"
        assert str(until) == "2015-10-01"
        assert period == "September"
    # This quarter
    for argument in ["quarter", "this quarter"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-10-01"
        assert str(until) == "2016-01-01"
        assert period == "this quarter"
    # Last quarter
    for argument in ["last quarter"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-07-01"
        assert str(until) == "2015-10-01"
        assert period == "the last quarter"
    # This year
    for argument in ["year", "this year"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2015-01-01"
        assert str(until) == "2016-01-01"
        assert period == "this year"
    # Last year
    for argument in ["last year"]:
        since, until, period = Date.period(argument)
        assert str(since) == "2014-01-01"
        assert str(until) == "2015-01-01"
        assert period == "the last year"
    # Adding and subtracting days
    assert str(Date('2018-11-29') + 1) == '2018-11-30'
    assert str(Date('2018-11-29') + 2) == '2018-12-01'
    assert str(Date('2018-12-02') - 1) == '2018-12-01'
    assert str(Date('2018-12-02') - 2) == '2018-11-30'
    did.base.TODAY = today