RTC time related optimizations

Consider this changes. 

First commit removes the need to call heavy function gettime() where possible. 

The second commit reduces the number of  gettime() calls.