public void testParseStringUnknown() { string strValue = "@#DUNKNOWN@ 20 DEC 1980"; GEDCOMDate instance = new GEDCOMDate(null, null, "", ""); instance.SetDate(GEDCOMCalendar.dcIslamic, 0, 0, 0); string expResult = ""; string result = instance.ParseString(strValue); Assert.AreEqual(expResult, result); Assert.AreEqual("@#DUNKNOWN@ 20 DEC 1980", instance.StringValue); }
public void testSetDateHebrew() { GEDCOMCalendar calendar = GEDCOMCalendar.dcHebrew; int day = 20; int month = 12; int year = 1980; GEDCOMDate instance = new GEDCOMDate(null, null, "", ""); instance.SetDate(calendar, day, month, year); string result = instance.GetDisplayString(DateFormat.dfYYYY_MM_DD, false, false); Assert.AreEqual("1980.12.20", result); Assert.AreEqual("@#DHEBREW@ 20 AAV 1980", instance.StringValue); }
/// <summary> /// This function transforms the string into a date. All components of /// the date's string must be given by numbers in order of day / month / year. /// </summary> /// <param name="strDate"></param> /// <param name="calendar"></param> /// <param name="aException"></param> /// <returns></returns> public static GEDCOMDate CreateByFormattedStr(string dateStr, GEDCOMCalendar calendar, bool aException) { if (string.IsNullOrEmpty(dateStr)) { return(null); } if (dateStr.IndexOf("-") >= 0) { dateStr = dateStr.Replace("-", "."); } if (dateStr.IndexOf("/") >= 0) { dateStr = dateStr.Replace("/", "."); } if (dateStr.IndexOf("_") >= 0) { dateStr = dateStr.Replace("_", " "); } string[] dtParts = dateStr.Split('.'); if (dtParts.Length < 3) { if (aException) { throw new GEDCOMDateException(string.Format("GEDCOMDate.CreateByFormattedStr(): date format is invalid {0}", dateStr)); } return(null); } string pd = dtParts[0].Trim(); string pm = dtParts[1].Trim(); string py = dtParts[2].Trim(); int day = (pd == "") ? 0 : SysUtils.ParseInt(pd, 0); int month = (pm == "") ? 0 : SysUtils.ParseInt(pm, 0); int year = (py == "") ? UNKNOWN_YEAR : SysUtils.ParseInt(py, UNKNOWN_YEAR); var date = new GEDCOMDate(null, null, "", ""); date.SetDate(calendar, day, month, year); return(date); }