@@ -2008,7 +2008,7 @@ public static string SqlType(TableMapping.Column column) {
20082008 return "bigint" ;
20092009 }
20102010 else if ( clrType == typeof ( DateTimeOffset ) ) {
2011- return "bigint " ;
2011+ return "blob " ;
20122012 }
20132013 else if ( clrType . IsEnum ) {
20142014 return column . StoreAsText ? "varchar" : "integer" ;
@@ -2285,7 +2285,7 @@ internal static void BindParameter(Sqlite3Statement stmt, int index, object? val
22852285 SQLite3 . BindInt64 ( stmt , index , dateTimeValue . Ticks ) ;
22862286 }
22872287 else if ( value is DateTimeOffset dateTimeOffsetValue ) {
2288- SQLite3 . BindInt64 ( stmt , index , dateTimeOffsetValue . UtcTicks ) ;
2288+ SQLite3 . BindBlob ( stmt , index , DateTimeOffsetToBytes ( dateTimeOffsetValue ) ) ;
22892289 }
22902290 else if ( value is byte [ ] byteArrayValue ) {
22912291 SQLite3 . BindBlob ( stmt , index , byteArrayValue ) ;
@@ -2348,7 +2348,7 @@ private class Binding {
23482348 return new DateTime ( SQLite3 . ColumnInt64 ( stmt , index ) ) ;
23492349 }
23502350 else if ( clrType == typeof ( DateTimeOffset ) ) {
2351- return new DateTimeOffset ( SQLite3 . ColumnInt64 ( stmt , index ) , TimeSpan . Zero ) ;
2351+ return BytesToDateTimeOffset ( SQLite3 . ColumnBlob ( stmt , index ) ) ;
23522352 }
23532353 else if ( clrType . IsEnum ) {
23542354 if ( type is SQLite3 . ColType . Text ) {
@@ -2407,6 +2407,18 @@ private class Binding {
24072407 }
24082408 }
24092409 }
2410+
2411+ internal static DateTimeOffset BytesToDateTimeOffset ( byte [ ] bytes ) {
2412+ long dateTicks = BitConverter . ToInt64 ( bytes , 0 ) ;
2413+ long offsetTicks = BitConverter . ToInt64 ( bytes , sizeof ( long ) ) ;
2414+ return new DateTimeOffset ( new DateTime ( dateTicks ) , TimeSpan . FromTicks ( offsetTicks ) ) ;
2415+ }
2416+ internal static byte [ ] DateTimeOffsetToBytes ( DateTimeOffset dateTimeOffset ) {
2417+ return [
2418+ .. BitConverter . GetBytes ( dateTimeOffset . DateTime . Ticks ) ,
2419+ .. BitConverter . GetBytes ( dateTimeOffset . Offset . Ticks )
2420+ ] ;
2421+ }
24102422}
24112423
24122424internal class FastColumnSetter {
@@ -2468,7 +2480,7 @@ internal class FastColumnSetter {
24682480 }
24692481 else if ( clrType == typeof ( DateTimeOffset ) ) {
24702482 return CreateNullableTypedSetterDelegate < T , DateTimeOffset > ( column , ( stmt , index ) => {
2471- return new DateTimeOffset ( SQLite3 . ColumnInt64 ( stmt , index ) , TimeSpan . Zero ) ;
2483+ return SQLiteCommand . BytesToDateTimeOffset ( SQLite3 . ColumnBlob ( stmt , index ) ) ;
24722484 } ) ;
24732485 }
24742486 else if ( clrType . IsEnum ) {
0 commit comments