diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-05-24 23:21:12 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-05-24 23:21:12 +0700 |
commit | aa4f6e11a9b7103a2baf6617664f387575a2a774 (patch) | |
tree | 476d4b5ad3b68878909a6fb4df6d758d7067e6ad /crypto/src/util | |
parent | Refactoring in Asn1.Ocsp (diff) | |
download | BouncyCastle.NET-ed25519-aa4f6e11a9b7103a2baf6617664f387575a2a774.tar.xz |
Refactor DateTimeUtilities
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/date/DateTimeUtilities.cs | 33 |
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)); } } |