mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Use CultureInfo.GetCultureInfo for DateTimeSpanExtensions.LocAbsolute instead (#1742)
* MMmm * Use regional culture infos instead
This commit is contained in:
parent
6027aaab77
commit
eb5fa24101
1 changed files with 18 additions and 12 deletions
|
|
@ -15,6 +15,10 @@ public static class DateTimeSpanExtensions
|
||||||
{
|
{
|
||||||
private static readonly ModuleLog Log = new(nameof(DateTimeSpanExtensions));
|
private static readonly ModuleLog Log = new(nameof(DateTimeSpanExtensions));
|
||||||
|
|
||||||
|
private static readonly CultureInfo Region0CultureInfo = CultureInfo.GetCultureInfo("ja-jp");
|
||||||
|
private static readonly CultureInfo Region1CultureInfo = CultureInfo.GetCultureInfo("en-us");
|
||||||
|
private static readonly CultureInfo Region2CultureInfo = CultureInfo.GetCultureInfo("en-gb");
|
||||||
|
|
||||||
private static ParsedRelativeFormatStrings? relativeFormatStringLong;
|
private static ParsedRelativeFormatStrings? relativeFormatStringLong;
|
||||||
|
|
||||||
private static ParsedRelativeFormatStrings? relativeFormatStringShort;
|
private static ParsedRelativeFormatStrings? relativeFormatStringShort;
|
||||||
|
|
@ -27,21 +31,23 @@ public static class DateTimeSpanExtensions
|
||||||
public static unsafe string LocAbsolute(this DateTime when)
|
public static unsafe string LocAbsolute(this DateTime when)
|
||||||
{
|
{
|
||||||
var culture = Service<Localization>.GetNullable()?.DalamudLanguageCultureInfo ?? CultureInfo.InvariantCulture;
|
var culture = Service<Localization>.GetNullable()?.DalamudLanguageCultureInfo ?? CultureInfo.InvariantCulture;
|
||||||
if (!Equals(culture, CultureInfo.InvariantCulture))
|
if (Equals(culture, CultureInfo.InvariantCulture))
|
||||||
return when.ToString("G", culture);
|
{
|
||||||
|
|
||||||
var framework = FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance();
|
var framework = FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance();
|
||||||
var region = 0;
|
var region = 0;
|
||||||
if (framework is not null)
|
if (framework is not null)
|
||||||
region = framework->Region;
|
region = framework->Region;
|
||||||
return region switch
|
culture = region switch
|
||||||
{
|
{
|
||||||
1 => when.ToString("MM/dd/yyyy HH:mm:ss"), // na
|
1 => Region1CultureInfo,
|
||||||
2 => when.ToString("dd-mm-yyyy HH:mm:ss"), // eu
|
2 => Region2CultureInfo,
|
||||||
_ => when.ToString("yyyy-MM-dd HH:mm:ss"), // jp(0), cn(3), kr(4), and other possible errorneous cases
|
_ => Region0CultureInfo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return when.ToString("G", culture);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Formats an instance of <see cref="DateTime"/> as a localized relative time.</summary>
|
/// <summary>Formats an instance of <see cref="DateTime"/> as a localized relative time.</summary>
|
||||||
/// <param name="when">When.</param>
|
/// <param name="when">When.</param>
|
||||||
/// <param name="floorBy">The alignment unit of time span.</param>
|
/// <param name="floorBy">The alignment unit of time span.</param>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue