/// <summary> /// This function compares dates only by chronological year. /// Month and day are not taken into account, the year is compared with the calendar. /// </summary> /// <param name="tag"></param> /// <param name="matchParams"></param> /// <returns></returns> public override float IsMatch(GDMCustomDate tag, MatchParams matchParams) { if (tag == null) { return(0.0f); } GDMDateValue date = (GDMDateValue)tag; if (IsEmpty() || date.IsEmpty()) { return(0.0f); } int absVal1 = this.GetChronologicalYear(); int absVal2 = date.GetChronologicalYear(); float match = 0.0f; float matches = 0.0f; if (absVal1 != 0 && absVal2 != 0) { matches += 1.0f; if (Math.Abs(absVal1 - absVal2) <= matchParams.YearsInaccuracy) { match += 100.0f; } } return(match / matches); }
// DateValue format: INT/FROM/TO/etc..._<date> protected static string ParseDateValue(GDMDateValue dateValue, string str) { if (str == null) { return(string.Empty); } var strTok = new GEDCOMParser(str, false); strTok.SkipWhitespaces(); int idx = 0; var token = strTok.CurrentToken; if (token == GEDCOMToken.Word) { string su = strTok.GetWord(); idx = Algorithms.BinarySearch(GDMCustomDate.GEDCOMDateTypes, su, string.CompareOrdinal); } var dateType = (idx < 0) ? GEDCOMDateType.SIMP : (GEDCOMDateType)idx; string result; GDMCustomDate date; switch (dateType) { case GEDCOMDateType.AFT: case GEDCOMDateType.BEF: case GEDCOMDateType.BET: date = new GDMDateRange(); result = ParseRangeDate((GDMDateRange)date, strTok); break; case GEDCOMDateType.INT: date = new GDMDateInterpreted(); result = ParseIntDate((GDMDateInterpreted)date, strTok); break; case GEDCOMDateType.FROM: case GEDCOMDateType.TO: date = new GDMDatePeriod(); result = ParsePeriodDate((GDMDatePeriod)date, strTok); break; default: date = new GDMDate(); result = ParseDate((GDMDate)date, strTok); break; } dateValue.SetRawData(date); return(result); }