Cleanup Monday references

main
William Perron 2 months ago
parent 589ef1a207
commit fdc7a77daa
No known key found for this signature in database
GPG Key ID: F701727E6034EEC9

@ -22,10 +22,10 @@ func (s *Store) AddAbsence(ctx context.Context, session time.Time, userId string
)) ))
defer span.End() defer span.End()
if session.Weekday() != time.Monday { if session.Weekday() != time.Wednesday {
log.Debug().Ctx(ctx).Msg(fmt.Sprintf("%s is not a monday", session)) log.Debug().Ctx(ctx).Msg(fmt.Sprintf("%s is not a wednesday", session))
span.RecordError(fmt.Errorf("%s is not a monday", session)) span.RecordError(fmt.Errorf("%s is not a wednesday", session))
return fmt.Errorf("not a monday") return fmt.Errorf("not a wednesday")
} }
defer s.Audit(ctx, &AuditableEvent{ defer s.Audit(ctx, &AuditableEvent{

@ -580,7 +580,7 @@ func main() {
return nil return nil
}, },
"schedule": func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error { "schedule": func(ctx context.Context, s *discordgo.Session, i *discordgo.InteractionCreate) error {
// get schedule from now to 4 mondays into the future // get schedule from now to 4 wednesdays into the future
sched, err := store.GetSchedule(ctx, themis.NextWednesday(), themis.NextWednesday().Add(4*7*24*time.Hour)) sched, err := store.GetSchedule(ctx, themis.NextWednesday(), themis.NextWednesday().Add(4*7*24*time.Hour))
if err != nil { if err != nil {
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
@ -675,17 +675,17 @@ func main() {
return nil return nil
} }
if date.Weekday() != time.Monday { if date.Weekday() != time.Wednesday {
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource, Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{ Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral, Flags: discordgo.MessageFlagsEphemeral,
Content: "The date you provided is not a Monday.", Content: "The date you provided is not a Wednesday.",
}, },
}); err != nil { }); err != nil {
return fmt.Errorf("failed to respond to interaction: %w", err) return fmt.Errorf("failed to respond to interaction: %w", err)
} }
// TODO(wperron) suggest Mondays before and after? // TODO(wperron) suggest Wednesdays before and after?
return nil return nil
} }
@ -753,7 +753,7 @@ func main() {
var msg string var msg string
var components []discordgo.MessageComponent var components []discordgo.MessageComponent
if len(absentees) == 0 { if len(absentees) == 0 {
msg = "Everybody can make it next Monday, see you then! 🎉" msg = "Everybody can make it next Wednesday, see you then! 🎉"
components = []discordgo.MessageComponent{ components = []discordgo.MessageComponent{
discordgo.ActionsRow{ discordgo.ActionsRow{
Components: []discordgo.MessageComponent{ Components: []discordgo.MessageComponent{
@ -770,7 +770,7 @@ func main() {
}, },
} }
} else { } else {
msg = fmt.Sprintf("%s can't make it next Monday. 🙁", themis.FormatStringSlice(absentees)) msg = fmt.Sprintf("%s can't make it next Wednesday. 🙁", themis.FormatStringSlice(absentees))
} }
_, err = discord.ChannelMessageSendComplex(channelId, &discordgo.MessageSend{ _, err = discord.ChannelMessageSendComplex(channelId, &discordgo.MessageSend{

@ -34,7 +34,7 @@ func (n *Notifier) Start(ctx context.Context) {
t, err := time.ParseInLocation(time.DateTime, fmt.Sprintf("%s 17:00:00", sat.Format(time.DateOnly)), loc) t, err := time.ParseInLocation(time.DateTime, fmt.Sprintf("%s 17:00:00", sat.Format(time.DateOnly)), loc)
if err != nil { if err != nil {
panic("failed to parse next monday notif time. this is likely a bug.") panic("failed to parse next wednesday notif time. this is likely a bug.")
} }
log.Debug().Time("next", t).Msg("starting notifier instance") log.Debug().Time("next", t).Msg("starting notifier instance")

@ -8,10 +8,6 @@ func init() {
now = time.Now now = time.Now
} }
func NextMonday() time.Time {
return now().AddDate(0, 0, int((8-now().Weekday())%7))
}
func NextWednesday() time.Time { func NextWednesday() time.Time {
return now().AddDate(0, 0, int((10-now().Weekday())%7)) return now().AddDate(0, 0, int((10-now().Weekday())%7))
} }

@ -6,14 +6,14 @@ import (
"time" "time"
) )
func TestNextMonday(t *testing.T) { func TestNextWednesday(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
seed string seed string
want string want string
}{ }{
{ {
name: "on monday", name: "on wednesday",
seed: "2023-11-13T15:04:05Z07:00", seed: "2023-11-13T15:04:05Z07:00",
want: "2023-11-13T15:04:05Z07:00", want: "2023-11-13T15:04:05Z07:00",
}, },
@ -38,8 +38,8 @@ func TestNextMonday(t *testing.T) {
seedt, _ := time.Parse(time.RFC3339, tt.seed) seedt, _ := time.Parse(time.RFC3339, tt.seed)
now = func() time.Time { return seedt } now = func() time.Time { return seedt }
wantt, _ := time.Parse(time.RFC3339, tt.want) wantt, _ := time.Parse(time.RFC3339, tt.want)
if got := NextMonday(); !reflect.DeepEqual(got, wantt) { if got := NextWednesday(); !reflect.DeepEqual(got, wantt) {
t.Errorf("NextMonday() = %v, want %v", got, wantt) t.Errorf("NextWednesday() = %v, want %v", got, wantt)
} }
}) })
} }

Loading…
Cancel
Save