HmsFormatter.cs 836 B

1234567891011121314151617181920212223242526
  1. namespace Quadarax.Foundation.Core.Value.Formatters
  2. {
  3. /// <summary>
  4. /// Formatter for forms of seconds/hours/day
  5. /// </summary>
  6. public class HmsFormatter : ICustomFormatter, IFormatProvider
  7. {
  8. static Dictionary<string, string> _timeformats = new()
  9. {
  10. {"S", "{0:P:Seconds:Second}"},
  11. {"M", "{0:P:Minutes:Minute}"},
  12. {"H","{0:P:Hours:Hour}"},
  13. {"D", "{0:P:Days:Day}"}
  14. };
  15. public string Format(string? format, object? arg, IFormatProvider? formatProvider)
  16. {
  17. return string.Format(new PluralFormatter(),format == null ? string.Empty : _timeformats[format], arg);
  18. }
  19. public object? GetFormat(Type? formatType)
  20. {
  21. return formatType == typeof(ICustomFormatter)?this:null;
  22. }
  23. }
  24. }