/// <summary> /// FhirPath toDate() function. /// </summary> /// <param name="focus"></param> /// <returns></returns> public static PartialDate?ToDate(this ITypedElement focus) { var val = focus?.Value; if (val == null) { return(null); } switch (val) { case PartialDate pt: return(pt); case string s: return(convertString(s)); default: return(null); } PartialDate?convertString(string si) { return(PartialDate.TryParse(si, out var result) ? result : (PartialDate?)null); } }
void accept(string testInput, int?y, int?m, int?d, PartialPrecision?p, TimeSpan?o) { Assert.IsTrue(PartialDate.TryParse(testInput, out PartialDate parsed), "TryParse"); Assert.AreEqual(y, parsed.Years, "years"); Assert.AreEqual(m, parsed.Months, "months"); Assert.AreEqual(d, parsed.Days, "days"); Assert.AreEqual(o, parsed.Offset, "offset"); Assert.AreEqual(p, parsed.Precision, "precision"); Assert.AreEqual(testInput, parsed.ToString(), "ToString"); }
private static PartialDate?ValidateDate(string month, string year) { PartialDate?date; if (string.IsNullOrEmpty(month)) { return(PartialDate.TryParse("Jan " + year, out date) ? date : null); } return(PartialDate.TryParse(month + " " + year, out date) ? date : null); }
protected override PartialDate?GetDateOfBirth(XmlDocument xmlDoc) { var dob = Get(xmlDoc, "//contact/personal/dob"); if (string.IsNullOrEmpty(dob)) { dob = Get(xmlDoc, "//resume/statements/personal/dob"); if (string.IsNullOrEmpty(dob)) { return(null); } } PartialDate?date; PartialDate.TryParse(dob, out date); return(date); }
void reject(string testValue) { Assert.IsFalse(PartialDate.TryParse(testValue, out _)); }