Clock.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. namespace Abp.Timing
  3. {
  4. /// <summary>
  5. /// Used to perform some common date-time operations.
  6. /// </summary>
  7. public static class Clock
  8. {
  9. /// <summary>
  10. /// This object is used to perform all <see cref="Clock"/> operations.
  11. /// Default value: <see cref="UnspecifiedClockProvider"/>.
  12. /// </summary>
  13. public static IClockProvider Provider
  14. {
  15. get { return _provider; }
  16. set
  17. {
  18. if (value == null)
  19. {
  20. throw new ArgumentNullException(nameof(value), "Can not set Clock.Provider to null!");
  21. }
  22. _provider = value;
  23. }
  24. }
  25. private static IClockProvider _provider;
  26. static Clock()
  27. {
  28. Provider = ClockProviders.Unspecified;
  29. }
  30. /// <summary>
  31. /// Gets Now using current <see cref="Provider"/>.
  32. /// </summary>
  33. public static DateTime Now => Provider.Now;
  34. public static DateTimeKind Kind => Provider.Kind;
  35. /// <summary>
  36. /// Returns true if multiple timezone is supported, returns false if not.
  37. /// </summary>
  38. public static bool SupportsMultipleTimezone => Provider.SupportsMultipleTimezone;
  39. /// <summary>
  40. /// Normalizes given <see cref="DateTime"/> using current <see cref="Provider"/>.
  41. /// </summary>
  42. /// <param name="dateTime">DateTime to be normalized.</param>
  43. /// <returns>Normalized DateTime</returns>
  44. public static DateTime Normalize(DateTime dateTime)
  45. {
  46. return Provider.Normalize(dateTime);
  47. }
  48. }
  49. }