diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-08 13:18:17 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-08 13:18:17 +0700 |
commit | 879bb29bb0058a0723326de6edebb201e4cbc0b8 (patch) | |
tree | 089e7769c2342a99dfa7549c57290522f72c451b /crypto/src/util/date/DateTimeUtilities.cs | |
parent | removed unused SecureRandom (diff) | |
download | BouncyCastle.NET-ed25519-879bb29bb0058a0723326de6edebb201e4cbc0b8.tar.xz |
Overhaul GeneralizedTime classes
Diffstat (limited to 'crypto/src/util/date/DateTimeUtilities.cs')
-rw-r--r-- | crypto/src/util/date/DateTimeUtilities.cs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/crypto/src/util/date/DateTimeUtilities.cs b/crypto/src/util/date/DateTimeUtilities.cs index 3660e29c2..c46cde8db 100644 --- a/crypto/src/util/date/DateTimeUtilities.cs +++ b/crypto/src/util/date/DateTimeUtilities.cs @@ -53,5 +53,31 @@ namespace Org.BouncyCastle.Utilities.Date { return DateTimeToUnixMs(DateTime.UtcNow); } - } + + 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); + } + + 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); + } + + 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); + } + + public static DateTime WithPrecisionSecond(DateTime dateTime) + { + return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, + dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind); + } + } } |