예제 #1
0
def test_compare_begin_recalc(input_time, rel_time, output_time):
    # timezone unaware
    assert snap(input_time, rel_time) == output_time

    # timezone aware
    res = snap_tz(CET.localize(input_time), rel_time, CET)
    assert res == CET.localize(output_time)
    assert res.replace(tzinfo=None) == output_time
예제 #2
0
    def snap(self, instruction):
        """
        Returns a new MayaDT object modified by the given instruction.

        Powered by snaptime.  See https://github.com/zartstrom/snaptime
        for a complete documentation about the snaptime instructions.
        """
        return self.from_datetime(snaptime.snap(self.datetime(), instruction))
예제 #3
0
def test_empty_instruction():
    instr = ""
    dttm = datetime(2016, 7, 17, 15, 17, 0)
    assert dttm == snap(dttm, instr)
예제 #4
0
def test_bad_weekday(instruction, bad_weekday):
    with pytest.raises(SnapParseError) as exc:
        snap(DTTM, instruction)

    assert "'%s'" % bad_weekday in exc.value.message
예제 #5
0
def test_unit_error(instruction, bad_unit):
    with pytest.raises(SnapUnitError) as exc:
        snap(DTTM, instruction)

    assert "'%s'" % bad_unit in exc.value.message
예제 #6
0
def test_parse_error(instruction, bad_rest):
    with pytest.raises(SnapParseError) as exc:
        snap(DTTM, instruction)
    assert "'%s'" % instruction in exc.value.message
    assert "'%s'" % bad_rest in exc.value.message
def _following(date, week_day="SUN", tzinfo=timezone.utc):
    date = parse_date(date, tzinfo=tzinfo).astimezone(tzinfo)
    instruction = _make_instruction(week_day)
    return snap(date, instruction).date()