TimeZone.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINDOWS
  3. #include "os/TimeZone.h"
  4. #include "os/Win32/WindowsHeaders.h"
  5. /*
  6. * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
  7. */
  8. const uint64_t FILETIME_ADJUST = ((uint64_t)504911232000000000LL);
  9. namespace il2cpp
  10. {
  11. namespace os
  12. {
  13. static void
  14. convert_to_absolute_date(SYSTEMTIME *date)
  15. {
  16. #define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
  17. static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  18. static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  19. /* from the calendar FAQ */
  20. int a = (14 - date->wMonth) / 12;
  21. int y = date->wYear - a;
  22. int m = date->wMonth + 12 * a - 2;
  23. int d = (1 + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12) % 7;
  24. /* d is now the day of the week for the first of the month (0 == Sunday) */
  25. int day_of_week = date->wDayOfWeek;
  26. /* set day_in_month to the first day in the month which falls on day_of_week */
  27. int day_in_month = 1 + (day_of_week - d);
  28. if (day_in_month <= 0)
  29. day_in_month += 7;
  30. /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
  31. date->wDay = day_in_month + (date->wDay - 1) * 7;
  32. if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
  33. date->wDay -= 7;
  34. }
  35. // names[0] - standardName
  36. // names[1] - daylightName
  37. bool TimeZone::GetTimeZoneData(int32_t year, int64_t data[4], std::string names[2], bool* daylight_inverted)
  38. {
  39. //On Windows, we should always load timezones in managed
  40. return false;
  41. }
  42. }
  43. }
  44. #endif