Skip to content

Commit

Permalink
squashed merge of development in test-living-again branch
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronD73 committed Nov 3, 2024
1 parent 8ca2326 commit 7811760
Show file tree
Hide file tree
Showing 5 changed files with 834 additions and 475 deletions.
2 changes: 1 addition & 1 deletion gramps/gen/filters/rules/test/person_rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def test_ProbablyAlive(self):
"""
rule = ProbablyAlive(["1900"])
res = self.filter_with_rule(rule)
self.assertEqual(len(res), 733)
self.assertEqual(len(res), 897)

def test_RegExpName(self):
"""
Expand Down
52 changes: 31 additions & 21 deletions gramps/gen/lib/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ class Date(BaseObject):
The core date handling class for Gramps.
Supports partial dates, compound dates and alternate calendars.
Create a new Date instance using one of the following:
Date() - an empty (invalid) date
Date( other_date ) - duplicate another Date
Date( year ) - create an exact date - 1st Jan of the specified year
Date( year, month ) - create an exact date - 1st of the given month, year
Date( year, month, day ) - create an exact date
"""

MOD_NONE = 0 # CODE
Expand Down Expand Up @@ -1022,12 +1028,12 @@ def match(self, other_date, comparison="="):
Comparison Returns
========== =======================================================
=,== True if any part of other_date matches any part of self
< True if any part of other_date < any part of self
<= True if any part of other_date <= any part of self
<< True if all parts of other_date < all parts of self
> True if any part of other_date > any part of self
>= True if any part of other_date >= any part of self
>> True if all parts of other_date > all parts of self
< True if any part of self < any part of other_date
<= True if any part of self <= any part of other_date
<< True if all parts of self < all parts of other_date
> True if any part of self > any part of other_date
>= True if any part of self >= any part of other_date
>> True if all parts of self > all parts of other_date
========== =======================================================
"""
if Date.MOD_TEXTONLY in [other_date.modifier, self.modifier]:
Expand Down Expand Up @@ -1408,6 +1414,11 @@ def set_yr_mon_day(self, year, month, day, remove_stop_date=None):
def _assert_compound(self):
if not self.is_compound():
raise DateError("Operation allowed for compound dates only!")
# ensure the dateval structure is suitable
if len(self.dateval) == 4:
dlist = list(self.dateval)
dlist.extend(self.EMPTY)
self.dateval = tuple(dlist)

def set2_yr_mon_day(self, year, month, day):
"""
Expand Down Expand Up @@ -1450,6 +1461,7 @@ def __set_yr_mon_day_offset(self, year, month, day, pos_yr, pos_mon, pos_day):
def set_yr_mon_day_offset(self, year=0, month=0, day=0):
"""
Offset the date by the given year, month, and day values.
If the source is a compound date then both are offset.
"""
if self.__set_yr_mon_day_offset(
year, month, day, Date._POS_YR, Date._POS_MON, Date._POS_DAY
Expand All @@ -1473,6 +1485,7 @@ def set2_yr_mon_day_offset(self, year=0, month=0, day=0):
def copy_offset_ymd(self, year=0, month=0, day=0):
"""
Return a Date copy based on year, month, and day offset.
If the source is a compound date then both are offset.
"""
orig_cal = self.calendar
if self.calendar != 0:
Expand Down Expand Up @@ -1735,15 +1748,7 @@ def set(
self.calendar = calendar
self.dateval = value
self.set_new_year(newyear)
year, month, day = self._zero_adjust_ymd(
value[Date._POS_YR], value[Date._POS_MON], value[Date._POS_DAY]
)

if year == month == day == 0:
self.sortval = 0
else:
func = Date._calendar_convert[calendar]
self.sortval = func(year, month, day)
self._calc_sort_value()

if self.get_slash() and self.get_calendar() != Date.CAL_JULIAN:
self.set_calendar(Date.CAL_JULIAN)
Expand Down Expand Up @@ -1814,14 +1819,19 @@ def _calc_sort_value(self):
"""
Calculate the numerical sort value associated with the date.
"""
year, month, day = self._zero_adjust_ymd(
self.dateval[Date._POS_YR],
self.dateval[Date._POS_MON],
self.dateval[Date._POS_DAY],
)
if year == month == 0 and day == 0:
if (
self.dateval[Date._POS_YR]
== self.dateval[Date._POS_MON]
== self.dateval[Date._POS_DAY]
== 0
):
self.sortval = 0
else:
year, month, day = self._zero_adjust_ymd(
self.dateval[Date._POS_YR],
self.dateval[Date._POS_MON],
self.dateval[Date._POS_DAY],
)
func = Date._calendar_convert[self.calendar]
self.sortval = func(year, month, day)

Expand Down
1 change: 1 addition & 0 deletions gramps/gen/lib/eventtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def is_death_fallback(self):
self.BURIAL,
self.CREMATION,
self.CAUSE_DEATH,
self.PROBATE,
]

def is_marriage(self):
Expand Down
10 changes: 5 additions & 5 deletions gramps/gen/lib/test/date_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,11 +1577,11 @@ class AgeTest(BaseDateTest):
"2000",
"40 years",
),
("", "1760", "greater than 110 years"),
("", "1960", "greater than 110 years"),
("", "2020", "greater than 110 years"),
("", "3020", "greater than 110 years"),
("2000", "", "(1999 years)"),
("", "1760", "unknown"),
("", "1960", "unknown"),
("", "2020", "unknown"),
("", "3020", "unknown"),
("2000", "", "unknown"),
]

def convert_to_date(self, d):
Expand Down
Loading

0 comments on commit 7811760

Please sign in to comment.