示例#1
0
        public void BasicConstruction()
        {
            var t = new FudgeTime(13, 4, 5, 123456789, -120, FudgeDateTimePrecision.Nanosecond);
            Assert.Equal(13, t.Hour);
            Assert.Equal(4, t.Minute);
            Assert.Equal(5, t.Second);
            Assert.Equal(123456789, t.Nanoseconds);
            Assert.Equal(-120, t.TimeZoneOffset);
            Assert.Equal(FudgeDateTimePrecision.Nanosecond, t.Precision);
            Assert.Equal("13:04:05.123456789-02:00", t.ToString());

            var t2 = new FudgeTime(1, 2, 3);
            Assert.Null(t2.TimeZoneOffset);
            Assert.Equal(FudgeDateTimePrecision.Second, t2.Precision);
            Assert.Equal("01:02:03", t2.ToString());

            var t3 = new FudgeTime(1, 2, 3, 60);
            Assert.Equal(60, t3.TimeZoneOffset);
            Assert.Equal(FudgeDateTimePrecision.Second, t3.Precision);
            Assert.Equal("01:02:03+01:00", t3.ToString());

            // Other variants
            Assert.Equal("04:01", new FudgeTime(4, 1).ToString());
            Assert.Equal("23", new FudgeTime(23).ToString());
            Assert.Equal("10:00:05.987654321", new FudgeTime(10, 0, 5, 987654321, FudgeDateTimePrecision.Nanosecond).ToString());
            Assert.Equal("01:01:01.000000123", new FudgeTime(FudgeDateTimePrecision.Nanosecond, 3661, 123).ToString());
            Assert.Equal("01:01:01.000000123+00:30", new FudgeTime(FudgeDateTimePrecision.Nanosecond, 3661, 123, 30).ToString());
        }
        private void Cycle(FudgeTime t)
        {
            var msg1 = new FudgeMsg(context, new Field("t", t));
            var bytes = msg1.ToByteArray();
            var msg2 = context.Deserialize(bytes).Message;

            Assert.Equal(t, msg2.GetValue<FudgeTime>("t"));
        }
示例#3
0
        public void ConstructingFromDateTime()
        {
            Assert.Equal("12:14:10.000000000", new FudgeTime(new DateTime(2000, 2, 3, 12, 14, 10, DateTimeKind.Unspecified)).ToString());
            Assert.Equal("12:14:10.000000000+00:00", new FudgeTime(new DateTime(2000, 2, 3, 12, 14, 10, DateTimeKind.Utc)).ToString());

            var local = new FudgeTime(new DateTime(2000, 7, 6, 12, 14, 10, DateTimeKind.Local));
            Assert.True(local.ToString().StartsWith("12:14:10"));
            Assert.True(local.TimeZoneOffset.HasValue);
        }
        public void CheckActualBytes()
        {
            var t = new FudgeTime(1, 2, 3, 123456789, 60, FudgeDateTimePrecision.Microsecond);
            var stream = new MemoryStream();
            var writer = new FudgeBinaryWriter(stream);
            TimeFieldType.Instance.WriteValue(writer, t);

            Assert.Equal("04-90-0e-8b-07-5b-cd-15", stream.ToArray().ToNiceString());   // 04 = timezone, 9 = accuracy, 00e8b = seconds, 075bcd15 = nanos
        }
示例#5
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> based on a .net <see cref="DateTime"/>, specifying the precision.
 /// </summary>
 /// <param name="dateTime"></param>
 /// <param name="precision"></param>
 public FudgeDateTime(DateTime dateTime, FudgeDateTimePrecision precision)
 {
     this.date = new FudgeDate(dateTime);
     if (precision > FudgeDateTimePrecision.Day)
     {
         this.time = new FudgeTime(dateTime, precision);
     }
     else
     {
         this.time = FudgeTime.Midnight;
     }
     this.precision = precision;
 }
示例#6
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> based on a .net <see cref="DateTime"/>, specifying the precision.
 /// </summary>
 /// <param name="dateTime"></param>
 /// <param name="precision"></param>
 public FudgeDateTime(DateTime dateTime, FudgeDateTimePrecision precision)
 {
     this.date = new FudgeDate(dateTime);
     if (precision > FudgeDateTimePrecision.Day)
     {
         this.time = new FudgeTime(dateTime, precision);
     }
     else
     {
         this.time = FudgeTime.Midnight;
     }
     this.precision = precision;
 }
示例#7
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> using a <see cref="FudgeDate"/> and <see cref="FudgeTime"/>, specifying the precision.
 /// </summary>
 /// <param name="date">Date part of the datetime.</param>
 /// <param name="time">Time part of the datetime, may be <c>null</c>.</param>
 /// <param name="precision">Precision to use.</param>
 public FudgeDateTime(FudgeDate date, FudgeTime time, FudgeDateTimePrecision precision)
 {
     this.date = date;
     if (time == null)
     {
         this.time = FudgeTime.Midnight;
     }
     else
     {
         this.time = time;
     }
     this.precision = precision;
 }
示例#8
0
 /// <summary>
 /// Constructs a <c>FudgeDateTime</c> from component values with timezone information.
 /// </summary>
 /// <param name="year"></param>
 /// <param name="month"></param>
 /// <param name="day"></param>
 /// <param name="hour"></param>
 /// <param name="minute"></param>
 /// <param name="second"></param>
 /// <param name="nanosecond"></param>
 /// <param name="timeZoneOffset">Timezone offset from UTC, in minutes, must be multiple of 15</param>
 /// <param name="precision"></param>
 public FudgeDateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond, int timeZoneOffset, FudgeDateTimePrecision precision)
 {
     this.date = new FudgeDate(year, month, day);
     if (precision > FudgeDateTimePrecision.Day)
     {
         this.time = new FudgeTime(hour, minute, second, nanosecond, timeZoneOffset, precision);
     }
     else
     {
         this.time = FudgeTime.Midnight;
     }
     this.precision = precision;
 }
示例#9
0
        /// <inheritdoc/>
        public override FudgeDateTime ReadTypedValue(BinaryReader input, int dataSize)
        {
            FudgeDate date = DateFieldType.Instance.ReadTypedValue(input, 0);

            int?timeZone;
            int seconds;
            int nanos;
            FudgeDateTimePrecision precision;

            TimeFieldType.ReadEncodedTime(input, out precision, out timeZone, out seconds, out nanos);

            // Time can't have a precision of worse than hours
            var timePrecision = (precision > FudgeDateTimePrecision.Day) ? precision : FudgeDateTimePrecision.Hour;
            var time          = new FudgeTime(timePrecision, seconds, nanos, timeZone);

            return(new FudgeDateTime(date, time, precision));
        }
示例#10
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> based on a .net <see cref="DateTimeOffset"/>, specifying the precision.
 /// </summary>
 /// <param name="dateTimeOffset"><see cref="DateTimeOffset"/> to use.</param>
 /// <param name="precision"></param>
 /// <remarks>The offset must be on a 15-minute boundary and within the +/- 30 hour range allowed by <c>FudgeDateTime</c>.</remarks>
 public FudgeDateTime(DateTimeOffset dateTimeOffset, FudgeDateTimePrecision precision)
 {
     this.date = new FudgeDate(dateTimeOffset.Date);
     if (precision > FudgeDateTimePrecision.Day)
     {
         int seconds = (int)(dateTimeOffset.TimeOfDay.Ticks / FudgeTime.TicksPerSecond);
         int nanos   = (int)(dateTimeOffset.TimeOfDay.Ticks % FudgeTime.TicksPerSecond);
         int offset  = (int)(dateTimeOffset.Offset.Ticks / FudgeTime.TicksPerSecond / 60);
         this.time = new FudgeTime(precision, seconds, nanos, offset);
     }
     else
     {
         // Time and offset are irrelevant
         this.time = FudgeTime.Midnight;
     }
     this.precision = precision;
 }
示例#11
0
 public void Totals()
 {
     var t = new FudgeTime(1, 2, 3, 123456789, FudgeDateTimePrecision.Nanosecond);
     Assert.Equal(3723, t.TotalSeconds);
     Assert.Equal(3723123456789L, t.TotalNanoseconds);
 }
示例#12
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> based on a .net <see cref="DateTimeOffset"/>, specifying the precision.
 /// </summary>
 /// <param name="dateTimeOffset"><see cref="DateTimeOffset"/> to use.</param>
 /// <param name="precision"></param>
 /// <remarks>The offset must be on a 15-minute boundary and within the +/- 30 hour range allowed by <c>FudgeDateTime</c>.</remarks>
 public FudgeDateTime(DateTimeOffset dateTimeOffset, FudgeDateTimePrecision precision)
 {
     this.date = new FudgeDate(dateTimeOffset.Date);
     if (precision > FudgeDateTimePrecision.Day)
     {
         int seconds = (int)(dateTimeOffset.TimeOfDay.Ticks / FudgeTime.TicksPerSecond);
         int nanos = (int)(dateTimeOffset.TimeOfDay.Ticks % FudgeTime.TicksPerSecond);
         int offset = (int)(dateTimeOffset.Offset.Ticks / FudgeTime.TicksPerSecond / 60);
         this.time = new FudgeTime(precision, seconds, nanos, offset);
     }
     else
     {
         // Time and offset are irrelevant
         this.time = FudgeTime.Midnight;
     }
     this.precision = precision;
 }
示例#13
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> using a <see cref="FudgeDate"/> and <see cref="FudgeTime"/>, specifying the precision.
 /// </summary>
 /// <param name="date">Date part of the datetime.</param>
 /// <param name="time">Time part of the datetime, may be <c>null</c>.</param>
 /// <param name="precision">Precision to use.</param>
 public FudgeDateTime(FudgeDate date, FudgeTime time, FudgeDateTimePrecision precision)
 {
     this.date = date;
     if (time == null)
     {
         this.time = FudgeTime.Midnight;
     }
     else
     {
         this.time = time;
     }
     this.precision = precision;
 }
示例#14
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> using a <see cref="FudgeDate"/> and <see cref="FudgeTime"/>, taking the
 /// precision from the <see cref="FudgeTime"/>.
 /// </summary>
 /// <param name="date">Date part of the datetime.</param>
 /// <param name="time">Time part of the datetime, may be <c>null</c>.</param>
 public FudgeDateTime(FudgeDate date, FudgeTime time)
     : this(date, time, time == null ? FudgeDateTimePrecision.Day : time.Precision)
 {
 }
示例#15
0
 /// <summary>
 /// Constructs a <c>FudgeDateTime</c> from component values with timezone information.
 /// </summary>
 /// <param name="year"></param>
 /// <param name="month"></param>
 /// <param name="day"></param>
 /// <param name="hour"></param>
 /// <param name="minute"></param>
 /// <param name="second"></param>
 /// <param name="nanosecond"></param>
 /// <param name="timeZoneOffset">Timezone offset from UTC, in minutes, must be multiple of 15</param>
 /// <param name="precision"></param>
 public FudgeDateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond, int timeZoneOffset, FudgeDateTimePrecision precision)
 {
     this.date = new FudgeDate(year, month, day);
     if (precision > FudgeDateTimePrecision.Day)
     {
         this.time = new FudgeTime(hour, minute, second, nanosecond, timeZoneOffset, precision);
     }
     else
     {
         this.time = FudgeTime.Midnight;
     }
     this.precision = precision;
 }
示例#16
0
 /// <summary>
 /// Constructs a new <c>FudgeDateTime</c> using a <see cref="FudgeDate"/> and <see cref="FudgeTime"/>, taking the
 /// precision from the <see cref="FudgeTime"/>.
 /// </summary>
 /// <param name="date">Date part of the datetime.</param>
 /// <param name="time">Time part of the datetime, may be <c>null</c>.</param>
 public FudgeDateTime(FudgeDate date, FudgeTime time) : this(date, time, time == null ? FudgeDateTimePrecision.Day : time.Precision)
 {
 }