aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/histplorer.py10
-rw-r--r--backend/tests/test_histplorer.py2
2 files changed, 8 insertions, 4 deletions
diff --git a/backend/histplorer.py b/backend/histplorer.py
index e5c6c5a..9f9e8ad 100755
--- a/backend/histplorer.py
+++ b/backend/histplorer.py
@@ -31,6 +31,7 @@ DEFAULT_REQ_EVENTS = 20
MAX_REQ_EXCLS = 100
MAX_REQ_SUGGS = 50
DEFAULT_REQ_SUGGS = 5
+MIN_CAL_YEAR = -4713 # Disallow within-year dates before this year
# Classes for objects sent as responses
class HistDate:
@@ -41,9 +42,9 @@ class HistDate:
- 'gcal' may be:
- True: Indicates a Gregorian calendar date
- False: Means the date should be converted and displayed as a Julian calendar date
- - None: 'month' and 'day' are None (used for dates before the Julian period starting year 4713 BCE)
+ - None: 'month' and 'day' are 1 (used for dates before the Julian period starting year 4713 BCE)
"""
- def __init__(self, gcal: bool | None, year: int, month: int | None = None, day: int | None = None):
+ def __init__(self, gcal: bool | None, year: int, month=1, day=1):
self.gcal = gcal
self.year = year
self.month = month
@@ -282,7 +283,10 @@ def eventEntryToResults(
if n is None:
continue
elif fmt == 0:
- newDates[i] = HistDate(None, n)
+ if n >= MIN_CAL_YEAR:
+ newDates[i] = HistDate(True, n, 1, 1)
+ else:
+ newDates[i] = HistDate(None, n)
elif fmt == 1:
newDates[i] = HistDate(False, *jdnToJulian(n))
elif fmt == 2:
diff --git a/backend/tests/test_histplorer.py b/backend/tests/test_histplorer.py
index 32f1404..6487977 100644
--- a/backend/tests/test_histplorer.py
+++ b/backend/tests/test_histplorer.py
@@ -77,7 +77,7 @@ class TestHandleReq(unittest.TestCase):
def test_events_req(self):
response = handleReq(self.dbFile, {'QUERY_STRING': 'type=events&range=-1999.2002-11-1&incl=3&limit=2'})
self.assertEqual(response, [
- Event(5, 'event five', HistDate(None, 2000), None, HistDate(None, 2001), None,
+ Event(5, 'event five', HistDate(True, 2000, 1, 1), None, HistDate(True, 2001, 1, 1), None,
'event', 50, 51),
Event(3, 'event three', HistDate(True, 1990, 10, 10), HistDate(True, 2000, 10, 10), None, None,
'discovery', 30, 0),