Add missing header <sys/time.h> for gettimeofday

The patch adds `<sys/time.h>` header for `clock_gettime()`. Also make
sure `_POSIX_TIMERS` is defined before checking its value.

On Darwin/OSX one could use `mach_absolute_time()` and
`AbsoluteToNanoseconds` provided by CoreServices framework instead.

Signed-off-by: David Abdurachmanov <davidlt@cern.ch>
Merge pull request #6444 from davidlt/add-missing-header-gettimeofday

Add missing header <sys/time.h> for gettimeofday