diff --git a/MAA.sln.DotSettings b/MAA.sln.DotSettings index 3e53fc188c..57ad328c91 100644 --- a/MAA.sln.DotSettings +++ b/MAA.sln.DotSettings @@ -52,6 +52,7 @@ True True True + True True True True diff --git a/src/MaaWpfGui/Extensions/DateTimeExtension.cs b/src/MaaWpfGui/Extensions/DateTimeExtension.cs index e7aae1728c..4e6497c44f 100644 --- a/src/MaaWpfGui/Extensions/DateTimeExtension.cs +++ b/src/MaaWpfGui/Extensions/DateTimeExtension.cs @@ -11,6 +11,7 @@ // but WITHOUT ANY WARRANTY // +#nullable enable using System; using System.Collections.Generic; using System.Globalization; @@ -25,7 +26,7 @@ namespace MaaWpfGui.Extensions private static string ClientType => ConfigurationHelper.GetValue(ConfigurationKeys.ClientType, string.Empty); - private static readonly Dictionary _clientTypeTimezone = new Dictionary + private static readonly Dictionary _clientTypeTimezone = new() { { string.Empty, 8 }, { "Official", 8 }, @@ -56,10 +57,9 @@ namespace MaaWpfGui.Extensions return dt is { Month: 4, Day: 1 }; } - public static string ToLocalTimeString(this DateTime dt) + public static string ToLocalTimeString(this DateTime dt, string? format = null, string? shortDatePattern = null, string? longTimePattern = "HH:mm:ss") { - var dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat; - return dt.ToLocalTime().ToString(dateTimeFormat.ShortDatePattern + " HH:mm:ss"); + return dt.ToLocalTime().ToString(format ?? $"{shortDatePattern ?? CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern} {longTimePattern}", CultureInfo.CurrentCulture); } public static DateTime ToDateTime(this System.Runtime.InteropServices.ComTypes.FILETIME filetime)