WikiFunctions.Parse.Parsers.SetPersonDataDate C# (CSharp) Method

SetPersonDataDate() private static method

Completes a persondata call with a date of birth/death.
private static SetPersonDataDate ( string personData, string field, string sourceValue, string articletext ) : string
personData string
field string
sourceValue string
articletext string
return string
        private static string SetPersonDataDate(string personData, string field, string sourceValue, string articletext)
        {
            string dateFound = "";

            if (field.Equals("DATE OF BIRTH") && BirthDate.IsMatch(articletext))
            {
                sourceValue = Tools.RemoveTemplateParameters(BirthDate.Match(articletext).Value, DfMf);
                dateFound = Tools.GetTemplateArgument(sourceValue, 1);

                // first argument is a year, or a full date
                if (dateFound.Length < 5)
                    dateFound += ("-" + Tools.GetTemplateArgument(sourceValue, 2) + "-" + Tools.GetTemplateArgument(sourceValue, 3));
            }
            else if (field.Equals("DATE OF DEATH") && DeathDate.Matches(articletext).Count == 1)
            {
                sourceValue = Tools.RemoveTemplateParameters(DeathDate.Match(articletext).Value, DfMf);
                dateFound = Tools.GetTemplateArgument(sourceValue, 1);
                if (dateFound.Length < 5)
                    dateFound += ("-" + Tools.GetTemplateArgument(sourceValue, 2) + "-" + Tools.GetTemplateArgument(sourceValue, 3));
            }
            else if (WikiRegexes.AmericanDates.IsMatch(sourceValue))
                dateFound = WikiRegexes.AmericanDates.Match(sourceValue).Value;
            else if (WikiRegexes.InternationalDates.IsMatch(sourceValue))
                dateFound = WikiRegexes.InternationalDates.Match(sourceValue).Value;
            else if (WikiRegexes.ISODates.IsMatch(sourceValue))
                dateFound = WikiRegexes.ISODates.Match(sourceValue).Value;

            // if date not found yet, fall back to year/month/day of brith fields or birth date in {{dda}}
            if (dateFound.Length == 0)
            {
                if (field.Equals("DATE OF BIRTH"))
                {
                    if (GetInfoBoxFieldValue(articletext, "yearofbirth").Length > 0)
                        dateFound = (GetInfoBoxFieldValue(articletext, "yearofbirth") + "-" + GetInfoBoxFieldValue(articletext, "monthofbirth") + "-" + GetInfoBoxFieldValue(articletext, "dayofbirth")).Trim('-');
                    else if (GetInfoBoxFieldValue(articletext, "yob").Length > 0)
                        dateFound = (GetInfoBoxFieldValue(articletext, "yob") + "-" + GetInfoBoxFieldValue(articletext, "mob") + "-" + GetInfoBoxFieldValue(articletext, "dob")).Trim('-');
                    else if (WikiRegexes.DeathDateAndAge.IsMatch(articletext))
                    {
                        string dda = Tools.RemoveTemplateParameters(WikiRegexes.DeathDateAndAge.Match(articletext).Value, DfMf);
                        dateFound = (Tools.GetTemplateArgument(dda, 4) + "-" + Tools.GetTemplateArgument(dda, 5) + "-" + Tools.GetTemplateArgument(dda, 6)).Trim('-');
                    }
                    else if (GetInfoBoxFieldValue(articletext, "birthyear").Length > 0)
                        dateFound = (GetInfoBoxFieldValue(articletext, "birthyear") + "-" + GetInfoBoxFieldValue(articletext, "birthmonth") + "-" + GetInfoBoxFieldValue(articletext, "birthday")).Trim('-');
                }
                else if (field.Equals("DATE OF DEATH"))
                {
                    if (GetInfoBoxFieldValue(articletext, "yearofdeath").Length > 0)
                        dateFound = (GetInfoBoxFieldValue(articletext, "yearofdeath") + "-" + GetInfoBoxFieldValue(articletext, "monthofdeath") + "-" + GetInfoBoxFieldValue(articletext, "dayofdeath")).Trim('-');
                    else if (GetInfoBoxFieldValue(articletext, "deathyear").Length > 0)
                        dateFound = (GetInfoBoxFieldValue(articletext, "deathyear") + "-" + GetInfoBoxFieldValue(articletext, "deathmonth") + "-" + GetInfoBoxFieldValue(articletext, "deathday")).Trim('-');
                    else if (GetInfoBoxFieldValue(articletext, "yod").Length > 0)
                        dateFound = (GetInfoBoxFieldValue(articletext, "yod") + "-" + GetInfoBoxFieldValue(articletext, "mod") + "-" + GetInfoBoxFieldValue(articletext, "dod")).Trim('-');
                }
            }

            // call parser function for futher date fixes
            if (dateFound.Length > 0)
            {
                dateFound = WikiRegexes.Comments.Replace(CiteTemplateDates(@"{{cite web|date=" + dateFound + @"}}").Replace(@"{{cite web|date=", "").Trim('}'), "");

                dateFound = Tools.ConvertDate(dateFound, DeterminePredominantDateLocale(articletext, false)).Trim('-');

                // check ISO dates valid (in case dda used zeros for month/day)
                if (dateFound.Contains("-") && !WikiRegexes.ISODates.IsMatch(dateFound))
                    return personData;

                return Tools.SetTemplateParameterValue(personData, field, dateFound, true);
            }

            return personData;
        }
Parsers