TimeSpanHelper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System;
  7. using System.Runtime;
  8. using System.Globalization;
  9. static class TimeSpanHelper
  10. {
  11. static public TimeSpan FromMinutes(int minutes, string text)
  12. {
  13. TimeSpan value = TimeSpan.FromTicks(TimeSpan.TicksPerMinute * minutes);
  14. Fx.Assert(value == TimeSpan.Parse(text, CultureInfo.InvariantCulture), "");
  15. return value;
  16. }
  17. static public TimeSpan FromSeconds(int seconds, string text)
  18. {
  19. TimeSpan value = TimeSpan.FromTicks(TimeSpan.TicksPerSecond * seconds);
  20. Fx.Assert(value == TimeSpan.Parse(text, CultureInfo.InvariantCulture), "");
  21. return value;
  22. }
  23. static public TimeSpan FromMilliseconds(int ms, string text)
  24. {
  25. TimeSpan value = TimeSpan.FromTicks(TimeSpan.TicksPerMillisecond * ms);
  26. Fx.Assert(value == TimeSpan.Parse(text, CultureInfo.InvariantCulture), "");
  27. return value;
  28. }
  29. static public TimeSpan FromDays(int days, string text)
  30. {
  31. TimeSpan value = TimeSpan.FromTicks(TimeSpan.TicksPerDay * days);
  32. Fx.Assert(value == TimeSpan.Parse(text, CultureInfo.InvariantCulture), "");
  33. return value;
  34. }
  35. }
  36. }