'Potentially update the IERS table in place depending on the requested
time values in ``mjd`` and the time span of the table.
For IERS_Auto the behavior is that the table is refreshed from the IERS
server if both the following apply:
- Any of the requested IERS values are predictive.  The IERS-A table
contains predictive data out for a year after the available
definitive values.
- The first predictive values are at least ``conf.auto_max_age days`` old.
In other words the IERS-A table was created by IERS long enough
ago that it can be considered stale for predictions.'

def _refresh_table_as_needed(self, mjd):

    max_input_mjd = np.max(mjd)
    now_mjd = self.time_now.mjd
    fpi = self.meta[u'predictive_index']
    predictive_mjd = self.meta[u'predictive_mjd']
    auto_max_age = (conf.auto_max_age if (conf.auto_max_age is not None) else np.finfo(np.float).max)
    if (auto_max_age < 10):
        raise ValueError(u'IERS    auto_max_age    configuration    value    must    be    larger    than    10    days')
    if ((max_input_mjd > predictive_mjd) and ((now_mjd - predictive_mjd) > auto_max_age)):
        try:
            clear_download_cache(conf.iers_auto_url)
            filename = download_file(conf.iers_auto_url, cache=True)
        except Exception as err:
            warn(AstropyWarning(u'failed    to    download    {}:    {}.\nA    coordinate    or    time-related    calculation    might    be    compromised    or    fail    because    the    dates    are    not    covered    by    the    available    IERS    file.        See    the    "IERS    data    access"    section    of    the    astropy    documentation    for    additional    information    on    working    offline.'.format(conf.iers_auto_url, str(err))))
            return
        new_table = self.__class__.read(file=filename)
        if (new_table[u'MJD'][(-1)] > self[u'MJD'][(-1)]):
            new_fpi = np.searchsorted(new_table[u'MJD'].value, predictive_mjd, side=u'right')
            n_replace = (len(self) - fpi)
            self[fpi:] = new_table[new_fpi:(new_fpi + n_replace)]
            if ((new_table[u'MJD'][(new_fpi + n_replace)] - self[u'MJD'][(-1)]) != (1.0 * u.d)):
                raise ValueError(u'unexpected    gap    in    MJD    when    refreshing    IERS    table')
            for row in new_table[(new_fpi + n_replace):]:
                self.add_row(row)
            self.meta.update(new_table.meta)
        else:
            warn(IERSStaleWarning(u'IERS_Auto    predictive    values    are    older    than    {}    days    but    downloading    the    latest    table    did    not    find    newer    values'.format(conf.auto_max_age)))
