예제 #1
0
        private ISqlValue ToBinary(SqlDayToSecond dts, SqlBinaryType destType)
        {
            var bytes  = dts.ToByArray();
            var binary = new SqlBinary(bytes);

            return(destType.NormalizeValue(binary));
        }
예제 #2
0
        public static Field CurrentTimeStamp(IRequest request)
        {
            var systemDate    = SqlDateTime.Now;
            var sessionOffset = request.Query.Session.TimeZoneOffset();
            var offset        = new SqlDayToSecond(sessionOffset.Hours, sessionOffset.Minutes, 0);

            return(Field.TimeStamp(systemDate.Add(offset)));
        }
예제 #3
0
        public void CompareTwoDayToSecond()
        {
            var dts1 = new SqlDayToSecond(22, 11, 23, 0, 678);
            var dts2 = new SqlDayToSecond(0, 3, 22, 15, 877);

            var result = dts1.CompareTo(dts2);

            Assert.AreEqual(1, result);
        }
예제 #4
0
        public void AddNullDayToSecond()
        {
            var dts1 = new SqlDayToSecond(22, 11, 23, 0, 678);
            var dts2 = SqlDayToSecond.Null;

            var result = dts1.Add(dts2);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsNull);
        }
예제 #5
0
        private ISqlValue ToDayToSecond(SqlString value)
        {
            SqlDayToSecond dts;

            if (!SqlDayToSecond.TryParse(value.Value, out dts))
            {
                return(SqlNull.Value);
            }

            return(dts);
        }
        public static void CastToString(string value, SqlTypeCode destTypeCode, int size, string expexted)
        {
            var dts = SqlDayToSecond.Parse(value);

            var type     = new SqlDayToSecondType();
            var destType = PrimitiveTypes.Type(destTypeCode, new { size });
            var result   = type.Cast(dts, destType);

            var exp = SqlValueUtil.FromObject(expexted);

            Assert.NotNull(result);
            Assert.Equal(exp, result);
        }
예제 #7
0
        private static void BinaryWithInterval(Func <SqlDateTimeType, Func <ISqlValue, ISqlValue, ISqlValue> > selector, string date, string offset, string expected)
        {
            var type    = new SqlDateTimeType(SqlTypeCode.DateTime);
            var sqlDate = SqlDateTime.Parse(date);
            var dts     = SqlDayToSecond.Parse(offset);

            var op     = selector(type);
            var result = op(sqlDate, dts);

            var expectedResult = SqlDateTime.Parse(expected);

            Assert.Equal(expectedResult, result);
        }
예제 #8
0
        public void Add_TimeSpan_NoDays()
        {
            var value = new SqlDateTime(2001, 01, 03, 10, 22, 03, 0);
            var ts = new SqlDayToSecond(0, 2, 03, 0);

            var result = new SqlDateTime();
            Assert.DoesNotThrow(() => result = value.Add(ts));
            Assert.IsFalse(result.IsNull);
            Assert.AreEqual(2001, result.Year);
            Assert.AreEqual(01, result.Month);
            Assert.AreEqual(03, result.Day);
            Assert.AreEqual(12, result.Hour);
            Assert.AreEqual(25, result.Minute);
        }
예제 #9
0
        public void SerializeObject_DayToSecond_NotNull()
        {
            var type = PrimitiveTypes.DayToSecond();
            var obj = new SqlDayToSecond(22, 4, 15, 0);

            var stream = new MemoryStream();
            type.SerializeObject(stream, obj);

            stream.Seek(0, SeekOrigin.Begin);

            var serialized = type.DeserializeObject(stream);

            Assert.AreEqual(obj, serialized);
        }
예제 #10
0
        public void SerializeObject_DayToSecond_NotNull()
        {
            var type = PrimitiveTypes.DayToSecond();
            var obj  = new SqlDayToSecond(22, 4, 15, 0);

            var stream = new MemoryStream();

            type.SerializeObject(stream, obj);

            stream.Seek(0, SeekOrigin.Begin);

            var serialized = type.DeserializeObject(stream);

            Assert.AreEqual(obj, serialized);
        }
예제 #11
0
        public void AddDayToSecond()
        {
            var dts1 = new SqlDayToSecond(22, 11, 23, 0, 678);
            var dts2 = new SqlDayToSecond(0, 3, 22, 15, 877);

            var result = dts1.Add(dts2);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsNull);

            Assert.AreEqual(22, result.Days);
            Assert.AreEqual(14, result.Hours);
            Assert.AreEqual(45, result.Minutes);
            Assert.AreEqual(16, result.Seconds);
            Assert.AreEqual(555, result.Milliseconds);
        }
        public static void CastToBinary(string value, SqlTypeCode destTypeCode, int size)
        {
            var dts = SqlDayToSecond.Parse(value);

            var type     = new SqlDayToSecondType();
            var destType = PrimitiveTypes.Type(destTypeCode, new { size });
            var result   = type.Cast(dts, destType);

            Assert.IsType <SqlBinary>(result);

            var binary = (SqlBinary)result;
            var bytes  = binary.ToByteArray();

            var back = new SqlDayToSecond(bytes);

            Assert.Equal(dts, back);
        }
        private static void Binary(Func <SqlType, Func <ISqlValue, ISqlValue, ISqlValue> > selector,
                                   string value1,
                                   string value2,
                                   string expected)
        {
            var type = new SqlDayToSecondType();

            var a = SqlDayToSecond.Parse(value1);
            var b = SqlDayToSecond.Parse(value2);

            var op     = selector(type);
            var result = op(a, b);

            var exp = SqlDayToSecond.Parse(expected);

            Assert.Equal(exp, result);
        }
예제 #14
0
        public void AddDayToSecondToDate()
        {
            var date = new SqlDateTime(2010, 11, 03, 05, 22, 43, 0);
            var dts = new SqlDayToSecond(19, 08, 23, 1);

            var result = date.Add(dts);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsNull);
            Assert.AreEqual(2010, result.Year);
            Assert.AreEqual(11, result.Month);
            Assert.AreEqual(22, result.Day);
            Assert.AreEqual(13, result.Hour);
            Assert.AreEqual(45, result.Minute);
            Assert.AreEqual(44, result.Second);
            Assert.AreEqual(0, result.Millisecond);
        }
        public static void CastToDayToSecond(string s, string expected)
        {
            var expectedResult = SqlDayToSecond.Parse(expected);

            Cast(s, SqlTypeCode.DayToSecond, -1, -1, expectedResult);
        }
예제 #16
0
		public static DataObject Date(DateTimeOffset value) {
			var offset = new SqlDayToSecond(value.Offset.Days, value.Offset.Hours, value.Offset.Minutes, value.Offset.Seconds, value.Offset.Milliseconds);
			var sqlDate = new SqlDateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond, offset);
			return Date(sqlDate);
		}
예제 #17
0
 public void DayToSecondToString(int days, int hours, int minutes, int seconds, int millis, string expected)
 {
     var dayToSecond = new SqlDayToSecond(days, hours, minutes, seconds, millis);
     var s = dayToSecond.ToString();
     Assert.IsNotNullOrEmpty(s);
     Assert.AreEqual(expected, s);
 }
예제 #18
0
        public void SubtractDayToSeconds()
        {
            var dts1 = new SqlDayToSecond(22, 11, 23, 0, 678);
            var dts2 = new SqlDayToSecond(0, 3, 22, 15, 877);

            var result = dts1.Subtract(dts2);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsNull);

            Assert.AreEqual(22, result.Days);
            Assert.AreEqual(8, result.Hours);
            Assert.AreEqual(0, result.Minutes);
            Assert.AreEqual(44, result.Seconds);
            Assert.AreEqual(801, result.Milliseconds);
        }
예제 #19
0
        public void SubtractDayToSecondFromDate()
        {
            var date = new SqlDateTime(2010, 11, 03, 05, 22, 43, 0);
            var dts = new SqlDayToSecond(19, 08, 23, 1);

            var result = date.Subtract(dts);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsNull);

            Assert.AreEqual(2010, result.Year);
            Assert.AreEqual(10, result.Month);
            Assert.AreEqual(14, result.Day);
            Assert.AreEqual(20, result.Hour);
            Assert.AreEqual(59, result.Minute);
            Assert.AreEqual(42, result.Second);
            Assert.AreEqual(0, result.Millisecond);
        }
예제 #20
0
        private ISqlValue ToString(SqlDayToSecond dts, SqlCharacterType destType)
        {
            var s = new SqlString(dts.ToString());

            return(destType.NormalizeValue(s));
        }
예제 #21
0
        public void Operator_Subtract_TimeSpan()
        {
            var value = new SqlDateTime(2001, 01, 03, 10, 22, 03, 0);
            var ts = new SqlDayToSecond(0, 2, 03, 0);

            var result = new SqlDateTime();
            Assert.DoesNotThrow(() => result = value - ts);
            Assert.IsFalse(result.IsNull);
            Assert.AreEqual(2001, result.Year);
            Assert.AreEqual(01, result.Month);
            Assert.AreEqual(03, result.Day);
            Assert.AreEqual(8, result.Hour);
            Assert.AreEqual(19, result.Minute);
        }
예제 #22
0
 public static Field CurrentTimeStamp(IRequest request)
 {
     var systemDate = SqlDateTime.Now;
     var sessionOffset = request.Query.Session.TimeZoneOffset();
     var offset = new SqlDayToSecond(sessionOffset.Hours, sessionOffset.Minutes, 0);
     return Field.TimeStamp(systemDate.Add(offset));
 }