Skip to content

Commit

Permalink
Fixed bug with calculating the age of parents in tree diagrams (fix #610
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Serg-Norseman committed Jan 30, 2025
1 parent cabd30b commit 3afcee2
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 56 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p><b>??.??.2025 [v2.32.1 &amp; v3.8.1]</b></p>
<ul>
<li>Fixed a bug with calculating the age of parents in tree diagrams.</li>
<li>Added calling of ancestor, descendant and all persons maps from tree diagrams.</li>
<li>Added a number of checks for adding invalid links between different records.</li>
<li>Added functions for moving multimedia files between absolute and relative paths, archive and storage.</li>
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p><b>??.??.2025 [v2.32.1 &amp; v3.8.1]</b></p>
<ul>
<li>Исправлена ошибка расчета возраста родителей в диаграммах деревьев.</li>
<li>Добавлен вызов карт предков, потомков и всех персон из диаграмм деревьев.</li>
<li>Добавлен ряд проверок на добавление недопустимых ссылок между различными записями.</li>
<li>Добавлены функции перемещения мультимедиа-файлов между абсолютными и относительными путями, архивом и хранилищем.</li>
Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GDModel/GDMDate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -520,7 +520,7 @@ public static GDMDate CreateByFormattedStr(string dateStr, GDMCalendar calendar,
public static UDN GetUDNByFormattedStr(string dateStr, GDMCalendar calendar, bool aException = false)
{
GDMDate dtx = GDMDate.CreateByFormattedStr(dateStr, calendar, aException);
return (dtx != null) ? dtx.GetUDN() : UDN.CreateUnknown();
return (dtx != null) ? dtx.GetUDN() : UDN.Unknown;
}

public string GetDisplayString(DateFormat format, bool includeBC = false, bool showCalendar = false)
Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GDModel/GDMDatePeriod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -150,7 +150,7 @@ public override UDN GetUDN()
} else if (!toEmpty) {
result = UDN.CreateBefore(fDateTo.GetUDN());
} else {
result = UDN.CreateUnknown();
result = UDN.Unknown;
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GDModel/GDMDateRange.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -148,7 +148,7 @@ public override UDN GetUDN()
} else if (!befEmpty) {
result = UDN.CreateBefore(fDateBefore.GetUDN());
} else {
result = UDN.CreateUnknown();
result = UDN.Unknown;
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion projects/GKCore/GDModel/GDMDateValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override float IsMatch(GDMTag tag, MatchParams matchParams)

public override UDN GetUDN()
{
return (fValue == null) ? UDN.CreateUnknown() : fValue.GetUDN();
return (fValue == null) ? UDN.Unknown : fValue.GetUDN();
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions projects/GKCore/GDModel/GDMRecordWithEvents.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -181,13 +181,13 @@ public GDMCustomEvent FindEvent(GEDCOMTagType eventType)
public UDN GetUDN(string eventSign)
{
GDMCustomEvent evt = FindEvent(eventSign);
return (evt == null) ? UDN.CreateUnknown() : evt.Date.GetUDN();
return (evt == null) ? UDN.Unknown : evt.Date.GetUDN();
}

public UDN GetUDN(GEDCOMTagType eventType)
{
GDMCustomEvent evt = FindEvent(eventType);
return (evt == null) ? UDN.CreateUnknown() : evt.Date.GetUDN();
return (evt == null) ? UDN.Unknown : evt.Date.GetUDN();
}

/// <summary>
Expand Down
15 changes: 4 additions & 11 deletions projects/GKCore/GKCore/Calendar/UDN.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2016-2023 by Sergey V. Zhdanovskih, Ruslan Garipov.
* Copyright (C) 2016-2025 by Sergey V. Zhdanovskih, Ruslan Garipov.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -33,6 +33,9 @@ public enum UDNCalendarType { ctGregorian, ctJulian, ctHebrew, ctIslamic }
/// </summary>
public struct UDN : ICloneable<UDN>, IComparable, IComparable<UDN>, IEquatable<UDN>
{
public static readonly UDN Empty = new UDN(0);
public static readonly UDN Unknown = new UDN(UDNCalendarType.ctGregorian, UnknownYear, UnknownMonth, UnknownDay);

private const int IgnoreYear = 1 << 31;
private const int IgnoreMonth = 1 << 30;
private const int IgnoreDay = 1 << 29;
Expand Down Expand Up @@ -522,16 +525,6 @@ public static UDN CreateBetween(UDN left, UDN right, bool checkYears = true)
return new UDN(value);
}

public static UDN CreateEmpty()
{
return new UDN(0);
}

public static UDN CreateUnknown()
{
return new UDN(UDNCalendarType.ctGregorian, UnknownYear, UnknownMonth, UnknownDay);
}

#endregion

/// <summary>Checks year part of this date.</summary>
Expand Down
26 changes: 8 additions & 18 deletions projects/GKCore/GKCore/Charts/TreeChartPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,29 +438,19 @@ public void SetParents()
FatherAge = string.Empty;
MotherAge = string.Empty;

GDMCustomEvent evt = fRec.FindEvent(GEDCOMTagName.BIRT);
if (evt == null) return;
int childYear = evt.GetChronologicalYear();
if (childYear == 0) return;
GDMCustomEvent evtChild = fRec.FindEvent(GEDCOMTagName.BIRT);
if (evtChild == null || !evtChild.Date.GetUDN().HasKnownYear()) return;

if (Father != null && Father.Rec != null) {
evt = Father.Rec.FindEvent(GEDCOMTagName.BIRT);
if (evt != null) {
int parentYear = evt.GetChronologicalYear();
if (parentYear != 0) {
FatherAge = (childYear - parentYear).ToString();
}
}
var evtFth = Father.Rec.FindEvent(GEDCOMTagName.BIRT);
var diff = GKUtils.GetEventsYearsDiff(evtFth, evtChild, false);
FatherAge = (diff != -1) ? diff.ToString() : string.Empty;
}

if (Mother != null && Mother.Rec != null) {
evt = Mother.Rec.FindEvent(GEDCOMTagName.BIRT);
if (evt != null) {
int parentYear = evt.GetChronologicalYear();
if (parentYear != 0) {
MotherAge = (childYear - parentYear).ToString();
}
}
var evtMth = Mother.Rec.FindEvent(GEDCOMTagName.BIRT);
var diff = GKUtils.GetEventsYearsDiff(evtMth, evtChild, false);
MotherAge = (diff != -1) ? diff.ToString() : string.Empty;
}
}

Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GKCore/Export/PedigreeExporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -74,7 +74,7 @@ public PedigreeEvent(GDMIndividualRecord iRec, GDMCustomEvent evt)
{
IRec = iRec;
Event = evt;
Date = (evt == null) ? UDN.CreateUnknown() : evt.Date.GetUDN();
Date = (evt == null) ? UDN.Unknown : evt.Date.GetUDN();
Sources = new List<string>();
}
}
Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GKCore/GKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,11 @@ public static int GetEventsYearsDiff(GDMCustomEvent ev1, GDMCustomEvent ev2, boo
result = Math.Abs(dt2 - dt1);
}
#else
var udn1 = (ev1 == null) ? UDN.CreateUnknown() : ev1.Date.GetUDN();
var udn1 = (ev1 == null) ? UDN.Unknown : ev1.Date.GetUDN();
if (udn1.HasKnownYear()) {
DateTime dt1 = udn1.GetGregorianDateTime();

var udn2 = (ev2 == null) ? UDN.CreateUnknown() : ev2.Date.GetUDN();
var udn2 = (ev2 == null) ? UDN.Unknown : ev2.Date.GetUDN();
DateTime dt2;
if (udn2.HasKnownYear()) {
dt2 = udn2.GetGregorianDateTime();
Expand Down
6 changes: 3 additions & 3 deletions projects/GKCore/GKCore/Lists/IndividualListModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -358,8 +358,8 @@ private bool CheckSpecificFilter()
break;

case FilterLifeMode.lmAliveBefore:
UDN bdt = (buf_bd == null) ? UDN.CreateUnknown() : buf_bd.Date.GetUDN();
UDN ddt = (buf_dd == null) ? UDN.CreateUnknown() : buf_dd.Date.GetUDN();
UDN bdt = (buf_bd == null) ? UDN.Unknown : buf_bd.Date.GetUDN();
UDN ddt = (buf_dd == null) ? UDN.Unknown : buf_dd.Date.GetUDN();
if ((bdt.CompareTo(filter_abd) > 0) || (ddt.CompareTo(filter_abd) < 0)) return false;
break;

Expand Down
8 changes: 5 additions & 3 deletions projects/GKCore/GKCore/Lists/ListSource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -529,10 +529,12 @@ public int GetFieldColumnId(string[] fields, string fieldName)

#region Cell values

private static readonly object UnknownUDNObject = (object)UDN.Unknown;

protected static object GetDateValue(GDMCustomEvent evt, bool isVisible)
{
if (evt == null) {
return (isVisible) ? null : (object)UDN.CreateUnknown();
return (isVisible) ? null : UnknownUDNObject;
}

return GetDateValue(evt.Date.Value, isVisible);
Expand All @@ -543,7 +545,7 @@ protected static object GetDateValue(GDMCustomDate date, bool isVisible)
object result;

if (date == null) {
result = (isVisible) ? null : (object)UDN.CreateUnknown();
result = (isVisible) ? null : UnknownUDNObject;
} else {
if (isVisible) {
GlobalOptions glob = GlobalOptions.Instance;
Expand Down
4 changes: 2 additions & 2 deletions projects/GKTests/GDModel/GDMCustomEventTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -192,7 +192,7 @@ public void Test_GDMIndividualEvent()
[Test]
public void Test_UDN()
{
UDN emptyUDN = UDN.CreateEmpty();
UDN emptyUDN = UDN.Empty;
Assert.IsTrue(emptyUDN.IsEmpty());

// BIRT: "28 DEC 1990"
Expand Down
4 changes: 2 additions & 2 deletions projects/GKTests/GDModel/GDMDateTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -619,7 +619,7 @@ public void Test_CreateByFormattedStr_3args()
[Test]
public void Test_GetUDNByFormattedStr()
{
UDN expResult = UDN.CreateUnknown();
UDN expResult = UDN.Unknown;
UDN result = GDMDate.GetUDNByFormattedStr("", GDMCalendar.dcGregorian);
Assert.AreEqual(expResult, result);
}
Expand Down
4 changes: 3 additions & 1 deletion projects/GKTests/GKCore/GKUtilsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -704,6 +704,8 @@ public void Test_GetDifferenceInYears()
Assert.AreEqual(19, GKUtils.GetDifferenceInYears(DateTime.Parse("1987-09-23T00:00:00"), DateTime.Parse("2007-06-15T00:00:00"))); // 3 monthes to 20

Assert.AreEqual(45, GKUtils.GetDifferenceInYears(DateTime.Parse("1979-01-20T00:00:00"), DateTime.Parse("2024-05-05T00:00:00"))); // 45

Assert.AreEqual(37, GKUtils.GetDifferenceInYears(DateTime.Parse("1957-03-05T00:00:00"), DateTime.Parse("1995-02-15T00:00:00"))); // 37
}
}
}
4 changes: 2 additions & 2 deletions projects/plugins/GKStdReports/PersonalEventsReport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2018-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2018-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -56,7 +56,7 @@ public PersonalEvent(EventType type, GDMRecord rec, GDMCustomEvent evt)
Type = type;
Rec = rec;
Event = evt;
Date = (evt == null) ? UDN.CreateUnknown() : evt.Date.GetUDN();
Date = (evt == null) ? UDN.Unknown : evt.Date.GetUDN();
}
}

Expand Down

0 comments on commit 3afcee2

Please sign in to comment.