Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_birthday should be is_anniversary #298

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def is_same_day(self, dt):
"""
return self == dt

def is_birthday(self, dt=None):
def is_anniversary(self, dt=None):
"""
Check if its the birthday.
Check if its the anniversary.

Compares the date/month values of the two dates.

Expand All @@ -207,10 +207,15 @@ def is_birthday(self, dt=None):
if dt is None:
dt = Date.today()

instance = dt1 = self.__class__(dt.year, dt.month, dt.day)
instance = self.__class__(dt.year, dt.month, dt.day)

return (self.month, self.day) == (instance.month, instance.day)

# the additional method for checking if today is the anniversary day
# the alias is provided to start using a new name and keep the backward compatibility
# the old name can be completely replaced with the new in one of the future versions
is_birthday = is_anniversary

# ADDITIONS AND SUBSTRACTIONS

def add(self, years=0, months=0, weeks=0, days=0):
Expand Down
9 changes: 7 additions & 2 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ def is_same_day(self, dt):

return self.to_date_string() == dt.to_date_string()

def is_birthday(self, dt=None):
def is_anniversary(self, dt=None):
redlickigrzegorz marked this conversation as resolved.
Show resolved Hide resolved
"""
Check if its the birthday.
Check if its the anniversary.
Compares the date/month values of the two dates.

:rtype: bool
Expand All @@ -585,6 +585,11 @@ def is_birthday(self, dt=None):

return (self.month, self.day) == (instance.month, instance.day)

# the additional method for checking if today is the anniversary day
# the alias is provided to start using a new name and keep the backward compatibility
# the old name can be completely replaced with the new in one of the future versions
is_birthday = is_anniversary

# ADDITIONS AND SUBSTRACTIONS

def add(
Expand Down
30 changes: 23 additions & 7 deletions tests/date/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,30 @@ def test_less_than_or_equal_false():
assert not d1 <= d3


def test_is_birthday():
def test_is_anniversary():
redlickigrzegorz marked this conversation as resolved.
Show resolved Hide resolved
d = pendulum.Date.today()
a_birthday = d.subtract(years=1)
assert a_birthday.is_birthday()
not_a_birthday = d.subtract(days=1)
assert not not_a_birthday.is_birthday()
also_not_a_birthday = d.add(days=2)
assert not also_not_a_birthday.is_birthday()
an_anniversary = d.subtract(years=1)
assert an_anniversary.is_anniversary()
not_an_anniversary = d.subtract(days=1)
assert not not_an_anniversary.is_anniversary()
also_not_an_anniversary = d.add(days=2)
assert not also_not_an_anniversary.is_anniversary()

d1 = pendulum.Date(1987, 4, 23)
d2 = pendulum.Date(2014, 9, 26)
d3 = pendulum.Date(2014, 4, 23)
assert not d2.is_anniversary(d1)
assert d3.is_anniversary(d1)


def test_is_birthday(): # backward compatibility
d = pendulum.Date.today()
an_anniversary = d.subtract(years=1)
assert an_anniversary.is_birthday()
not_an_anniversary = d.subtract(days=1)
assert not not_an_anniversary.is_birthday()
also_not_an_anniversary = d.add(days=2)
assert not also_not_an_anniversary.is_birthday()

d1 = pendulum.Date(1987, 4, 23)
d2 = pendulum.Date(2014, 9, 26)
Expand Down
31 changes: 24 additions & 7 deletions tests/datetime/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,32 @@ def test_less_than_or_equal_with_timezone_false():
assert not d1 <= d3


def test_is_birthday():
def test_is_anniversary():
redlickigrzegorz marked this conversation as resolved.
Show resolved Hide resolved
with pendulum.test(pendulum.now()):
d = pendulum.now()
a_birthday = d.subtract(years=1)
assert a_birthday.is_birthday()
not_a_birthday = d.subtract(days=1)
assert not not_a_birthday.is_birthday()
also_not_a_birthday = d.add(days=2)
assert not also_not_a_birthday.is_birthday()
an_anniversary = d.subtract(years=1)
assert an_anniversary.is_anniversary()
not_an_anniversary = d.subtract(days=1)
assert not not_an_anniversary.is_anniversary()
also_not_an_anniversary = d.add(days=2)
assert not also_not_an_anniversary.is_anniversary()

d1 = pendulum.datetime(1987, 4, 23)
d2 = pendulum.datetime(2014, 9, 26)
d3 = pendulum.datetime(2014, 4, 23)
assert not d2.is_anniversary(d1)
assert d3.is_anniversary(d1)


def test_is_birthday(): # backward compatibility
with pendulum.test(pendulum.now()):
d = pendulum.now()
an_anniversary = d.subtract(years=1)
assert an_anniversary.is_birthday()
not_an_anniversary = d.subtract(days=1)
assert not not_an_anniversary.is_birthday()
also_not_an_anniversary = d.add(days=2)
assert not also_not_an_anniversary.is_birthday()

d1 = pendulum.datetime(1987, 4, 23)
d2 = pendulum.datetime(2014, 9, 26)
Expand Down