/// <summary> /// Initializes a new instance of the <see cref="GedcomxDateRecurring"/> class. /// </summary> /// <param name="date">The recurring date string that describes a recurring GEDCOM X date.</param> /// <exception cref="Gedcomx.Date.GedcomxDateException"> /// Thrown if the formal date string is null, empty, or fails to meet the expected format. The specific reason will be given at runtime. /// </exception> public GedcomxDateRecurring(String date) { if (date == null || date.Length < 3) { throw new GedcomxDateException("Invalid Recurring Date"); } if (date[0] != 'R') { throw new GedcomxDateException("Invalid Recurring Date: Must start with R"); } String[] parts = date.Split('/'); if (parts.Length != 3) { throw new GedcomxDateException("Invalid Recurring Date: Must contain 3 parts"); } // We must have a start and end if (parts[1].Equals("") || parts[2].Equals("")) { throw new GedcomxDateException("Invalid Recurring Date: Range must have a start and an end"); } String countNum = parts[0].Substring(1); char[] countNumChars = parts[0].Substring(1).ToCharArray(); if (countNumChars.Length > 0) { foreach (char c in countNumChars) { if (!Char.IsDigit(c)) { throw new GedcomxDateException("Invalid Recurring Date: Malformed Count"); } } count = Int32.Parse(countNum); } try { range = new GedcomxDateRange(parts[1] + "/" + parts[2]); } catch (GedcomxDateException e) { throw new GedcomxDateException(e.Message + " in Recurring Range"); } // If we have a count set end if (count != null) { end = GetNth(count.Value); } }