Skip to content

Commit a94ec80

Browse files
committed
fix birthday bug
1 parent cb2be1e commit a94ec80

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/models/calendar_feed.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
class CalendarFeed
22
def baby_age_event(birthdate = Date.parse(Timeframe::Application.config.local["birthdate"]))
3-
day_count = Date.yesterday - birthdate
3+
today = Time.now.in_time_zone(Timeframe::Application.config.local["timezone"]).to_date
4+
5+
day_count = today - 1.day - birthdate
46
week_count = (day_count / 7).to_i
57

68
if week_count > 24
7-
time_difference = TimeDifference.between(birthdate, Date.yesterday).in_general
9+
time_difference = TimeDifference.between(birthdate, today).in_general
810
months = time_difference[:months]
911
weeks = time_difference[:weeks]
1012
days = time_difference[:days]
13+
years = time_difference[:years]
1114

1215
summary = ""
16+
summary << "#{years}y" if years > 0
1317
summary << "#{months}m" if months > 0
1418
summary << "#{weeks}w" if weeks > 0
1519
summary << "#{days}d" if days > 0

test/models/calendar_feed_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def test_baby_age_event_works_in_evening
3232
end
3333
end
3434

35+
def test_baby_age_event_1_yr
36+
travel_to DateTime.new(2024, 7, 11, 8, 0, 0, "-0600") do
37+
result = CalendarFeed.new.baby_age_event(Date.new(2023, 7, 11))
38+
39+
assert_equal("1y", result.summary)
40+
end
41+
end
42+
3543
# CalendarEvents coming from the DB look different than those
3644
# constructed on the fly. DB events have string keys, for example.
3745
# This is not ideal and we should probably move to a standard value

0 commit comments

Comments
 (0)