DateTime.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #ifndef RUNTIME_PLATFORM_AGNOSTIC_COMMON_DATETIME
  6. #define RUNTIME_PLATFORM_AGNOSTIC_COMMON_DATETIME
  7. #include "PlatformAgnostic/DateTimeInternal.h"
  8. namespace PlatformAgnostic
  9. {
  10. namespace DateTime
  11. {
  12. class HiResTimer
  13. {
  14. private:
  15. HiresTimerPlatformData data;
  16. public:
  17. double Now();
  18. double GetSystemTime();
  19. void Reset() { data.Reset(); }
  20. };
  21. class Utility
  22. {
  23. UtilityPlatformData data;
  24. public:
  25. const WCHAR *GetStandardName(size_t *nameLength,
  26. // xplat implementation needs an actual
  27. // date for the zone abbr.
  28. const DateTime::YMD *ymd = NULL);
  29. const WCHAR *GetDaylightName(size_t *nameLength,
  30. const DateTime::YMD *ymd = NULL);
  31. };
  32. // Decomposed date (Year-Month-Date).
  33. struct YMD
  34. {
  35. int year; // year
  36. int yt; // year type: wkd of Jan 1 (plus 7 if a leap year).
  37. int mon; // month (0 to 11)
  38. int mday; // day in month (0 to 30)
  39. int yday; // day in year (0 to 365)
  40. int wday; // week day (0 to 6)
  41. int time; // time of day (in milliseconds: 0 to 86399999)
  42. void ToSystemTime(SYSTEMTIME *sys)
  43. {
  44. sys->wYear = (WORD)year;
  45. sys->wMonth = (WORD)(mon + 1);
  46. sys->wDay =(WORD)(mday + 1);
  47. int t = time;
  48. sys->wMilliseconds = (WORD)(t % 1000);
  49. t /= 1000;
  50. sys->wSecond = (WORD)(t % 60);
  51. t /= 60;
  52. sys->wMinute = (WORD)(t % 60);
  53. t /= 60;
  54. sys->wHour = (WORD)t;
  55. }
  56. };
  57. class DaylightTimeHelper
  58. {
  59. CLANG_WNO_BEGIN("-Wunused-private-field")
  60. DaylightTimeHelperPlatformData data;
  61. CLANG_WNO_END
  62. public:
  63. double UtcToLocal(double utcTime, int &bias, int &offset, bool &isDaylightSavings);
  64. double LocalToUtc(double time);
  65. };
  66. } // namespace DateTime
  67. } // namespace PlatformAgnostic
  68. #endif // RUNTIME_PLATFORM_AGNOSTIC_COMMON_DATETIME