예제 #1
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;
 }
예제 #2
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;
 }
예제 #3
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;
 }
예제 #4
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));
        }
예제 #5
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;
 }
예제 #6
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)
 {
 }