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 | |
parent | removed unused SecureRandom (diff) | |
download | BouncyCastle.NET-ed25519-879bb29bb0058a0723326de6edebb201e4cbc0b8.tar.xz |
Overhaul GeneralizedTime classes
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/Platform.cs | 15 | ||||
-rw-r--r-- | crypto/src/util/date/DateTimeUtilities.cs | 28 |
2 files changed, 42 insertions, 1 deletions
diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs index 118c29918..78ff6cee4 100644 --- a/crypto/src/util/Platform.cs +++ b/crypto/src/util/Platform.cs @@ -31,11 +31,26 @@ namespace Org.BouncyCastle.Utilities d.Dispose(); } + internal static int IndexOf(string source, char value) + { + return InvariantCompareInfo.IndexOf(source, value, CompareOptions.Ordinal); + } + internal static int IndexOf(string source, string value) { return InvariantCompareInfo.IndexOf(source, value, CompareOptions.Ordinal); } + internal static int IndexOf(string source, char value, int startIndex) + { + return InvariantCompareInfo.IndexOf(source, value, startIndex, CompareOptions.Ordinal); + } + + internal static int IndexOf(string source, string value, int startIndex) + { + return InvariantCompareInfo.IndexOf(source, value, startIndex, CompareOptions.Ordinal); + } + internal static int LastIndexOf(string source, string value) { return InvariantCompareInfo.LastIndexOf(source, value, CompareOptions.Ordinal); 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); + } + } } |