diff options
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); + } + } } |