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)