DateTime.h 2.4 KB

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