diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-09 17:22:03 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-09 17:22:03 +0700 |
commit | b69b93cdb558b392e80362af340b151c04375ebc (patch) | |
tree | 4ad2ef9dc766631b40fc8cbf8df7effa5923c460 /crypto | |
parent | Simplify digest calculation (diff) | |
download | BouncyCastle.NET-ed25519-b69b93cdb558b392e80362af340b151c04375ebc.tar.xz |
Simplify WithPrecision methods
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/util/date/DateTimeUtilities.cs | 18 |
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); } } } |