Skip to content

Commit

Permalink
Add factory method for localized durations
Browse files Browse the repository at this point in the history
  • Loading branch information
aetherstrata committed Feb 15, 2024
1 parent 633b5de commit 3730512
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 1 addition & 4 deletions Aosta.Ava/Aosta.Ava/Converters/NullValueBoolConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@ public object Convert(object? value, Type targetType, object? parameter, Culture
return value;
}

public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
public override object ProvideValue(IServiceProvider serviceProvider) => this;
}
12 changes: 11 additions & 1 deletion Aosta.Ava/Aosta.Ava/Localization/LocalizedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ public abstract class LocalizedString(string key) : ReactiveObject, ILocalized,

public static LocalizedString CompactDate(DateTimeOffset dt)
{
return new TwoArgs(compact_date_keys[dt.Month], dt.Day, dt.Year);
return Create(compact_date_keys[dt.Month], dt.Day, dt.Year);
}

public static LocalizedString Duration(TimeSpan span)
{
return span switch
{
{ Hours: > 0 } => Create("Duration.Compact.Hours", span.Hours, span.Minutes, span.Seconds),
{ Minutes: > 0 } => Create("Duration.Compact.Minutes", span.Minutes, span.Seconds),
_ => Create("Duration.Compact.Seconds", span.Seconds)
};
}

public static LocalizedString Create(string key) => new ZeroArgs(key);
Expand Down

0 comments on commit 3730512

Please sign in to comment.