summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-05-24 23:21:12 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-05-24 23:21:12 +0700
commitaa4f6e11a9b7103a2baf6617664f387575a2a774 (patch)
tree476d4b5ad3b68878909a6fb4df6d758d7067e6ad /crypto/src/util
parentRefactoring in Asn1.Ocsp (diff)
downloadBouncyCastle.NET-ed25519-aa4f6e11a9b7103a2baf6617664f387575a2a774.tar.xz
Refactor DateTimeUtilities
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/date/DateTimeUtilities.cs33
1 files changed, 9 insertions, 24 deletions
diff --git a/crypto/src/util/date/DateTimeUtilities.cs b/crypto/src/util/date/DateTimeUtilities.cs
index 1105cbdd7..73ac07886 100644
--- a/crypto/src/util/date/DateTimeUtilities.cs
+++ b/crypto/src/util/date/DateTimeUtilities.cs
@@ -49,33 +49,18 @@ namespace Org.BouncyCastle.Utilities.Date
 		/// <summary>
 		/// Return the current number of milliseconds since the Unix epoch (1 Jan., 1970 UTC).
 		/// </summary>
-		public static long CurrentUnixMs()
-		{
-			return DateTimeToUnixMs(DateTime.UtcNow);
-		}
+		public static long CurrentUnixMs() => DateTimeToUnixMs(DateTime.UtcNow);
 
-        public static DateTime WithPrecisionCentisecond(DateTime dateTime)
-        {
-            long ticks = dateTime.Ticks - dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 10L);
-            return new DateTime(ticks, dateTime.Kind);
-        }
+        public static DateTime WithPrecisionCentisecond(DateTime dateTime) =>
+            dateTime.AddTicks(-(dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 10L)));
 
-        public static DateTime WithPrecisionDecisecond(DateTime dateTime)
-        {
-            long ticks = dateTime.Ticks - dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 100L);
-            return new DateTime(ticks, dateTime.Kind);
-        }
+        public static DateTime WithPrecisionDecisecond(DateTime dateTime) =>
+            dateTime.AddTicks(-(dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 100L)));
 
-        public static DateTime WithPrecisionMillisecond(DateTime dateTime)
-        {
-            long ticks = dateTime.Ticks - dateTime.Ticks % TimeSpan.TicksPerMillisecond;
-            return new DateTime(ticks, dateTime.Kind);
-        }
+        public static DateTime WithPrecisionMillisecond(DateTime dateTime) =>
+            dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerMillisecond));
 
-        public static DateTime WithPrecisionSecond(DateTime dateTime)
-        {
-            long ticks = dateTime.Ticks - dateTime.Ticks % TimeSpan.TicksPerSecond;
-            return new DateTime(ticks, dateTime.Kind);
-        }
+        public static DateTime WithPrecisionSecond(DateTime dateTime) =>
+            dateTime.AddTicks(-(dateTime.Ticks % TimeSpan.TicksPerSecond));
     }
 }