'Parse the templates and store a datetime tuple in _period.'

def update_period(self):

    start = None
    end = None
    if (self._start is not None):
        try:
            start_rendered = self._start.render()
        except (TemplateError, TypeError) as ex:
            HistoryStatsHelper.handle_template_exception(ex, 'start')
            return
        start = dt_util.parse_datetime(start_rendered)
        if (start is None):
            try:
                start = dt_util.as_local(dt_util.utc_from_timestamp(math.floor(float(start_rendered))))
            except ValueError:
                _LOGGER.error('Parsing    error:    start    must    be    a    datetimeor    a    timestamp')
                return
    if (self._end is not None):
        try:
            end_rendered = self._end.render()
        except (TemplateError, TypeError) as ex:
            HistoryStatsHelper.handle_template_exception(ex, 'end')
            return
        end = dt_util.parse_datetime(end_rendered)
        if (end is None):
            try:
                end = dt_util.as_local(dt_util.utc_from_timestamp(math.floor(float(end_rendered))))
            except ValueError:
                _LOGGER.error('Parsing    error:    end    must    be    a    datetime    or    a    timestamp')
                return
    if (start is None):
        start = (end - self._duration)
    if (end is None):
        end = (start + self._duration)
    self._period = (start, end)
