Fixed before/after + date_format rules implementation

This fixes PR #3607 to provide missing features described on PR #1824 and PR #4699. Also rewrote testBeforeAndAfterWithFormat() tests.
Merge pull request #4710 from paulofreitas/patch-1

Fixed before/after + date_format rules inconsistencies