From b2d8bf4e062c18a71a1115ff204d7ac57d31288a Mon Sep 17 00:00:00 2001 From: cesarvh Date: Wed, 13 Mar 2019 12:28:20 -0700 Subject: [PATCH] CC-397: Fixed BP date ranges to be based off 1950 not the curr year --- .../antlr/ANTLRStructuredDateEvaluator.java | 12 +++----- .../src/test/resources/test-dates.yaml | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java b/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java index bfa622ff3..89e82f3ea 100644 --- a/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java +++ b/services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/antlr/ANTLRStructuredDateEvaluator.java @@ -105,6 +105,7 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp * The result of the evaluation. */ protected StructuredDateInternal result; + private final int BP_ZERO_YEAR = 1950; /** * The operation stack. The parse listener methods that are implemented here @@ -1244,15 +1245,10 @@ public class ANTLRStructuredDateEvaluator extends StructuredDateBaseListener imp if (ctx.exception != null) return; Integer adjustmentDate = (Integer) stack.pop(); - Integer mainYear = (Integer) stack.pop(); + Integer mainYear = (Integer) stack.pop(); - Integer upperBound = mainYear + adjustmentDate; - Integer lowerBound = mainYear - adjustmentDate; - - Integer currentYear = DateUtils.getCurrentDate().getYear(); - - Integer earliestYear = currentYear - upperBound; - Integer latestYear = currentYear - lowerBound ; + Integer earliestYear = (BP_ZERO_YEAR - mainYear) - adjustmentDate; + Integer latestYear = (BP_ZERO_YEAR - mainYear) + adjustmentDate; // If negative, then BC, else AD Era earliestEra = earliestYear < 0 ? Era.BCE : Era.CE; diff --git a/services/structureddate/structureddate/src/test/resources/test-dates.yaml b/services/structureddate/structureddate/src/test/resources/test-dates.yaml index bd9d8d26e..344737e8f 100644 --- a/services/structureddate/structureddate/src/test/resources/test-dates.yaml +++ b/services/structureddate/structureddate/src/test/resources/test-dates.yaml @@ -1198,29 +1198,29 @@ earliestSingleDate: [9, 7, 31, CE] latestDate: [1996, 4, 1, CE] - "1200±50 BP": # Uncalibrated date with ± symbol, with CE - earliestSingleDate: "uncalibrated earliest date" - latestDate: "uncalibrated latest date" + "1200±50 BP": # Uncalibrated date with ± symbol + earliestSingleDate: [700, 1, 1, CE] + latestDate: [800, 12, 31, CE ] "3100 +/- 150 BP": # Uncalibrated date with +/- instead of ± symbol - earliestSingleDate: "uncalibrated earliest date" - latestDate: "uncalibrated latest date" + earliestSingleDate: [1300, 1, 1, BCE] + latestDate: [1000, 12, 31, BCE] "3100+/-150 BP": # Uncalibrated date with +/- instead of ± symbol, no spaces - earliestSingleDate: "uncalibrated earliest date" - latestDate: "uncalibrated latest date" + earliestSingleDate: [1300, 1, 1, BCE] + latestDate: [1000, 12, 31, BCE] "3100+/-150 years BP": # Uncalibrated date with 'years' in it - earliestSingleDate: "uncalibrated earliest date" - latestDate: "uncalibrated latest date" + earliestSingleDate: [1300, 1, 1, BCE] + latestDate: [1000, 12, 31, BCE] "3,100+/-150 years BP": # Uncalibrated date with 'years' in it as well as with a comma - earliestSingleDate: "uncalibrated earliest date" - latestDate: "uncalibrated latest date" + earliestSingleDate: [1300, 1, 1, BCE] + latestDate: [1000, 12, 31, BCE] "2000±100 BP": # Uncalibrated date with BCE and AD mix - earliestSingleDate: "uncalibrated earliest date" - latestDate: "uncalibrated latest date" + earliestSingleDate: [150, 1, 1, BCE] + latestDate: [50, 12, 31, CE] "5580-5460 BC": # Calibrated date with commas earliestSingleDate: [5580, 1, 1, BCE] @@ -1268,6 +1268,10 @@ '01-IV-2017 BCE': # Day-Month-Year with roman numeral as month, with Era earliestSingleDate: [2017, 4, 1, BCE] + + # '12 june 1942 - 13 june 1943': # hyphenatedRange, date with comma'd numbers + # earliestSingleDate: [1942, 6, 12, CE] + # latestDate: [1942, 6, 13, CE] # ------------------------------------------------------------------------------------------------------- # Invalid dates -- 2.47.3