Skip to content

Commit

Permalink
Merge pull request #1643 from Sefaria/patch_for_normalized_dates
Browse files Browse the repository at this point in the history
chore: set years to 3000 ignore compDate
  • Loading branch information
akiva10b authored Sep 20, 2023
2 parents e8c28c0 + 40cd092 commit d866edb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion sefaria/client/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def format_link_object_for_client(link, with_text, ref, pos=None):
compDate = getattr(linkRef.index, "compDate", None)
if compDate:
try:
com["compDate"] = int(compDate)
com["compDate"] = 3000
except ValueError:
com["compDate"] = 3000 # default comp date to in the future
try:
Expand Down
24 changes: 12 additions & 12 deletions sefaria/model/garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,18 @@ def _derive_metadata(self):
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
self.start = self.end = 3000
# 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()
Expand Down
60 changes: 30 additions & 30 deletions sefaria/model/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,21 @@ def best_time_period(self):
if getattr(self, "compDate", None):
errorMargin = int(getattr(self, "errorMargin", 0))
self.startIsApprox = self.endIsApprox = errorMargin > 0

try:
year = int(getattr(self, "compDate"))
start = year - errorMargin
end = year + errorMargin
except ValueError as e:
years = getattr(self, "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])
try:
start = int(years[0]) - errorMargin
end = int(years[1]) + errorMargin
except UnicodeEncodeError as e:
pass
start = end = 3000
# try:
# year = int(getattr(self, "compDate"))
# start = year - errorMargin
# end = year + errorMargin
# except ValueError as e:
# years = getattr(self, "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])
# try:
# start = int(years[0]) - errorMargin
# end = int(years[1]) + errorMargin
# except UnicodeEncodeError as e:
# pass

else:
author = self.author_objects()[0] if len(self.author_objects()) > 0 else None
Expand Down Expand Up @@ -510,21 +510,21 @@ def _get_time_period(self, date_field, margin_field=None):
except ValueError:
error_margin = 0
startIsApprox = endIsApprox = error_margin > 0

try:
year = int(getattr(self, date_field))
start = year - error_margin
end = year + error_margin
except ValueError as e:
try:
years = getattr(self, date_field).split("-")
if years[0] == "" and len(years) == 3: #Fix for first value being negative
years[0] = -int(years[1])
years[1] = int(years[2])
start = int(years[0]) - error_margin
end = int(years[1]) + error_margin
except ValueError as e:
return None
start = end = 3000
# try:
# year = int(getattr(self, date_field))
# start = year - error_margin
# end = year + error_margin
# except ValueError as e:
# try:
# years = getattr(self, date_field).split("-")
# if years[0] == "" and len(years) == 3: #Fix for first value being negative
# years[0] = -int(years[1])
# years[1] = int(years[2])
# start = int(years[0]) - error_margin
# end = int(years[1]) + error_margin
# except ValueError as e:
# return None
return timeperiod.TimePeriod({
"start": start,
"startIsApprox": startIsApprox,
Expand Down

0 comments on commit d866edb

Please sign in to comment.