From 10d38ad31612cd0a845ff15096ee107c0735c3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 15 Aug 2023 21:26:32 +0200 Subject: [PATCH] misc: change |age_in_working_days so it can return negative values (#71759) --- tests/test_templates.py | 4 ++-- wcs/qommon/templatetags/qommon.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_templates.py b/tests/test_templates.py index 6e8c729a6..e91fee3b2 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -1162,9 +1162,9 @@ def test_age_in_working_days_settings(settings, pub, freezer): assert t.render({'value': '2020-07-12'}) == '2' settings.WORKING_DAY_CALENDAR = 'workalendar.europe.France' t = Template('{{ value|age_in_working_days }}') - assert t.render({'value': '2020-07-12'}) == '7' + assert t.render({'value': '2020-07-12'}) == '-7' t = Template('{{ value|age_in_working_days_with_saturday }}') - assert t.render({'value': '2020-07-12'}) == '9' + assert t.render({'value': '2020-07-12'}) == '-9' pub.site_options.set('options', 'working_day_calendar', 'foobar') with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd: diff --git a/wcs/qommon/templatetags/qommon.py b/wcs/qommon/templatetags/qommon.py index 07c416bbf..860f081d1 100644 --- a/wcs/qommon/templatetags/qommon.py +++ b/wcs/qommon/templatetags/qommon.py @@ -482,7 +482,10 @@ def age_in_working_days(value, arg=None, saturday_is_a_working_day=False): if not cal: return '' - return cal.get_working_days_delta(value, arg) + delta = cal.get_working_days_delta(value, arg) + if arg.timetuple() < value.timetuple(): + delta = -delta + return delta @register.filter(expects_localtime=True) -- 2.39.2