Skip to content

Commit

Permalink
fix(Gardens): derive metadata based on compDate being an array not a …
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
stevekaplan123 committed Sep 13, 2023
1 parent 755415d commit f9512cd
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions sefaria/model/garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,24 +441,16 @@ def _derive_metadata(self):
# Time
# This is similar to logic on Index.composition_time_period() refactor
if getattr(self, "start", None) is None or getattr(self, "end", None) is None:
if getattr(i, "compDate", None):
errorMargin = int(getattr(i, "errorMargin", 0))
self.startIsApprox = self.endIsApprox = errorMargin > 0

try:
year = int(getattr(i, "compDate"))
self.start = year - errorMargin
self.end = year + errorMargin
except ValueError as e:
years = getattr(i, "compDate").split("-")
if years[0] == "" and len(years) == 3: #Fix for first value being negative
years[0] = -int(years[1])
years[1] = int(years[2])
self.start = int(years[0]) - errorMargin
self.end = int(years[1]) + errorMargin

elif author and author.mostAccurateTimePeriod():
tp = author.mostAccurateTimePeriod()
years = getattr(i, 'compDate', [])
if years and len(years) > 0:
self.startIsApprox = self.endIsApprox = getattr(i, "hasErrorMargin", False)
if len(years) > 1:
self.start = years[0]
self.end = years[1]
else:
self.start = self.end = years[0]
elif author and author.most_accurate_time_period():
tp = author.most_accurate_time_period()
self.start = tp.start
self.end = tp.end
self.startIsApprox = tp.startIsApprox
Expand Down

0 comments on commit f9512cd

Please sign in to comment.