Beispiel #1
0
        public void InstantParsing()
        {
            Instant ins = Instant.Parse("2011-03-04T14:45:33Z");

            Assert.AreEqual("2011-03-04T14:45:33+00:00", ins.ToString());

            Instant ins2 = Instant.Parse("2011-03-04T14:45:33+02:00");

            Assert.AreEqual("2011-03-04T14:45:33+02:00", ins2.ToString());

            Instant ins4 = Instant.Parse("2012-04-14T10:35:23+00:00");

            Assert.AreEqual("2012-04-14T10:35:23+00:00", ins4.ToString());

            try
            {
                Instant dummy = Instant.Parse("2011-03-04T11:45:33");
                Assert.Fail();
            }
            catch (Exception) {}

            Instant ins5 = Instant.FromDateTimeUtc(2011, 3, 4, 16, 45, 33);

            Assert.AreEqual("2011-03-04T16:45:33+00:00", ins5.ToString());
        }
        /// <summary>
        /// Parse instant
        /// </summary>
        public static Hl7.Fhir.Model.Instant ParseInstant(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Instant existingInstance = null)
        {
            Hl7.Fhir.Model.Instant result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Instant();
            string currentElementName     = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element value
                else if (atName == "value")
                {
                    result.Value = Instant.Parse(reader.ReadPrimitiveContents(typeof(Instant))).Value;
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
Beispiel #3
0
 public virtual void ParseDateTimeStandardInstantFormat()
 {
     NUnit.Framework.Assert.AreEqual(Instant.Parse("2017-11-02T19:30:00Z").ToEpochMilli(), SUTime.ParseDateTime("2017-11-02T19:30:00Z", true).GetJodaTimeInstant().GetMillis());
 }