Exemplo n.º 1
0
 /// <summary>
 /// Reads a BSON DateTime from the reader.
 /// </summary>
 /// <returns>The number of milliseconds since the Unix epoch.</returns>
 public override long ReadDateTime()
 {
     if (disposed)
     {
         ThrowObjectDisposedException();
     }
     VerifyBsonType("ReadDateTime", BsonType.DateTime);
     state = GetNextState();
     return(buffer.ReadInt64());
 }
        /// <summary>
        /// Reads a BSON DateTime from the reader.
        /// </summary>
        /// <returns>The number of milliseconds since the Unix epoch.</returns>
        public override long ReadDateTime()
        {
            if (disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadDateTime", BsonType.DateTime);
            state = GetNextState();
            var value = buffer.ReadInt64();

            if (value == BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch + 1)
            {
                if (settings.FixOldDateTimeMaxValueOnInput)
                {
                    value = BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch;
                }
            }
            return(value);
        }
        /// <summary>
        /// Reads a BSON DateTime from the reader.
        /// </summary>
        /// <returns>A DateTime.</returns>
        public override DateTime ReadDateTime()
        {
            if (disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadDateTime", BsonType.DateTime);
            state = GetNextState();
            long milliseconds = buffer.ReadInt64();

            if (milliseconds == 253402300800000)
            {
                // special case to avoid ArgumentOutOfRangeException in AddMilliseconds
                return(DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc));
            }
            else
            {
                return(BsonConstants.UnixEpoch.AddMilliseconds(milliseconds)); // Kind = DateTimeKind.Utc
            }
        }