64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package report
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/module"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
|
)
|
|
|
|
func weekendDefinition() Definition {
|
|
return Definition{
|
|
ID: Weekend,
|
|
Name: "Weekend Outlook",
|
|
PromptID: "weather.weekend_outlook",
|
|
GenerationMode: GenerationModeScriptoriumMarkdown,
|
|
ComparisonStrategy: CompareWeekendWindow,
|
|
ArtifactGroup: "weekend",
|
|
BatchOutputName: "weekend.md",
|
|
Generated: true,
|
|
CompatiblePriorIDs: []ID{Weekend},
|
|
Modules: weekendModules(),
|
|
Morning: true,
|
|
resolve: resolveWeekend,
|
|
}
|
|
}
|
|
|
|
func weekendModules() []module.ConfigItem {
|
|
return moduleItems(
|
|
module.Metadata,
|
|
module.CurrentConditions,
|
|
module.DerivedDaypartSummaries,
|
|
module.PrecipTiming,
|
|
module.AlertDigest,
|
|
module.SPCConvectiveOutlooks,
|
|
module.AreaForecastDiscussion,
|
|
module.SPCConvectiveDiscussion,
|
|
module.WeatherStory,
|
|
module.OutdoorWindows,
|
|
)
|
|
}
|
|
|
|
func resolveWeekend(req ResolveRequest) (timeutil.Period, error) {
|
|
localNow := req.Now.In(req.Location)
|
|
weekday := localNow.Weekday()
|
|
if weekday == time.Sunday {
|
|
return timeutil.Period{}, fmt.Errorf("weekend outlook is not scheduled on Sunday morning")
|
|
}
|
|
|
|
daysUntilSaturday := (int(time.Saturday) - int(weekday) + 7) % 7
|
|
saturday := localNow.AddDate(0, 0, daysUntilSaturday)
|
|
start := time.Date(saturday.Year(), saturday.Month(), saturday.Day(), 0, 0, 0, 0, req.Location)
|
|
if weekday == time.Friday || weekday == time.Saturday {
|
|
friday := start.AddDate(0, 0, -1)
|
|
fridayEvening := time.Date(friday.Year(), friday.Month(), friday.Day(), 18, 0, 0, 0, req.Location)
|
|
start = fridayEvening
|
|
if localNow.After(start) {
|
|
start = localNow
|
|
}
|
|
}
|
|
end := time.Date(saturday.Year(), saturday.Month(), saturday.Day(), 0, 0, 0, 0, req.Location).AddDate(0, 0, 2)
|
|
return timeutil.Period{Start: start, End: end}, nil
|
|
}
|