HmsFormatter.cs 865 B

12345678910111213141516171819202122232425262728
  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 Dictionary<string, string> {
  11. {"S", "{0:P:Seconds:Second}"},
  12. {"M", "{0:P:Minutes:Minute}"},
  13. {"H","{0:P:Hours:Hour}"},
  14. {"D", "{0:P:Days:Day}"}
  15. };
  16. public string Format(string format, object arg, IFormatProvider formatProvider)
  17. {
  18. return string.Format(new PluralFormatter(),_timeformats[format], arg);
  19. }
  20. public object GetFormat(Type formatType)
  21. {
  22. return formatType == typeof(ICustomFormatter)?this:null;
  23. }
  24. }
  25. }