UtcClockProvider.cs 824 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace Abp.Timing
  3. {
  4. /// <summary>
  5. /// Implements <see cref="IClockProvider"/> to work with UTC times.
  6. /// </summary>
  7. public class UtcClockProvider : IClockProvider
  8. {
  9. public DateTime Now => DateTime.UtcNow;
  10. public DateTimeKind Kind => DateTimeKind.Utc;
  11. public bool SupportsMultipleTimezone => true;
  12. public DateTime Normalize(DateTime dateTime)
  13. {
  14. if (dateTime.Kind == DateTimeKind.Unspecified)
  15. {
  16. return DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
  17. }
  18. if (dateTime.Kind == DateTimeKind.Local)
  19. {
  20. return dateTime.ToUniversalTime();
  21. }
  22. return dateTime;
  23. }
  24. internal UtcClockProvider()
  25. {
  26. }
  27. }
  28. }