Time.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "os/c-api/il2cpp-config-platforms.h"
  2. #include "os/Time.h"
  3. #include <stdint.h>
  4. #include <time.h>
  5. extern "C"
  6. {
  7. #if !RUNTIME_TINY
  8. uint32_t UnityPalGetTicksMillisecondsMonotonic()
  9. {
  10. return il2cpp::os::Time::GetTicksMillisecondsMonotonic();
  11. }
  12. int64_t UnityPalGetTicks100NanosecondsDateTime()
  13. {
  14. return il2cpp::os::Time::GetTicks100NanosecondsDateTime();
  15. }
  16. #endif
  17. int64_t STDCALL UnityPalGetTicks100NanosecondsMonotonic()
  18. {
  19. return il2cpp::os::Time::GetTicks100NanosecondsMonotonic();
  20. }
  21. int64_t STDCALL UnityPalGetSystemTimeAsFileTime()
  22. {
  23. return il2cpp::os::Time::GetSystemTimeAsFileTime();
  24. }
  25. #if IL2CPP_TINY
  26. int32_t STDCALL UnityPalGetUtcOffsetHours(int64_t secondsSinceEpoch)
  27. {
  28. struct tm* utcTime = gmtime((time_t*)&secondsSinceEpoch);
  29. time_t utc = mktime(utcTime);
  30. struct tm* localTime = localtime((time_t*)&secondsSinceEpoch);
  31. time_t local = mktime(localTime);
  32. time_t offsetSeconds = local - utc;
  33. int daylightSavingsOffset = 0;
  34. if (localTime->tm_isdst)
  35. daylightSavingsOffset = 1;
  36. return (int32_t)offsetSeconds / 3600 + daylightSavingsOffset;
  37. }
  38. bool STDCALL UnityPalIsDaylightSavingsTime(int64_t secondsSinceEpoch)
  39. {
  40. struct tm* tt = localtime((time_t*)&secondsSinceEpoch);
  41. int32_t daylightSavingsOffset = 0;
  42. return tt->tm_isdst > 0;
  43. }
  44. #endif
  45. }