first functional version

This commit is contained in:
2021-12-10 15:15:21 -06:00
parent 4278e622ce
commit c9ad2a10f5
5 changed files with 56 additions and 24 deletions

View File

@@ -152,28 +152,30 @@ func initialize() {
setLogLevel(config.LogLevel)
log.SetOutput(config.Log)
// check to make sure options were formatted correctly and can be parsed
config.CalculateDate, err = time.Parse(config.TimeFormat, dt)
if err != nil {
runError(fmt.Sprintf("Unable to parse time: %v\n", err))
}
config.TimeZone, err = time.LoadLocation(tz)
if err != nil {
runError(fmt.Sprintf("Unable to parse time zone: %v\n", err))
}
// check to see if the program was called correctly
if config.On && config.Off {
runError("Can not set '-on' and '-off' at the same time.")
}
if config.Host == "" && (config.On || config.Off || config.GetState) {
runError("Must supply '-host' with '-on', '-off', '-get-state'.")
}
if config.NextSunrise && config.NextSunset {
runError("Can not set '-next-sunrise' and '-next-sunset' at the same time.")
}
// Get timezone offset
_, tzOffset := config.CalculateDate.In(config.TimeZone).Zone()
config.SunRiseSet.UtcOffset = float64(tzOffset / 60 / 60)
}
func runError(errorMsg string) {