Skip to content

Commit

Permalink
Fix wrong notifcation on morning
Browse files Browse the repository at this point in the history
  • Loading branch information
rupinr committed Oct 28, 2024
1 parent 747c528 commit 2b41543
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ func timeSlotInLocation(currentServerTime *time.Time, schedule *entity.Subscript
func isMorning(localtime time.Time, location time.Location) bool {
six := timeOf(localtime, 6, &location)
twelve := timeOf(localtime, 12, &location)
return localtime.Equal(six) || localtime.After(six) && localtime.Equal(twelve) || localtime.Before(twelve)
return (localtime.Equal(six) || localtime.After(six)) && (localtime.Equal(twelve) || localtime.Before(twelve))
}

func isAfterNoon(localtime time.Time, location time.Location) bool {
twelve := timeOf(localtime, 12, &location)
eighteen := timeOf(localtime, 18, &location)
return localtime.After(twelve) && localtime.Equal(eighteen) || localtime.Before(eighteen)
return localtime.After(twelve) && (localtime.Equal(eighteen) || localtime.Before(eighteen))
}

func isEvening(localtime time.Time, location time.Location) bool {
eighteen := timeOf(localtime, 18, &location)
twenty := timeOf(localtime, 20, &location)
return localtime.After(eighteen) && localtime.Equal(twenty) || localtime.Before(twenty)
return localtime.After(eighteen) && (localtime.Equal(twenty) || localtime.Before(twenty))
}

func timeOf(localTime time.Time, hour int, location *time.Location) time.Time {
Expand Down
19 changes: 19 additions & 0 deletions cmd/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ func TestNotify(t *testing.T) {
},
expectedNotification: false,
},

// Notification on Morning
{
name: "Notification on Morning",
currentServerTime: time.Date(2023, time.October, 28, 0, 0, 0, 0, time.UTC),
subscription: entity.Subscription{
SubscriptionSchedule: entity.SubscriptionSchedule{
TimeZone: "Europe/Berlin",
Monday: true,
Tuesday: true,
Wednesday: true,
Thursday: true,
Friday: true,
Saturday: true,
TimeSlot: common.Morning,
},
},
expectedNotification: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 2b41543

Please sign in to comment.