DateTimeInternal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #pragma once
  6. #include "Core/CommonTypedefs.h"
  7. namespace PlatformAgnostic
  8. {
  9. namespace DateTime
  10. {
  11. struct YMD;
  12. #define DateTimeTicks_PerSecond 1000.0
  13. #define DateTimeTicks_PerMinute (60 * DateTimeTicks_PerSecond)
  14. #define DateTimeTicks_PerHour (60 * DateTimeTicks_PerMinute)
  15. #define DateTimeTicks_PerDay (DateTimeTicks_PerHour * 24)
  16. #define DateTimeTicks_PerLargestTZOffset (DateTimeTicks_PerDay + 1)
  17. #define DateTimeTicks_PerNonLeapYear (DateTimeTicks_PerDay * 365)
  18. #define DateTimeTicks_PerSafeEndOfYear (DateTimeTicks_PerNonLeapYear - DateTimeTicks_PerLargestTZOffset)
  19. #ifdef _WIN32
  20. class TimeZoneInfo // DateTime.cpp
  21. {
  22. public:
  23. double daylightDate;
  24. double standardDate;
  25. double january1;
  26. double nextJanuary1;
  27. int32 daylightBias;
  28. int32 standardBias;
  29. int32 bias;
  30. uint32 lastUpdateTickCount;
  31. bool isDaylightTimeApplicable;
  32. bool isJanuary1Critical;
  33. TimeZoneInfo();
  34. bool IsValid(const double time);
  35. void Update(const double time);
  36. };
  37. class DaylightTimeHelperPlatformData // DaylightHelper.cpp
  38. {
  39. public:
  40. TimeZoneInfo cache1, cache2;
  41. bool useFirstCache;
  42. DaylightTimeHelperPlatformData() :
  43. useFirstCache(true)
  44. {
  45. }
  46. };
  47. class UtilityPlatformData
  48. {
  49. public:
  50. TIME_ZONE_INFORMATION timeZoneInfo;
  51. uint32 lastTimeZoneUpdateTickCount;
  52. void UpdateTimeZoneInfo();
  53. UtilityPlatformData() : lastTimeZoneUpdateTickCount(0) { GetTimeZoneInformation(&timeZoneInfo); }
  54. };
  55. class HiresTimerPlatformData
  56. {
  57. public:
  58. double dBaseTime;
  59. double dLastTime;
  60. double dAdjustFactor;
  61. uint64 baseMsCount;
  62. uint64 freq;
  63. bool fReset;
  64. bool fInit;
  65. bool fHiResAvailable;
  66. HiresTimerPlatformData() :
  67. dBaseTime(0),
  68. dLastTime(0),
  69. dAdjustFactor(1),
  70. baseMsCount(0),
  71. freq(0),
  72. fReset(true),
  73. fInit(false),
  74. fHiResAvailable(true)
  75. {
  76. }
  77. void Reset() { fReset = true; }
  78. };
  79. #else // ! _WIN32
  80. typedef void* DaylightTimeHelperPlatformData;
  81. #define __CC_PA_TIMEZONE_ABVR_NAME_LENGTH 32
  82. struct UtilityPlatformData
  83. {
  84. // cache always the last date's zone
  85. WCHAR standardName[__CC_PA_TIMEZONE_ABVR_NAME_LENGTH];
  86. size_t standardNameLength;
  87. };
  88. class HiresTimerPlatformData
  89. {
  90. public:
  91. double cacheSysTime;
  92. ULONGLONG cacheTick;
  93. ULONGLONG previousDifference;
  94. HiresTimerPlatformData():cacheSysTime(0), cacheTick(-1), previousDifference(0) { }
  95. void Reset() { /* dummy method for interface compatiblity */ }
  96. };
  97. #endif // ! _WIN32
  98. } // namespace DateTime
  99. } // namespace PlatformAgnostic