Implement Application Layer with TDD
- Add date utilities for habit scheduling logic - Implement CreateHabitHandler with full validation - Implement GetTodaysHabitsHandler with carry-over support - Implement MarkHabitHandler for completing habits - All components developed following TDD methodology - Complete test coverage for commands and queries
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
func ShouldAppearToday(
|
||||
frequency string,
|
||||
specificDays []int,
|
||||
specificDates []int,
|
||||
targetDate time.Time,
|
||||
) bool {
|
||||
switch frequency {
|
||||
case "DAILY":
|
||||
return true
|
||||
case "WEEKLY":
|
||||
weekday := int(targetDate.Weekday())
|
||||
return contains(specificDays, weekday)
|
||||
case "MONTHLY":
|
||||
day := targetDate.Day()
|
||||
return contains(specificDates, day)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func contains(slice []int, val int) bool {
|
||||
for _, item := range slice {
|
||||
if item == val {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user