DateTime() public static method

public static DateTime ( ) : DateType
return DateType
Ejemplo n.º 1
0
        public void CastToDateTime(string s, int year, int month, int day, int hour, int minute, int second, int millis,
                                   int?offsetHour, int?offsetMinute)
        {
            var type  = PrimitiveTypes.String();
            var value = new SqlString(s);

            var casted = type.CastTo(value, PrimitiveTypes.DateTime());

            Assert.IsNotNull(casted);
            Assert.IsInstanceOf <SqlDateTime>(casted);

            var date = (SqlDateTime)casted;

            Assert.AreEqual(year, date.Year);
            Assert.AreEqual(month, date.Month);
            Assert.AreEqual(day, date.Day);
            Assert.AreEqual(hour, date.Hour);
            Assert.AreEqual(minute, date.Minute);
            Assert.AreEqual(second, date.Second);
            Assert.AreEqual(millis, date.Millisecond);

            var offset = (offsetHour != null && offsetMinute != null)
                                ? new SqlDayToSecond(0, offsetHour.Value, offsetMinute.Value, 0)
                                : SqlDayToSecond.Zero;

            Assert.AreEqual(offset, date.Offset);
        }
Ejemplo n.º 2
0
        public static SqlType Deserialize(BinaryReader reader, ITypeResolver resolver)
        {
            var typeCode = (SqlTypeCode)reader.ReadByte();

            if (BooleanType.IsBooleanType(typeCode))
            {
                return(PrimitiveTypes.Boolean(typeCode));
            }
            if (IntervalType.IsIntervalType(typeCode))
            {
                return(PrimitiveTypes.Interval(typeCode));
            }
            if (DateType.IsDateType(typeCode))
            {
                return(PrimitiveTypes.DateTime(typeCode));
            }

            if (StringType.IsStringType(typeCode))
            {
                var maxSize = reader.ReadInt32();

                CultureInfo locale    = null;
                var         hasLocale = reader.ReadByte() == 1;
                if (hasLocale)
                {
                    var name = reader.ReadString();
                    locale = new CultureInfo(name);
                }

                // TODO: Get the encoding from the serialization...
                return(PrimitiveTypes.String(typeCode, maxSize, Encoding.Unicode, locale));
            }

            if (NumericType.IsNumericType(typeCode))
            {
                var size  = reader.ReadInt32();
                var scale = reader.ReadInt32();

                return(PrimitiveTypes.Numeric(typeCode, size, scale));
            }

            if (BinaryType.IsBinaryType(typeCode))
            {
                var size = reader.ReadInt32();
                return(PrimitiveTypes.Binary(typeCode, size));
            }

            if (typeCode == SqlTypeCode.Type)
            {
                // TODO:
            }

            if (typeCode == SqlTypeCode.QueryPlan)
            {
                return(new QueryType());
            }

            if (typeCode == SqlTypeCode.Array)
            {
                var size = reader.ReadInt32();
                return(new ArrayType(size));
            }

            if (typeCode == SqlTypeCode.Null)
            {
                return(PrimitiveTypes.Null());
            }

            throw new NotSupportedException();
        }