Skip to content

Commit

Permalink
Prepare an alias for is_birthday to have more universal method
Browse files Browse the repository at this point in the history
  • Loading branch information
redlickigrzegorz committed Oct 28, 2018
1 parent a111349 commit 7c76ddc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
7 changes: 6 additions & 1 deletion pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_anniversary = is_birthday

# ADDITIONS AND SUBSTRACTIONS

def add(self, years=0, months=0, weeks=0, days=0):
Expand Down
5 changes: 5 additions & 0 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,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_anniversary = is_birthday

# ADDITIONS AND SUBSTRACTIONS

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


def test_is_birthday():
def test_is_anniversary():
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_birthday(d1)
assert d3.is_birthday(d1)
assert not d2.is_anniversary(d1)
assert d3.is_anniversary(d1)


def test_closest():
Expand Down
18 changes: 9 additions & 9 deletions tests/datetime/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,21 @@ def test_less_than_or_equal_with_timezone_false():
assert not d1 <= d3


def test_is_birthday():
def test_is_anniversary():
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_birthday(d1)
assert d3.is_birthday(d1)
assert not d2.is_anniversary(d1)
assert d3.is_anniversary(d1)


def test_closest():
Expand Down

0 comments on commit 7c76ddc

Please sign in to comment.