Exemplo n.º 1
0
        public DateTime BytesToDateTime(byte[] value)
        {
            // Attempt to convert the first 6 bytes.
            var dayBytes  = new byte[2];                                // Empty ushort
            var tickBytes = new byte[4];                                // Empty int

            Array.Copy(value, 0, dayBytes, 0, 2);
            Array.Copy(value, 2, tickBytes, 0, 4);

            if (BitConverter.IsLittleEndian)
            {
                // COMBs store the MOST significant bytes first, we need the opposite to convert back to x86-form int/ushort
                Array.Reverse(dayBytes);
                Array.Reverse(tickBytes);
            }

            var days  = BitConverter.ToUInt16(dayBytes, 0);
            var ticks = BitConverter.ToInt32(tickBytes, 0);

            if (ticks < 0f)
            {
                throw new ArgumentException("Not a COMB, time component is negative.");
            }
            else if (ticks > TicksPerDay)
            {
                throw new ArgumentException("Not a COMB, time component exceeds 24 hours.");
            }

            return(MinDateTimeValue.AddDays(days).AddMilliseconds((double)ticks / TicksPerMillisecond));
        }
Exemplo n.º 2
0
 public DateTime FromUnixTimeMilliseconds(long ms) => MinDateTimeValue.AddTicks(ms * TicksPerMillisecond);