Add birthday filters

This commit is contained in:
Miguel de la Cruz 2023-06-30 10:10:58 +02:00
parent 5812505763
commit c617fe2505

View file

@ -51,3 +51,45 @@ func NewBirthdayFromRecord(record []string) (*Birthday, error) {
return b, nil
}
func FilterByYear(birthdays []*Birthday, year int) []*Birthday {
filteredBirthdays := []*Birthday{}
for _, birthday := range birthdays {
if birthday.YearOfBirth == year {
filteredBirthdays = append(filteredBirthdays, birthday)
}
}
return filteredBirthdays
}
func FilterByMonth(birthdays []*Birthday, month int) []*Birthday {
filteredBirthdays := []*Birthday{}
for _, birthday := range birthdays {
if birthday.MonthOfBirth == month {
filteredBirthdays = append(filteredBirthdays, birthday)
}
}
return filteredBirthdays
}
func FilterByDay(birthdays []*Birthday, day int) []*Birthday {
filteredBirthdays := []*Birthday{}
for _, birthday := range birthdays {
if birthday.DayOfBirth == day {
filteredBirthdays = append(filteredBirthdays, birthday)
}
}
return filteredBirthdays
}
func FilterByDate(birthdays []*Birthday, day, month, year int) []*Birthday {
filteredBirthdays := []*Birthday{}
for _, birthday := range birthdays {
if birthday.DayOfBirth == day &&
birthday.MonthOfBirth == month &&
birthday.YearOfBirth == year {
filteredBirthdays = append(filteredBirthdays, birthday)
}
}
return filteredBirthdays
}