-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"When?" bot #83
"When?" bot #83
Conversation
remove when cmd implementation for "when bot" enable the "when bot"
Pull Request Test Coverage Report for Build 3567923629
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx. A few minor things/suggestions
app/bot/when.go
Outdated
} | ||
|
||
// closestPrevNextWeekdays returns closest next `weekday` at `hour`:`minute` after `t`. | ||
func closestPrevNextWeekdays(t time.Time, weekday time.Weekday, hour, minute int) (time.Time, time.Time) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this supposed to be called closestPrevNextWeekend? Or maybe closestPrevNextSat?
Actually, I'm not fully certain what this func supposed to do and how it does it. From the caller side it looks like an attempt to discover times of the prev and next start of the podcast stream, but I don't really understand this implementation. Alternatively I can think on a simple loop adding 6 days to the current day and for back till it gets a pair of Sat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is pretty easy (but reading this is not so easy). I try to change a function for our concrete purpose with hardcode. I dont like it, but it will be easy to rewrite this function by someone.
I try to explain current behaviour:
- Get an absolute diff in days between current weekday and stream weekday.
daysDiff
- Add this diff to current timestamp. now.Date() +
daysDiff
. This is date of stream - Create a new time.Time obj with date of stream, and constant hours of stream
- Also, get the prev (or next) stream date depends on current calculation
Check out commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I missed the point, this is way too much for what it does. Isn't replacing this thing with a trivial "gimme time duration from now till the next show" enough? It will get rid of prev/next thing completely and will give you back directly what you are looking for - duration till the next show.
func(w *When) tillNextShow(t time.Time) (time.Duration) {
next := t.AddDate(0, 0, int(time.Saturday-t.Weekday()))
next = time.Date(next.Year(), next.Month(), next.Day(), 20, 0, 0, 0, time.UTC)
return t.Sub(next)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
closes #82