HmsFormatter.cs 885 B

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