def test_granularity_month(): tzinfo = pytz.timezone('Europe/Amsterdam') g = GranularityMonth() timestamp = tzinfo.localize(datetime(2013, 1, 1)) v = g.inc(timestamp) assert_equal(v, tzinfo.localize(datetime(2013, 2, 1))) v = g.decr(timestamp) assert_equal(v, tzinfo.localize(datetime(2012, 12, 1))) start = tzinfo.localize(datetime(2012, 12, 1)) end = tzinfo.localize(datetime(2013, 3, 1)) timestamps = list(g.range(start, end)) assert_equal( timestamps, [ tzinfo.localize(datetime(2013, 1, 1)), tzinfo.localize(datetime(2013, 2, 1)), tzinfo.localize(datetime(2013, 3, 1)) ] )
def test_granularity_month_dst(): tzinfo = pytz.timezone('Europe/Amsterdam') granularity = GranularityMonth() timestamp = tzinfo.localize(datetime(2013, 11, 1)) before_dst_switch = granularity.decr(granularity.decr(timestamp)) assert_equal(before_dst_switch, tzinfo.localize(datetime(2013, 9, 1)))