Port date and time calculations over from ActiveSupport