Skip to content

Commit 9edfc29

Browse files
committed
Use new constructors that take microseconds.
1 parent 3645220 commit 9edfc29

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/MySqlConnector/Core/BinaryRow.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ private object ReadDateTime(ReadOnlySpan<byte> value)
191191
try
192192
{
193193
return Connection.AllowZeroDateTime ? (object) new MySqlDateTime(year, month, day, hour, minute, second, microseconds) :
194+
#if NET7_0_OR_GREATER
195+
new DateTime(year, month, day, hour, minute, second, microseconds / 1000, microseconds % 1000, Connection.DateTimeKind);
196+
#else
194197
new DateTime(year, month, day, hour, minute, second, microseconds / 1000, Connection.DateTimeKind).AddTicks(microseconds % 1000 * 10);
198+
#endif
195199
}
196200
catch (Exception ex)
197201
{
@@ -220,6 +224,10 @@ private static TimeSpan ReadTimeSpan(ReadOnlySpan<byte> value)
220224
microseconds = -microseconds;
221225
}
222226

227+
#if NET7_0_OR_GREATER
228+
return new TimeSpan(days, hours, minutes, seconds, microseconds / 1000, microseconds % 1000);
229+
#else
223230
return new TimeSpan(days, hours, minutes, seconds) + TimeSpan.FromTicks(microseconds * 10);
231+
#endif
224232
}
225233
}

src/MySqlConnector/Core/Row.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,11 @@ protected object ParseDateTime(ReadOnlySpan<byte> value)
545545
try
546546
{
547547
return Connection.AllowZeroDateTime ? (object) new MySqlDateTime(year, month, day, hour, minute, second, microseconds) :
548+
#if NET7_0_OR_GREATER
549+
new DateTime(year, month, day, hour, minute, second, microseconds / 1000, microseconds % 1000, Connection.DateTimeKind);
550+
#else
548551
new DateTime(year, month, day, hour, minute, second, microseconds / 1000, Connection.DateTimeKind).AddTicks(microseconds % 1000 * 10);
552+
#endif
549553
}
550554
catch (Exception ex)
551555
{

src/MySqlConnector/Utilities/Utility.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,11 @@ public static TimeSpan ParseTimeSpan(ReadOnlySpan<byte> value)
465465
seconds = -seconds;
466466
microseconds = -microseconds;
467467
}
468+
#if NET7_0_OR_GREATER
469+
return new TimeSpan(0, hours, minutes, seconds, microseconds / 1000, microseconds % 1000);
470+
#else
468471
return new TimeSpan(0, hours, minutes, seconds, microseconds / 1000) + TimeSpan.FromTicks(microseconds % 1000 * 10);
472+
#endif
469473

470474
InvalidTimeSpan:
471475
throw new FormatException("Couldn't interpret '{0}' as a valid TimeSpan".FormatInvariant(Encoding.UTF8.GetString(originalValue)));

0 commit comments

Comments
 (0)