def test_issue_times(single_forecast, issuetime, rl, lt, start, expected):
    fx = replace(single_forecast,
                 issue_time_of_day=dt.datetime.strptime(issuetime,
                                                        '%H:%M').time(),
                 run_length=pd.Timedelta(rl),
                 lead_time_to_start=pd.Timedelta(lt))
    out = utils.get_issue_times(fx, start)
    assert out == expected
def test_issue_times_localized(single_forecast):
    fx = replace(
        single_forecast,
        issue_time_of_day=pytz.timezone('Etc/GMT+7').localize(dt.time(12)),
        run_length=pd.Timedelta('12h'),
    )
    out = utils.get_issue_times(fx, pd.Timestamp('20200601T1700-0500'))
    assert out == [
        pd.Timestamp('20200601T0200-05:00'),
        pd.Timestamp('20200601T1400-05:00'),
        pd.Timestamp('20200602T0200-05:00')
    ]
def test_issue_times_high_freq(single_forecast):
    fx = replace(single_forecast,
                 issue_time_of_day=dt.time(0),
                 run_length=pd.Timedelta('15min'),
                 interval_length=pd.Timedelta('5min'),
                 lead_time_to_start=pd.Timedelta('5min'))
    out = utils.get_issue_times(fx, pd.Timestamp('20200501T0000-07:00'))
    assert out == list(
        pd.date_range(start='20200501T0000',
                      end='20200502T0000',
                      tz='Etc/GMT+7',
                      freq='15min'))
def test_issue_times_fx_gap(forecast_hr_begin):
    # 1-4 utc should not be included in output as 5 is the first
    # issue time for the day.
    out = utils.get_issue_times(forecast_hr_begin,
                                pd.Timestamp('20200505T2000-07:00'))
    assert out == list(
        pd.date_range(start=pd.Timestamp('20200505T0000-07:00'),
                      end=pd.Timestamp('20200505T1700-07:00'),
                      freq='1h')) + list(
                          pd.date_range(
                              start=pd.Timestamp('20200505T2200-07:00'),
                              end=pd.Timestamp('20200506T0000-07:00'),
                              freq='1h'))
def test_issue_times_localized_dst(single_forecast):
    tzinfo = pd.Timestamp('20200308T0000', tz='America/New_York').tzinfo
    fx = replace(
        single_forecast,
        issue_time_of_day=dt.time(hour=2, tzinfo=tzinfo),
        run_length=pd.Timedelta('12h'),
    )
    out = utils.get_issue_times(fx, pd.Timestamp('20200308T0100-0500'))
    assert out == [
        pd.Timestamp('20200308T0300-04:00'),
        pd.Timestamp('20200308T1500-04:00'),
        pd.Timestamp('20200309T0300-04:00')
    ]