diff --git a/app/controllers/birthdays_controller.rb b/app/controllers/birthdays_controller.rb index fb9be8d..ada8769 100644 --- a/app/controllers/birthdays_controller.rb +++ b/app/controllers/birthdays_controller.rb @@ -3,7 +3,7 @@ class BirthdaysController < ApplicationController before_filter :authenticate_user!, :except => [:do_mailing] def index - @birthdays = get_birthdays_next_7d + @birthdays = get_birthdays_in_2d # get_birthdays_next_7d @nav_active = "birthdays" end @@ -45,6 +45,14 @@ class BirthdaysController < ApplicationController get_birthdays_next_n_days(2) end + def get_birthdays_in_7d + get_birthdays_in_n_days(7) + end + + def get_birthdays_in_2d + get_birthdays_in_n_days(2) + end + def get_birthdays_next_n_days(num_days) n = Date.today e = Date.today + num_days.days @@ -60,6 +68,11 @@ class BirthdaysController < ApplicationController birthdays end + def get_birthdays_in_n_days(num_days) + target_date = Date.today + num_days.days + birthdays = Contact.where("birth_month = ? AND birth_day = ?", target_date.month, target_date.day) + end + # in: Array [contact,contact,contact,...] # out: Hash[email] = [contact,contact,contact,....] def group_birthdays_by_email(birthday_contacts)