Ejemplo n.º 1
0
        public void ObjectOverrides()
        {
            // ToString
            var dt = new FudgeDateTime(2003, 11, 13, 12, 14, 34, 987654321, 0, FudgeDateTimePrecision.Nanosecond);
            Assert.Equal("2003-11-13T12:14:34.987654321+00:00", dt.ToString());

            // Equals
            var dt2 = new FudgeDateTime(2003, 11, 13, 12, 14, 34, 987654321, 0, FudgeDateTimePrecision.Nanosecond);
            var dt3 = new FudgeDateTime(2003, 11, 13, 12, 14, 34, 987654321, 0, FudgeDateTimePrecision.Nanosecond);
            Assert.Equal(dt2, dt3);
            Assert.False(dt2.Equals(null));
            Assert.False(dt2.Equals("Fred"));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override bool Equals(object obj)
        {
            FudgeDateTime other = obj as FudgeDateTime;

            if (other == null)
            {
                return(false);
            }

            return(this.date.Equals(other.date) &&
                   this.time.Equals(other.time) &&
                   this.precision == other.precision);
        }
Ejemplo n.º 3
0
 public void Properties()
 {
     var dt = new FudgeDateTime(1234, 5, 6, 7, 8, 9, 123456789, -60, FudgeDateTimePrecision.Nanosecond);
     Assert.Equal(12340506, dt.Date.RawValue);
     Assert.Equal("07:08:09.123456789-01:00", dt.Time.ToString());
     Assert.Equal(FudgeDateTimePrecision.Nanosecond, dt.Precision);
     Assert.Equal(1234, dt.Year);
     Assert.Equal(5, dt.Month);
     Assert.Equal(6, dt.Day);
     Assert.Equal(7, dt.Hour);
     Assert.Equal(8, dt.Minute);
     Assert.Equal(9, dt.Second);
     Assert.Equal(123456789, dt.Nanoseconds);
     Assert.Equal(-60, dt.TimeZoneOffset);
     Assert.True(dt.IsValidDate);
 }
        public void Minimsation()
        {
            var msg = new FudgeMsg(context);
            var dt = new DateTime(1990, 2, 1);
            var fdt = new FudgeDateTime(1990, 2, 1, 0, 0, 0, 0, FudgeDateTimePrecision.Day);

            msg.Add("dt", dt);
            msg.Add("fdt", fdt);
            Assert.Same(DateFieldType.Instance, msg.GetByName("dt").Type);
            Assert.IsType<FudgeDate>(msg.GetByName("dt").Value);
            Assert.Same(DateFieldType.Instance, msg.GetByName("fdt").Type);
            Assert.IsType<FudgeDate>(msg.GetByName("fdt").Value);

            Assert.Equal(dt, msg.GetValue<DateTime>("dt"));
            Assert.Equal(fdt, msg.GetValue<FudgeDateTime>("fdt"));

            // Error cases
            FudgeFieldType type = null;
            Assert.Equal(null, DateTimeFieldType.Instance.Minimize(null, ref type));
            Assert.Throws<ArgumentException>(() => DateTimeFieldType.Instance.Minimize("fred", ref type));
        }
Ejemplo n.º 5
0
        public void ConvertingToNativeTypes()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new FudgeDateTime(new FudgeDate(-12300101), null).ToDateTime());

            DateTime dt1 = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, FudgeDateTimePrecision.Nanosecond).ToDateTime();
            Assert.Equal("1900-02-28T12:07:34.0000000", dt1.ToString("o"));
            Assert.Equal(DateTimeKind.Unspecified, dt1.Kind);

            DateTime dt2 = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, 60, FudgeDateTimePrecision.Nanosecond).ToDateTime();
            Assert.Equal("1900-02-28T11:07:34.0000000Z", dt2.ToString("o"));      // Back an hour
            Assert.Equal(DateTimeKind.Utc, dt2.Kind);

            DateTime dt3 = new FudgeDateTime(2009, 7, 13, 12, 0, 0, 0, FudgeDateTimePrecision.Nanosecond).ToDateTime(DateTimeKind.Local, true);
            Assert.Equal(DateTimeKind.Local, dt3.Kind);
            Assert.Equal(new DateTime(2009, 7, 13, 12, 0, 0, DateTimeKind.Utc).ToLocalTime(), dt3);

            DateTime dt4 = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, 60, FudgeDateTimePrecision.Nanosecond).ToDateTime(DateTimeKind.Unspecified, false);
            Assert.Equal("1900-02-28T12:07:34.0000000", dt4.ToString("o"));         // Ignore the offset because we're going to unspecified
            Assert.Equal(DateTimeKind.Unspecified, dt4.Kind);

            DateTimeOffset dto = new FudgeDateTime(1900, 2, 28, 12, 7, 34, 0, 60, FudgeDateTimePrecision.Nanosecond).ToDateTimeOffset();
            Assert.Equal("1900-02-28T12:07:34.0000000+01:00", dto.ToString("o"));
        }
        public void RoundTrip()
        {
            var dt = new FudgeDateTime(1999, 12, 10, 3, 4, 5, 987654321, -75, FudgeDateTimePrecision.Nanosecond);

            var msg1 = new FudgeMsg(context, new Field("dt", dt));
            var bytes = msg1.ToByteArray();
            var msg2 = context.Deserialize(bytes).Message;

            Assert.Equal("1999-12-10T03:04:05.987654321-01:15", msg2.GetValue<FudgeDateTime>("dt").ToString());
        }
Ejemplo n.º 7
0
 public Instant(FudgeDateTime versionInstant)
     : this((long)(versionInstant.ToDateTime() - new DateTimeOffset(DateTimeNumericEncoding.Epoch)).TotalSeconds, versionInstant.Nanoseconds)
 {
 }