Fix playtime formatting (#32974)
This commit is contained in:
@@ -36,6 +36,7 @@ namespace Content.Shared.Localizations
|
||||
_loc.AddFunction(culture, "LOC", FormatLoc);
|
||||
_loc.AddFunction(culture, "NATURALFIXED", FormatNaturalFixed);
|
||||
_loc.AddFunction(culture, "NATURALPERCENT", FormatNaturalPercent);
|
||||
_loc.AddFunction(culture, "PLAYTIME", FormatPlaytime);
|
||||
|
||||
|
||||
/*
|
||||
@@ -141,6 +142,16 @@ namespace Content.Shared.Localizations
|
||||
return Loc.GetString($"zzzz-fmt-direction-{dir.ToString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats playtime as hours and minutes.
|
||||
/// </summary>
|
||||
public static string FormatPlaytime(TimeSpan time)
|
||||
{
|
||||
var hours = (int)time.TotalHours;
|
||||
var minutes = time.Minutes;
|
||||
return Loc.GetString($"zzzz-fmt-playtime", ("hours", hours), ("minutes", minutes));
|
||||
}
|
||||
|
||||
private static ILocValue FormatLoc(LocArgs args)
|
||||
{
|
||||
var id = ((LocValueString) args.Args[0]).Value;
|
||||
@@ -229,5 +240,15 @@ namespace Content.Shared.Localizations
|
||||
|
||||
return new LocValueString(res);
|
||||
}
|
||||
|
||||
private static ILocValue FormatPlaytime(LocArgs args)
|
||||
{
|
||||
var time = TimeSpan.Zero;
|
||||
if (args.Args is { Count: > 0 } && args.Args[0].Value is TimeSpan timeArg)
|
||||
{
|
||||
time = timeArg;
|
||||
}
|
||||
return new LocValueString(FormatPlaytime(time));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user