22using Npgsql . BackendMessages ;
33using Npgsql . Internal . TypeHandling ;
44using Npgsql . PostgresTypes ;
5- using Npgsql . TypeMapping ;
65using NpgsqlTypes ;
76
7+ #pragma warning disable 618 // NpgsqlTimeSpan is obsolete, remove in 7.0
8+
89namespace Npgsql . Internal . TypeHandlers . DateTimeHandlers
910{
1011 /// <summary>
@@ -17,7 +18,8 @@ namespace Npgsql.Internal.TypeHandlers.DateTimeHandlers
1718 /// should be considered somewhat unstable, and may change in breaking ways, including in non-major releases.
1819 /// Use it at your own risk.
1920 /// </remarks>
20- public partial class IntervalHandler : NpgsqlSimpleTypeHandlerWithPsv < TimeSpan , NpgsqlTimeSpan >
21+ public partial class IntervalHandler : NpgsqlSimpleTypeHandlerWithPsv < TimeSpan , NpgsqlTimeSpan > ,
22+ INpgsqlSimpleTypeHandler < NpgsqlInterval >
2123 {
2224 /// <summary>
2325 /// Constructs an <see cref="IntervalHandler"/>
@@ -37,12 +39,23 @@ protected override NpgsqlTimeSpan ReadPsv(NpgsqlReadBuffer buf, int len, FieldDe
3739 return new NpgsqlTimeSpan ( month , day , ticks * 10 ) ;
3840 }
3941
42+ NpgsqlInterval INpgsqlSimpleTypeHandler < NpgsqlInterval > . Read ( NpgsqlReadBuffer buf , int len , FieldDescription ? fieldDescription )
43+ {
44+ var ticks = buf . ReadInt64 ( ) ;
45+ var day = buf . ReadInt32 ( ) ;
46+ var month = buf . ReadInt32 ( ) ;
47+ return new NpgsqlInterval ( month , day , ticks ) ;
48+ }
49+
4050 /// <inheritdoc />
4151 public override int ValidateAndGetLength ( TimeSpan value , NpgsqlParameter ? parameter ) => 16 ;
4252
4353 /// <inheritdoc />
4454 public override int ValidateAndGetLength ( NpgsqlTimeSpan value , NpgsqlParameter ? parameter ) => 16 ;
4555
56+ /// <inheritdoc />
57+ public int ValidateAndGetLength ( NpgsqlInterval value , NpgsqlParameter ? parameter ) => 16 ;
58+
4659 /// <inheritdoc />
4760 public override void Write ( NpgsqlTimeSpan value , NpgsqlWriteBuffer buf , NpgsqlParameter ? parameter )
4861 {
@@ -55,5 +68,12 @@ public override void Write(NpgsqlTimeSpan value, NpgsqlWriteBuffer buf, NpgsqlPa
5568 /// <inheritdoc />
5669 public override void Write ( TimeSpan value , NpgsqlWriteBuffer buf , NpgsqlParameter ? parameter )
5770 => Write ( value , buf , parameter ) ;
71+
72+ public void Write ( NpgsqlInterval value , NpgsqlWriteBuffer buf , NpgsqlParameter ? parameter )
73+ {
74+ buf . WriteInt64 ( value . Time ) ;
75+ buf . WriteInt32 ( value . Days ) ;
76+ buf . WriteInt32 ( value . Months ) ;
77+ }
5878 }
5979}
0 commit comments