Extract DateTime and Time duplicate methods to module

Refactoring according to https://github.com/rails/rails/pull/10879#issuecomment-21587166

@pixeltrix please take a look