コード例 #1
0
ファイル: DateTimeTests.cs プロジェクト: oldsaltycrab/npgsql
        public void ReadTime()
        {
            // TODO: Decide on the DateTime kind (#346)
            var expectedNpgsqlTime = new NpgsqlTime(10, 3, 45, 345000);
            var expectedDateTime   = new DateTime(expectedNpgsqlTime.Ticks, DateTimeKind.Unspecified);
            var cmd    = new NpgsqlCommand("SELECT '10:03:45.345'::TIME", Conn);
            var reader = cmd.ExecuteReader();

            reader.Read();

            // Regular type (DateTime)
            Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(DateTime)));
            Assert.That(reader.GetDateTime(0), Is.EqualTo(expectedDateTime));
            Assert.That(reader.GetFieldValue <DateTime>(0), Is.EqualTo(expectedDateTime));
            Assert.That(reader[0], Is.EqualTo(expectedDateTime));
            Assert.That(reader.GetValue(0), Is.EqualTo(expectedDateTime));

            // Provider-specific type (NpgsqlTime)
            Assert.That(reader.GetTime(0), Is.EqualTo(expectedNpgsqlTime));
            Assert.That(reader.GetProviderSpecificFieldType(0), Is.EqualTo(typeof(NpgsqlTime)));
            Assert.That(reader.GetProviderSpecificValue(0), Is.EqualTo(expectedNpgsqlTime));
            Assert.That(reader.GetFieldValue <NpgsqlTime>(0), Is.EqualTo(expectedNpgsqlTime));

            reader.Close();
            cmd.Dispose();
        }
コード例 #2
0
        public static NpgsqlTimeStamp GetNpgsqlDateTime(object dt)
        {
            NpgsqlDate dtDate = new NpgsqlDate(Convert.ToDateTime(dt));
            NpgsqlTime dtTime = new NpgsqlTime(((DateTime)dt).Ticks);

            return(new NpgsqlTimeStamp(dtDate, dtTime));
        }
コード例 #3
0
ファイル: DateTimeTests.cs プロジェクト: roji/Npgsql
        public void ReadTime()
        {
            // TODO: Decide on the DateTime kind (#346)
            var expectedNpgsqlTime = new NpgsqlTime(10, 3, 45, 345000);
            var expectedDateTime = new DateTime(expectedNpgsqlTime.Ticks, DateTimeKind.Unspecified);
            var cmd = new NpgsqlCommand("SELECT '10:03:45.345'::TIME", Conn);
            var reader = cmd.ExecuteReader();
            reader.Read();

            // Regular type (DateTime)
            Assert.That(reader.GetFieldType(0), Is.EqualTo(typeof(DateTime)));
            Assert.That(reader.GetDateTime(0), Is.EqualTo(expectedDateTime));
            Assert.That(reader.GetFieldValue<DateTime>(0), Is.EqualTo(expectedDateTime));
            Assert.That(reader[0], Is.EqualTo(expectedDateTime));
            Assert.That(reader.GetValue(0), Is.EqualTo(expectedDateTime));

            // Provider-specific type (NpgsqlTime)
            Assert.That(reader.GetTime(0), Is.EqualTo(expectedNpgsqlTime));
            Assert.That(reader.GetProviderSpecificFieldType(0), Is.EqualTo(typeof(NpgsqlTime)));
            Assert.That(reader.GetProviderSpecificValue(0), Is.EqualTo(expectedNpgsqlTime));
            Assert.That(reader.GetFieldValue<NpgsqlTime>(0), Is.EqualTo(expectedNpgsqlTime));

            reader.Close();
            cmd.Dispose();
        }
コード例 #4
0
ファイル: TypesTests.cs プロジェクト: Rungee/Npgsql2
        public void NpgsqlTimeConstructors()
        {
            NpgsqlTime test;

            test = new NpgsqlTime();
            Assert.AreEqual(0, test.Hours, "Hours");
            Assert.AreEqual(0, test.Minutes, "Minutes");
            Assert.AreEqual(0, test.Seconds, "Seconds");
            Assert.AreEqual(0, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(0, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(1234567890);
            Assert.AreEqual(0, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(456, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(456789, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(new NpgsqlInterval(0, 1, 2, 3, 4));
            Assert.AreEqual(1, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(4, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(4000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(new NpgsqlTime(1, 2, 3, 4));
            Assert.AreEqual(1, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(0, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(4, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(new TimeSpan(0, 1, 2, 3, 4));
            Assert.AreEqual(1, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(4, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(4000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(11, 45, 55.003m);
            Assert.AreEqual(11, test.Hours, "Hours");
            Assert.AreEqual(45, test.Minutes, "Minutes");
            Assert.AreEqual(55, test.Seconds, "Seconds");
            Assert.AreEqual(3, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(3000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(11, 45, 55.003);
            Assert.AreEqual(11, test.Hours, "Hours");
            Assert.AreEqual(45, test.Minutes, "Minutes");
            Assert.AreEqual(55, test.Seconds, "Seconds");
            Assert.AreEqual(3, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(3000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(4, 38, 53);
            Assert.AreEqual(4, test.Hours, "Hours");
            Assert.AreEqual(38, test.Minutes, "Minutes");
            Assert.AreEqual(53, test.Seconds, "Seconds");
            Assert.AreEqual(0, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(0, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(4, 38, 53, 123456);
            Assert.AreEqual(4, test.Hours, "Hours");
            Assert.AreEqual(38, test.Minutes, "Minutes");
            Assert.AreEqual(53, test.Seconds, "Seconds");
            Assert.AreEqual(123, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(123456, test.Microseconds, "Microseconds");
        }
コード例 #5
0
        public void NpgsqlTimeConstructors()
        {
            NpgsqlTime test;

            test = new NpgsqlTime();
            Assert.AreEqual(0, test.Hours, "Hours");
            Assert.AreEqual(0, test.Minutes, "Minutes");
            Assert.AreEqual(0, test.Seconds, "Seconds");
            Assert.AreEqual(0, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(0, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(1234567890);
            Assert.AreEqual(0, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(456, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(456789, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(new NpgsqlInterval(0, 1, 2, 3, 4));
            Assert.AreEqual(1, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(4, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(4000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(new NpgsqlTime(1, 2, 3, 4));
            Assert.AreEqual(1, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(0, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(4, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(new TimeSpan(0, 1, 2, 3, 4));
            Assert.AreEqual(1, test.Hours, "Hours");
            Assert.AreEqual(2, test.Minutes, "Minutes");
            Assert.AreEqual(3, test.Seconds, "Seconds");
            Assert.AreEqual(4, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(4000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(11, 45, 55.003m);
            Assert.AreEqual(11, test.Hours, "Hours");
            Assert.AreEqual(45, test.Minutes, "Minutes");
            Assert.AreEqual(55, test.Seconds, "Seconds");
            Assert.AreEqual(3, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(3000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(11, 45, 55.003);
            Assert.AreEqual(11, test.Hours, "Hours");
            Assert.AreEqual(45, test.Minutes, "Minutes");
            Assert.AreEqual(55, test.Seconds, "Seconds");
            Assert.AreEqual(3, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(3000, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(4, 38, 53);
            Assert.AreEqual(4, test.Hours, "Hours");
            Assert.AreEqual(38, test.Minutes, "Minutes");
            Assert.AreEqual(53, test.Seconds, "Seconds");
            Assert.AreEqual(0, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(0, test.Microseconds, "Microseconds");

            test = new NpgsqlTime(4, 38, 53, 123456);
            Assert.AreEqual(4, test.Hours, "Hours");
            Assert.AreEqual(38, test.Minutes, "Minutes");
            Assert.AreEqual(53, test.Seconds, "Seconds");
            Assert.AreEqual(123, test.Milliseconds, "Milliseconds");
            Assert.AreEqual(123456, test.Microseconds, "Microseconds");
        }
コード例 #6
0
        internal static object ToTime(NpgsqlBackendTypeInfo typeInfo, byte[] bBackendData, Int16 typeSize, Int32 typeModifier)
        {
            string backendData = BackendEncoding.UTF8Encoding.GetString(bBackendData);

            return(NpgsqlTime.Parse(backendData));
        }
コード例 #7
0
 internal static object ToTime(NpgsqlBackendTypeInfo typeInfo, String backendData, Int16 typeSize, Int32 typeModifier)
 {
     return(NpgsqlTime.Parse(backendData));
 }