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
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))
def test_empty_instruction(): instr = "" dttm = datetime(2016, 7, 17, 15, 17, 0) assert dttm == snap(dttm, instr)
def test_bad_weekday(instruction, bad_weekday): with pytest.raises(SnapParseError) as exc: snap(DTTM, instruction) assert "'%s'" % bad_weekday in exc.value.message
def test_unit_error(instruction, bad_unit): with pytest.raises(SnapUnitError) as exc: snap(DTTM, instruction) assert "'%s'" % bad_unit in exc.value.message
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()