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(); }
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)); }
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(); }
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"); }
internal static object ToTime(NpgsqlBackendTypeInfo typeInfo, byte[] bBackendData, Int16 typeSize, Int32 typeModifier) { string backendData = BackendEncoding.UTF8Encoding.GetString(bBackendData); return(NpgsqlTime.Parse(backendData)); }
internal static object ToTime(NpgsqlBackendTypeInfo typeInfo, String backendData, Int16 typeSize, Int32 typeModifier) { return(NpgsqlTime.Parse(backendData)); }