summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-09 17:22:03 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-09 17:22:03 +0700
commitb69b93cdb558b392e80362af340b151c04375ebc (patch)
tree4ad2ef9dc766631b40fc8cbf8df7effa5923c460
parentSimplify digest calculation (diff)
downloadBouncyCastle.NET-ed25519-b69b93cdb558b392e80362af340b151c04375ebc.tar.xz
Simplify WithPrecision methods
-rw-r--r--crypto/src/util/date/DateTimeUtilities.cs18
1 files changed, 8 insertions, 10 deletions
diff --git a/crypto/src/util/date/DateTimeUtilities.cs b/crypto/src/util/date/DateTimeUtilities.cs
index c46cde8db..1105cbdd7 100644
--- a/crypto/src/util/date/DateTimeUtilities.cs
+++ b/crypto/src/util/date/DateTimeUtilities.cs
@@ -56,28 +56,26 @@ namespace Org.BouncyCastle.Utilities.Date
 
         public static DateTime WithPrecisionCentisecond(DateTime dateTime)
         {
-            int millisecond = dateTime.Millisecond - (dateTime.Millisecond % 10);
-            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
-                dateTime.Hour, dateTime.Minute, dateTime.Second, millisecond, dateTime.Kind);
+            long ticks = dateTime.Ticks - dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 10L);
+            return new DateTime(ticks, dateTime.Kind);
         }
 
         public static DateTime WithPrecisionDecisecond(DateTime dateTime)
         {
-            int millisecond = dateTime.Millisecond - (dateTime.Millisecond % 100);
-            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
-                dateTime.Hour, dateTime.Minute, dateTime.Second, millisecond, dateTime.Kind);
+            long ticks = dateTime.Ticks - dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 100L);
+            return new DateTime(ticks, dateTime.Kind);
         }
 
         public static DateTime WithPrecisionMillisecond(DateTime dateTime)
         {
-            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
-                dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, dateTime.Kind);
+            long ticks = dateTime.Ticks - dateTime.Ticks % TimeSpan.TicksPerMillisecond;
+            return new DateTime(ticks, dateTime.Kind);
         }
 
         public static DateTime WithPrecisionSecond(DateTime dateTime)
         {
-            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
-                dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind);
+            long ticks = dateTime.Ticks - dateTime.Ticks % TimeSpan.TicksPerSecond;
+            return new DateTime(ticks, dateTime.Kind);
         }
     }
 }