From bc0abd9cfd7f2cc94f849de54cab89b2e9871928 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Thu, 10 Nov 2022 15:18:49 +0530 Subject: [PATCH] feat(util): add is_last_day_of_the_month (#18835) * feat: add is_last_day_of_the_month --- frappe/tests/test_utils.py | 4 ++++ frappe/utils/data.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/frappe/tests/test_utils.py b/frappe/tests/test_utils.py index 9f3d8d00f8..44966691a0 100644 --- a/frappe/tests/test_utils.py +++ b/frappe/tests/test_utils.py @@ -493,6 +493,10 @@ class TestDateUtils(FrappeTestCase): frappe.utils.get_last_day_of_week("2020-12-28"), frappe.utils.getdate("2021-01-02") ) + def test_is_last_day_of_the_month(self): + self.assertEqual(frappe.utils.is_last_day_of_the_month("2020-12-24"), False) + self.assertEqual(frappe.utils.is_last_day_of_the_month("2020-12-31"), True) + def test_get_time(self): datetime_input = now_datetime() timedelta_input = get_timedelta() diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 8f0065b04c..00572c1ae5 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -471,6 +471,12 @@ def get_last_day(dt): return get_first_day(dt, 0, 1) + datetime.timedelta(-1) +def is_last_day_of_the_month(dt): + last_day_of_the_month = get_last_day(dt) + + return getdate(dt) == getdate(last_day_of_the_month) + + def get_quarter_ending(date): date = getdate(date)