From 941892134a7c57ee96feb6ee74b4c32789f606ea Mon Sep 17 00:00:00 2001 From: Christian Tremblay Date: Thu, 16 Feb 2023 23:23:07 -0500 Subject: [PATCH] Related to issue #480 I think date should accept a real date, not just the minus 1900 version (#481) --- py25/bacpypes/primitivedata.py | 1 + py27/bacpypes/primitivedata.py | 1 + py34/bacpypes/primitivedata.py | 1 + tests/test_primitive_data/test_date.py | 7 +++++++ 4 files changed, 10 insertions(+) diff --git a/py25/bacpypes/primitivedata.py b/py25/bacpypes/primitivedata.py index a22e9a45..ce7fc1f0 100755 --- a/py25/bacpypes/primitivedata.py +++ b/py25/bacpypes/primitivedata.py @@ -1294,6 +1294,7 @@ class Date(Atomic): _app_tag = Tag.dateAppTag def __init__(self, arg=None, year=255, month=255, day=255, day_of_week=255): + year = year - 1900 if year >= 1900 else year self.value = (year, month, day, day_of_week) if arg is None: diff --git a/py27/bacpypes/primitivedata.py b/py27/bacpypes/primitivedata.py index a659a2ce..893c5b56 100755 --- a/py27/bacpypes/primitivedata.py +++ b/py27/bacpypes/primitivedata.py @@ -1340,6 +1340,7 @@ class Date(Atomic): _app_tag = Tag.dateAppTag def __init__(self, arg=None, year=255, month=255, day=255, day_of_week=255): + year = year - 1900 if year >= 1900 else year self.value = (year, month, day, day_of_week) if arg is None: diff --git a/py34/bacpypes/primitivedata.py b/py34/bacpypes/primitivedata.py index bf94bca2..57f842e2 100755 --- a/py34/bacpypes/primitivedata.py +++ b/py34/bacpypes/primitivedata.py @@ -1322,6 +1322,7 @@ class Date(Atomic): _app_tag = Tag.dateAppTag def __init__(self, arg=None, year=255, month=255, day=255, day_of_week=255): + year = year - 1900 if year >= 1900 else year self.value = (year, month, day, day_of_week) if arg is None: diff --git a/tests/test_primitive_data/test_date.py b/tests/test_primitive_data/test_date.py index 32cba6e9..c5fba208 100644 --- a/tests/test_primitive_data/test_date.py +++ b/tests/test_primitive_data/test_date.py @@ -181,3 +181,10 @@ def test_Wrong(self): for each in self.notEnoughPreciseOrWrong: Date(each[0]) + def test_date_args(self): + t = Tag() + date = Date(year=2023, month=2, day=10) + date1 = Date(year=123, month=2, day=10) + assert date == date1 + date.encode(t) +