PageRenderTime 21ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/platform/win/scaffold/time.d

http://github.com/wilkie/djehuty
D | 101 lines | 62 code | 24 blank | 15 comment | 8 complexity | 2b586315778df21d4f2c89539b2a687e MD5 | raw file
  1. /*
  2. * time.d
  3. *
  4. * This file implements the Scaffold for platform specific Time
  5. * operations in Windows.
  6. *
  7. * Author: Dave Wilkinson
  8. *
  9. */
  10. module scaffold.time;
  11. pragma(lib, "winmm.lib");
  12. import platform.win.common;
  13. import core.date;
  14. import core.definitions;
  15. import core.string;
  16. // Timing
  17. import io.console;
  18. string TimeZoneGet() {
  19. TIME_ZONE_INFORMATION tzi;
  20. GetTimeZoneInformation(&tzi);
  21. // Use Bias information.
  22. // The Bias entry is calculated as the difference from UTC such that:
  23. // UTC = lcoal time + bias.
  24. // Therefore, we need to use the negative of the Bias.
  25. int diff_hr, diff_min;
  26. diff_hr = -tzi.Bias / 60;
  27. diff_min = -tzi.Bias % 60;
  28. string ret = "UTC" ~ toStr(diff_hr) ~ ":";
  29. if (diff_min < 10) {
  30. ret ~= "0";
  31. }
  32. ret ~= toStr(diff_min);
  33. // Use other information
  34. wchar[] tzname = "";
  35. size_t len = strlen(tzi.StandardName.ptr);
  36. if (len != 0) {
  37. tzname = new wchar[len];
  38. tzname[0..len] = (tzi.StandardName.ptr)[0..len];
  39. switch (tzname) {
  40. case "EST":
  41. if (diff_hr != -5) { break; }
  42. case "Eastern Standard Time":
  43. return "Eastern Standard Time";
  44. case "PST":
  45. if (diff_hr != -8) { break; }
  46. case "Pacific Standard Time":
  47. return "Pacific Standard Time";
  48. default:
  49. break;
  50. }
  51. }
  52. return ret;
  53. }
  54. long TimeGet() {
  55. SYSTEMTIME sysTime;
  56. GetSystemTime(&sysTime);
  57. long micros;
  58. micros = cast(long)sysTime.wHour;
  59. micros *= 60L;
  60. micros += cast(long)sysTime.wMinute;
  61. micros *= 60L;
  62. micros += cast(long)sysTime.wSecond;
  63. micros *= 1000;
  64. micros += cast(long)sysTime.wMilliseconds;
  65. micros *= 1000L;
  66. return micros;
  67. }
  68. long SystemTimeGet() {
  69. return timeGetTime();
  70. }
  71. void DateGet(out Month month, out uint day, out uint year) {
  72. SYSTEMTIME sysTime;
  73. GetSystemTime(&sysTime);
  74. month = cast(Month)(sysTime.wMonth - 1);
  75. day = sysTime.wDay;
  76. year = sysTime.wYear;
  77. }