Timezone_WINCE.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // Timezone_WINCE.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Timezone_WINCE.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: DateTime
  8. // Module: Timezone
  9. //
  10. // Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/Timezone.h"
  16. #include "Poco/UnicodeConverter.h"
  17. #include "Poco/Exception.h"
  18. #include "Poco/UnWindows.h"
  19. #include <ctime>
  20. #if _WIN32_WCE >= 0x800
  21. #include "time.h"
  22. #else
  23. #include "wce_time.h"
  24. #endif
  25. namespace Poco {
  26. int Timezone::utcOffset()
  27. {
  28. TIME_ZONE_INFORMATION tzInfo;
  29. DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
  30. return -tzInfo.Bias*60;
  31. }
  32. int Timezone::dst()
  33. {
  34. TIME_ZONE_INFORMATION tzInfo;
  35. DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
  36. return dstFlag == TIME_ZONE_ID_DAYLIGHT ? -tzInfo.DaylightBias*60 : 0;
  37. }
  38. bool Timezone::isDst(const Timestamp& timestamp)
  39. {
  40. std::time_t time = timestamp.epochTime();
  41. #if _WIN32_WCE >= 0x800
  42. struct std::tm* tms = localtime(&time);
  43. #else
  44. struct std::tm* tms = wceex_localtime(&time);
  45. #endif
  46. if (!tms) throw SystemException("cannot get local time DST flag");
  47. return tms->tm_isdst > 0;
  48. }
  49. std::string Timezone::name()
  50. {
  51. std::string result;
  52. TIME_ZONE_INFORMATION tzInfo;
  53. DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
  54. WCHAR* ptr = dstFlag == TIME_ZONE_ID_DAYLIGHT ? tzInfo.DaylightName : tzInfo.StandardName;
  55. UnicodeConverter::toUTF8(ptr, result);
  56. return result;
  57. }
  58. std::string Timezone::standardName()
  59. {
  60. std::string result;
  61. TIME_ZONE_INFORMATION tzInfo;
  62. DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
  63. WCHAR* ptr = tzInfo.StandardName;
  64. UnicodeConverter::toUTF8(ptr, result);
  65. return result;
  66. }
  67. std::string Timezone::dstName()
  68. {
  69. std::string result;
  70. TIME_ZONE_INFORMATION tzInfo;
  71. DWORD dstFlag = GetTimeZoneInformation(&tzInfo);
  72. WCHAR* ptr = tzInfo.DaylightName;
  73. UnicodeConverter::toUTF8(ptr, result);
  74. return result;
  75. }
  76. } // namespace Poco