public void DateTimeConstructor() { PartialDateTime.Parse("2012-03"); PartialDateTime.Parse("2012-03-04"); PartialDateTime.Parse("2012-03-04T12:34:34+02:00"); PartialDateTime.Parse("2012-03-04T12:34:34Z"); PartialDateTime pd; Assert.True(PartialDateTime.TryParse("2012-03", out pd)); Assert.Equal(pd, PartialDateTime.Parse("2012-03")); Assert.Equal("2012-03", pd.ToString()); Assert.False(PartialDateTime.TryParse("2012-03T12:34", out pd)); Assert.False(PartialDateTime.TryParse("20120304", out pd)); Assert.True(PartialDateTime.TryParse("2012-03-04T12:04:45", out pd)); //FHIR does not allow this, ISO8601 does. Assert.True(PartialDateTime.TryParse("2012-03-04T12:04:45Z", out pd)); Assert.False(PartialDateTime.TryParse("T12:04:45Z", out pd)); Assert.False(PartialDateTime.TryParse("12:04:45Z", out pd)); Assert.True(PartialDateTime.Parse("2012-03-04") > PartialDateTime.Parse("2012-03-01")); Assert.Equal(PartialDateTime.Today().ToString(), PartialDateTime.FromDateTime(DateTime.Today).ToString().Substring(0, 10)); Assert.Equal(PartialDateTime.Now().ToString().Substring(0, 19), PartialDateTime.FromDateTime(DateTimeOffset.Now).ToString().Substring(0, 19)); }
public void TestExpressionTodayFunction() { // Check that date comes in Assert.Equal(PartialDateTime.Today(), fixture.TestInput.Scalar("today()")); // Check greater than fixture.IsTrue("today() < @" + PartialDateTime.FromDateTime(DateTime.Today.AddDays(1))); // Check less than fixture.IsTrue("today() > @" + PartialDateTime.FromDateTime(DateTime.Today.AddDays(-1))); // Check == fixture.IsTrue("today() = @" + PartialDateTime.Today()); fixture.IsTrue("now() > @" + PartialDateTime.Today()); fixture.IsTrue("now() >= @" + PartialDateTime.Now()); }
public void TestExpressionTodayFunction() { // Check that date comes in Assert.Equal(PartialDateTime.Today(), fixture.TestInput.Scalar("today()")); // Check greater than fixture.IsTrue("today() < @" + PartialDateTime.FromDateTime(DateTimeOffset.UtcNow.AddDays(1))); // Check less than fixture.IsTrue("today() > @" + PartialDateTime.FromDateTime(DateTimeOffset.UtcNow.AddDays(-1))); // Check == fixture.IsTrue("today() = @" + PartialDateTime.Today()); // This unit-test will fail if you are working between midnight // and start-of-day in GMT: // e.g. 2018-08-10T01:00T+02:00 > 2018-08-10 will fail, which is then // test on the next line //fixture.IsTrue("now() > @" + PartialDateTime.Today()); fixture.IsTrue("now() >= @" + PartialDateTime.Now()); }
public static SymbolTable AddStandardFP(this SymbolTable t) { // Functions that operate on the focus, without null propagation t.Add("empty", (IEnumerable <object> f) => !f.Any()); t.Add("exists", (IEnumerable <object> f) => f.Any()); t.Add("count", (IEnumerable <object> f) => f.Count()); t.Add("trace", (IEnumerable <ITypedElement> f, string name, EvaluationContext ctx) => f.Trace(name, ctx)); t.Add("combine", (IEnumerable <ITypedElement> l, IEnumerable <ITypedElement> r) => l.Concat(r)); t.Add("binary.|", (object f, IEnumerable <ITypedElement> l, IEnumerable <ITypedElement> r) => l.DistinctUnion(r)); t.Add("binary.contains", (object f, IEnumerable <ITypedElement> a, ITypedElement b) => a.Contains(b)); t.Add("binary.in", (object f, ITypedElement a, IEnumerable <ITypedElement> b) => b.Contains(a)); t.Add("distinct", (IEnumerable <ITypedElement> f) => f.Distinct()); t.Add("isDistinct", (IEnumerable <ITypedElement> f) => f.IsDistinct()); t.Add("subsetOf", (IEnumerable <ITypedElement> f, IEnumerable <ITypedElement> a) => f.SubsetOf(a)); t.Add("supersetOf", (IEnumerable <ITypedElement> f, IEnumerable <ITypedElement> a) => a.SubsetOf(f)); t.Add("today", (object f) => PartialDateTime.Today()); t.Add("now", (object f) => PartialDateTime.Now()); t.Add("binary.&", (object f, string a, string b) => (a ?? "") + (b ?? "")); t.Add("iif", (IEnumerable <ITypedElement> f, bool?condition, IEnumerable <ITypedElement> result) => f.IIf(condition, result)); t.Add("iif", (IEnumerable <ITypedElement> f, bool?condition, IEnumerable <ITypedElement> result, IEnumerable <ITypedElement> otherwise) => f.IIf(condition, result, otherwise)); // Functions that use normal null propagation and work with the focus (buy may ignore it) t.Add("not", (IEnumerable <ITypedElement> f) => f.Not(), doNullProp: true); t.Add("builtin.children", (IEnumerable <ITypedElement> f, string a) => f.Navigate(a), doNullProp: true); t.Add("children", (IEnumerable <ITypedElement> f) => f.Children(), doNullProp: true); t.Add("descendants", (IEnumerable <ITypedElement> f) => f.Descendants(), doNullProp: true); t.Add("binary.=", (object f, IEnumerable <ITypedElement> a, IEnumerable <ITypedElement> b) => a.IsEqualTo(b), doNullProp: true); t.Add("binary.!=", (object f, IEnumerable <ITypedElement> a, IEnumerable <ITypedElement> b) => !a.IsEqualTo(b), doNullProp: true); t.Add("binary.~", (object f, IEnumerable <ITypedElement> a, IEnumerable <ITypedElement> b) => a.IsEquivalentTo(b), doNullProp: true); t.Add("binary.!~", (object f, IEnumerable <ITypedElement> a, IEnumerable <ITypedElement> b) => !a.IsEquivalentTo(b), doNullProp: true); t.Add("unary.-", (object f, long a) => - a, doNullProp: true); t.Add("unary.-", (object f, decimal a) => - a, doNullProp: true); t.Add("unary.+", (object f, long a) => a, doNullProp: true); t.Add("unary.+", (object f, decimal a) => a, doNullProp: true); t.Add("binary.*", (object f, long a, long b) => a * b, doNullProp: true); t.Add("binary.*", (object f, decimal a, decimal b) => a * b, doNullProp: true); t.Add("binary./", (object f, decimal a, decimal b) => a / b, doNullProp: true); //.Add((object f, decimal a, decimal b) => a / b, doNullProp: true); t.Add("binary.+", (object f, long a, long b) => a + b, doNullProp: true); t.Add("binary.+", (object f, decimal a, decimal b) => a + b, doNullProp: true); t.Add("binary.+", (object f, string a, string b) => a + b, doNullProp: true); t.Add("binary.-", (object f, long a, long b) => a - b, doNullProp: true); t.Add("binary.-", (object f, decimal a, decimal b) => a - b, doNullProp: true); t.Add("binary.div", (object f, long a, long b) => a / b, doNullProp: true); t.Add("binary.div", (object f, decimal a, decimal b) => (long)Math.Truncate(a / b), doNullProp: true); t.Add("binary.mod", (object f, long a, long b) => a % b, doNullProp: true); t.Add("binary.mod", (object f, decimal a, decimal b) => a % b, doNullProp: true); t.Add("binary.>", (object f, long a, long b) => a > b, doNullProp: true); t.Add("binary.>", (object f, decimal a, decimal b) => a > b, doNullProp: true); t.Add("binary.>", (object f, string a, string b) => String.CompareOrdinal(a, b) > 0, doNullProp: true); t.Add("binary.>", (object f, PartialDateTime a, PartialDateTime b) => a > b, doNullProp: true); t.Add("binary.>", (object f, PartialTime a, PartialTime b) => a > b, doNullProp: true); t.Add("binary.<", (object f, long a, long b) => a < b, doNullProp: true); t.Add("binary.<", (object f, decimal a, decimal b) => a < b, doNullProp: true); t.Add("binary.<", (object f, string a, string b) => String.CompareOrdinal(a, b) < 0, doNullProp: true); t.Add("binary.<", (object f, PartialDateTime a, PartialDateTime b) => a < b, doNullProp: true); t.Add("binary.<", (object f, PartialTime a, PartialTime b) => a < b, doNullProp: true); t.Add("binary.<=", (object f, long a, long b) => a <= b, doNullProp: true); t.Add("binary.<=", (object f, decimal a, decimal b) => a <= b, doNullProp: true); t.Add("binary.<=", (object f, string a, string b) => String.CompareOrdinal(a, b) <= 0, doNullProp: true); t.Add("binary.<=", (object f, PartialDateTime a, PartialDateTime b) => a <= b, doNullProp: true); t.Add("binary.<=", (object f, PartialTime a, PartialTime b) => a <= b, doNullProp: true); t.Add("binary.>=", (object f, long a, long b) => a >= b, doNullProp: true); t.Add("binary.>=", (object f, decimal a, decimal b) => a >= b, doNullProp: true); t.Add("binary.>=", (object f, string a, string b) => String.CompareOrdinal(a, b) >= 0, doNullProp: true); t.Add("binary.>=", (object f, PartialDateTime a, PartialDateTime b) => a >= b, doNullProp: true); t.Add("binary.>=", (object f, PartialTime a, PartialTime b) => a >= b, doNullProp: true); t.Add("single", (IEnumerable <ITypedElement> f) => f.Single(), doNullProp: true); t.Add("skip", (IEnumerable <ITypedElement> f, long a) => f.Skip((int)a), doNullProp: true); t.Add("first", (IEnumerable <ITypedElement> f) => f.First(), doNullProp: true); t.Add("last", (IEnumerable <ITypedElement> f) => f.Last(), doNullProp: true); t.Add("tail", (IEnumerable <ITypedElement> f) => f.Tail(), doNullProp: true); t.Add("take", (IEnumerable <ITypedElement> f, long a) => f.Take((int)a), doNullProp: true); t.Add("builtin.item", (IEnumerable <ITypedElement> f, long a) => f.Item((int)a), doNullProp: true); t.Add("toInteger", (ITypedElement f) => f.ToInteger(), doNullProp: true); t.Add("toDecimal", (ITypedElement f) => f.ToDecimal(), doNullProp: true); t.Add("toString", (ITypedElement f) => f.ToStringRepresentation(), doNullProp: true); t.Add("substring", (string f, long a) => f.FpSubstring((int)a), doNullProp: true); t.Add("substring", (string f, long a, long b) => f.FpSubstring((int)a, (int)b), doNullProp: true); t.Add("startsWith", (string f, string fragment) => f.StartsWith(fragment), doNullProp: true); t.Add("endsWith", (string f, string fragment) => f.EndsWith(fragment), doNullProp: true); t.Add("matches", (string f, string regex) => Regex.IsMatch(f, regex), doNullProp: true); t.Add("indexOf", (string f, string fragment) => f.FpIndexOf(fragment), doNullProp: true); t.Add("contains", (string f, string fragment) => f.Contains(fragment), doNullProp: true); t.Add("replaceMatches", (string f, string regex, string subst) => Regex.Replace(f, regex, subst), doNullProp: true); t.Add("replace", (string f, string regex, string subst) => f.FpReplace(regex, subst), doNullProp: true); t.Add("length", (string f) => f.Length, doNullProp: true); // The next two functions existed pre-normative, so we have kept them. t.Add("is", (ITypedElement f, string name) => f.Is(name), doNullProp: true); t.Add("as", (IEnumerable <ITypedElement> f, string name) => f.FilterType(name), doNullProp: true); t.Add("ofType", (IEnumerable <ITypedElement> f, string name) => f.FilterType(name), doNullProp: true); t.Add("binary.is", (object f, ITypedElement left, string name) => left.Is(name), doNullProp: true); t.Add("binary.as", (object f, ITypedElement left, string name) => left.CastAs(name), doNullProp: true); t.Add("binary.as", (object f, IEnumerable <ITypedElement> left, string name) => left.FilterType(name), doNullProp: true); t.Add("extension", (IEnumerable <ITypedElement> f, string url) => f.Extension(url), doNullProp: true); // Logic operators do not use null propagation and may do short-cut eval t.AddLogic("binary.and", (a, b) => a.And(b)); t.AddLogic("binary.or", (a, b) => a.Or(b)); t.AddLogic("binary.xor", (a, b) => a.XOr(b)); t.AddLogic("binary.implies", (a, b) => a.Implies(b)); // Special late-bound functions t.Add(new CallSignature("where", typeof(IEnumerable <ITypedElement>), typeof(object), typeof(Invokee)), runWhere); t.Add(new CallSignature("select", typeof(IEnumerable <ITypedElement>), typeof(object), typeof(Invokee)), runSelect); t.Add(new CallSignature("all", typeof(bool), typeof(object), typeof(Invokee)), runAll); t.Add(new CallSignature("any", typeof(bool), typeof(object), typeof(Invokee)), runAny); t.Add(new CallSignature("repeat", typeof(IEnumerable <ITypedElement>), typeof(object), typeof(Invokee)), runRepeat); t.Add(new CallSignature("trace", typeof(IEnumerable <ITypedElement>), typeof(string), typeof(object), typeof(Invokee)), Trace); t.AddVar("sct", "http://snomed.info/sct"); t.AddVar("loinc", "http://loinc.org"); t.AddVar("ucum", "http://unitsofmeasure.org"); t.Add("builtin.coreexturl", (object f, string id) => getCoreExtensionUrl(id)); t.Add("builtin.corevsurl", (object f, string id) => getCoreValueSetUrl(id)); return(t); }