Fix Exception when no time periods are defined

Handle the case when no time periods are defined in preferences (timePeriods is None). Also if time periods is empty, return a tuple (None, None) to match what the function call expects.