Fixed before/after + date_format rules inconsistencies

This fixes PR #3607 to provide missing functionalities described on PR #1824 and PR #4699 and line up `before`/`after` rules to work smoothly with and without a `date_format` rule.

I also rewrote `testBeforeAndAfterWithFormat()` tests to better detect inconsistencies.