예제 #1
0
def test_week_ending():
    """
    test calculating the beginning of a week from its end?
    """
    pytest.debug_func()
    tlist = {'yesterday':   daystart(time.time() - 24*3600),
             'today':       daystart(time.time()),
             'tomorrow':    daystart(time.time() + 24*3600),
             '2014.1104':   U.epoch("2014.1104"),
             '2009.0401':   time.mktime(time.strptime('2009.0401',
                                                      '%Y.%m%d'))}
    for t in tlist.keys():
        (start, end) = wr.week_ending(t)
        tm = time.localtime(tlist[t])
        end_exp = time.strftime('%Y.%m%d', tm)

        tm = time.localtime(tlist[t] - (6*24*3600-7200))
        start_exp = time.strftime('%Y.%m%d', tm)

        assert start_exp == start
        assert end_exp == end
예제 #2
0
def test_week_starting():
    """
    test calculating the end of a week from its start. The test for
    2014.1031 spans the beginning of DST.
    """
    pytest.debug_func()
    tlist = {'yesterday': time.time() - 24*3600,
             'today': time.time(),
             'tomorrow': time.time() + 24*3600,
             '2014.1028': U.epoch("2014.1028"),
             '2009.0401': time.mktime(time.strptime('2009.0401',
                                                    '%Y.%m%d'))}
    for t in tlist.keys():
        print("t = %s" % t)
        (start, end) = wr.week_starting(t)
        tm = time.localtime(tlist[t])
        start_should_be = time.strftime('%Y.%m%d', tm)

        tm = time.localtime(tlist[t] + 6*24*3600 + 7200)
        end_should_be = time.strftime('%Y.%m%d', tm)

        assert start_should_be == start
        assert end_should_be == end