コード例 #1
0
        static DateMatch MatchDates(FamilyDateTimeClass date1, FamilyDateTimeClass date2)
        {
            if ((date1 != null) && (date2 != null))
            {
                if (date1.ValidDate() && date2.ValidDate())
                {
                    if ((date1.GetDateType() >= FamilyDateTimeClass.FamilyDateType.YearMonthDay) &&
                        (date2.GetDateType() >= FamilyDateTimeClass.FamilyDateType.YearMonthDay))
                    {
                        DateTime dt1 = date1.ToDateTime();
                        DateTime dt2 = date2.ToDateTime();

                        TimeSpan diff = dt1 - dt2;

                        if (Math.Abs(diff.Days) <= 10)
                        {
                            return(DateMatch.Good);
                        }
                        if (Math.Abs(diff.Days) <= 300)
                        {
                            return(DateMatch.Ok);
                        }
                        return(DateMatch.Bad);
                    }
                    if ((date1.GetDateType() >= FamilyDateTimeClass.FamilyDateType.YearMonth) &&
                        (date2.GetDateType() >= FamilyDateTimeClass.FamilyDateType.YearMonth))
                    {
                        DateTime dt1 = date1.ToDateTime();
                        DateTime dt2 = date2.ToDateTime();

                        if ((dt1.Year == dt2.Year) && (dt1.Month == dt2.Month))
                        {
                            return(DateMatch.Good);
                        }
                        if (Math.Abs(dt1.Year - dt2.Year) <= 1)
                        {
                            return(DateMatch.Ok);
                        }
                        return(DateMatch.Bad);
                    }
                    if ((date1.GetDateType() >= FamilyDateTimeClass.FamilyDateType.Year) &&
                        (date2.GetDateType() >= FamilyDateTimeClass.FamilyDateType.Year))
                    {
                        DateTime dt1 = date1.ToDateTime();
                        DateTime dt2 = date2.ToDateTime();

                        if (dt1.Year == dt2.Year)
                        {
                            return(DateMatch.Good);
                        }
                        if (Math.Abs(dt1.Year - dt2.Year) <= 2)
                        {
                            return(DateMatch.Ok);
                        }
                    }
                    return(DateMatch.Bad);
                }
            }
            return(DateMatch.Unknown);
        }
コード例 #2
0
        public IndividualClass DecodeIndividual(HttpPerson person)
        {
            if (person != null)
            {
                IndividualClass   individual = new IndividualClass();
                PersonalNameClass name       = new PersonalNameClass();

                if (person.id != null)
                {
                    individual.SetXrefName(person.id.Substring(8)); // skip "profile-"
                }
                if (person.first_name != null)
                {
                    name.SetName(PersonalNameClass.PartialNameType.GivenName, person.first_name);
                }
                if (person.last_name != null)
                {
                    name.SetName(PersonalNameClass.PartialNameType.Surname, person.last_name);
                }
                if (person.former_name != null)
                {
                    name.SetName(PersonalNameClass.PartialNameType.BirthSurname, person.former_name);
                }

                name.SanityCheck();

                individual.SetPersonalName(name);
                if (person.gender != null)
                {
                    switch (person.gender)
                    {
                    case "male":
                        individual.SetSex(IndividualClass.IndividualSexType.Male);
                        break;

                    case "female":
                        individual.SetSex(IndividualClass.IndividualSexType.Female);
                        break;
                    }
                }

                if (person.birth_date != null)
                {
                    FamilyDateTimeClass birthDate = new FamilyDateTimeClass(
                        person.birth_date.gedcom);
                    individual.AddEvent(new IndividualEventClass(IndividualEventClass.EventType.Birth, birthDate));
                }
                if (person.death_date != null)
                {
                    FamilyDateTimeClass deathDate = new FamilyDateTimeClass(
                        person.death_date.gedcom);
                    individual.AddEvent(new IndividualEventClass(IndividualEventClass.EventType.Death, deathDate));
                }

                return(individual);
            }

            return(null);
        }
コード例 #3
0
 public FamilyDateTimeClass DecodeDate(HttpDate inDate)
 {
     if (inDate != null)
     {
         FamilyDateTimeClass date = new FamilyDateTimeClass(inDate.gedcom);
     }
     return(null);
 }
コード例 #4
0
        private string CreateToolString()
        {
            string str = xref + "\n";

            if (family != null)
            {
                IndividualEventClass ev = family.GetEvent(IndividualEventClass.EventType.FamMarriage);

                if (ev != null)
                {
                    str += "Married ";

                    FamilyDateTimeClass date = ev.GetDate();

                    if ((date != null) && (date.GetDateType() != FamilyDateTimeClass.FamilyDateType.Unknown))
                    {
                        str += date.ToString();
                    }
                    AddressClass address = ev.GetAddress();
                    if (address != null)
                    {
                        str += " in " + address.ToString();
                    }
                    else
                    {
                        PlaceStructureClass place = ev.GetPlace();

                        if (place != null)
                        {
                            str += " in " + place.ToString();
                        }
                    }
                    str += "\n";
                }
                IList <IndividualXrefClass> childList = family.GetChildList();
                int children = 0;

                if (childList != null)
                {
                    children = childList.Count;
                }
                IList <IndividualXrefClass> parentList = family.GetParentList();
                int parents = 0;

                if (parentList != null)
                {
                    parents = parentList.Count;
                }
                str += parents + " parents and " + children + " children";
            }

            return(str);
        }
コード例 #5
0
        string GetEventDateString(IndividualClass person, IndividualEventClass.EventType evType)
        {
            if (person != null)
            {
                IndividualEventClass ev = person.GetEvent(IndividualEventClass.EventType.Birth);

                if (ev != null)
                {
                    FamilyDateTimeClass date = ev.GetDate();

                    if (date != null)
                    {
                        return(date.ToString());
                    }
                }
            }
            return("");
        }
コード例 #6
0
 public void SetDate(FamilyDateTimeClass inDate)
 {
     date = inDate;
 }
コード例 #7
0
        FamilyDateTimeClass ParseDateString(ref string dateStr)
        {
            string localDate    = dateStr;
            bool   approxDate   = false;
            int    dateStartPos = -1;
            int    parsePos     = 0;
            int    pos;

            if ((pos = localDate.IndexOf("omkring")) >= 0)
            {
                approxDate   = true;
                dateStartPos = pos;
                parsePos     = pos + 8; // strlen("omkring ")
            }

            if (parsePos == 0)
            {
                while (parsePos < dateStr.Length)
                {
                    if ((dateStr[parsePos] >= '0') && (dateStr[parsePos] <= '9'))
                    {
                        break;
                    }
                    parsePos++;
                }
            }
            if ((parsePos >= dateStr.Length) || (dateStr[parsePos] < '0') || (dateStr[parsePos] > '9'))
            {
                return(null);
            }
            FamilyDateTimeClass date = new FamilyDateTimeClass();

            if (dateStartPos < 0)
            {
                dateStartPos = parsePos;
            }

            DateParseState state = DateParseState.Year;
            string         partialString = "";
            int            year = -1, month = -1, day = -1;

            while (parsePos < localDate.Length)
            {
                char ch = localDate[parsePos++];

                if ((ch >= '0') && (ch <= '9'))
                {
                    partialString += ch;
                }
                if (ch == '-')
                {
                    switch (state)
                    {
                    case DateParseState.Year:
                        if (partialString.Length > 0)
                        {
                            year = Convert.ToInt32(partialString);
                            //dateType = FamilyDateTimeClass.FamilyDateType.Year;
                            state = DateParseState.Month;
                        }
                        partialString = "";
                        break;

                    case DateParseState.Month:
                        if (partialString.Length > 0)
                        {
                            month = Convert.ToInt32(partialString);
                            //dateType = FamilyDateTimeClass.FamilyDateType.YearMonth;
                            state = DateParseState.Day;
                        }
                        partialString = "";
                        break;

                    case DateParseState.Day:
                        trace.TraceInformation("weird...");
                        break;
                    }
                }
                else if ((ch == ' ') || (parsePos >= (localDate.Length)))
                {
                    if (partialString.Length > 0)
                    {
                        switch (state)
                        {
                        case DateParseState.Year:
                            year = Convert.ToInt32(partialString);
                            //dateType = FamilyDateTimeClass.FamilyDateType.Year;
                            break;

                        case DateParseState.Month:
                            month = Convert.ToInt32(partialString);
                            //dateType = FamilyDateTimeClass.FamilyDateType.YearMonth;
                            break;

                        case DateParseState.Day:
                            day = Convert.ToInt32(partialString);
                            //dateType = FamilyDateTimeClass.FamilyDateType.YearMonthDay;
                            break;
                        }
                        partialString = "";
                    }
                    date = new FamilyDateTimeClass(year, month, day);
                    date.SetApproximate(approxDate);
                    string outString = "";

                    if (dateStartPos > 0)
                    {
                        outString = dateStr.Substring(0, dateStartPos);
                    }
                    if (parsePos < localDate.Length)
                    {
                        outString += dateStr.Substring(parsePos);
                    }
                    if (outString.IndexOf(" i ") == 0)
                    {
                        outString = outString.Substring(3);
                    }
                    else if (outString.IndexOf("i ") == 0)
                    {
                        outString = outString.Substring(2);
                    }
                    dateStr = outString;
                    return(date);
                }
            }
            return(null);
        }