Dates.txt 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. MODULE HostDates;
  2. (* THIS IS TEXT COPY OF Dates.odc *)
  3. (* DO NOT EDIT *)
  4. IMPORT Dates, Strings, WinApi, HostRegistry;
  5. TYPE
  6. DatesHook = POINTER TO RECORD (Dates.Hook) END;
  7. PROCEDURE (hook: DatesHook) GetTime (OUT d: Dates.Date; OUT t: Dates.Time);
  8. VAR dt: WinApi.SYSTEMTIME;
  9. BEGIN
  10. WinApi.GetLocalTime(dt);
  11. d.year := dt.wYear; d.month := dt.wMonth; d.day := dt.wDay;
  12. t.hour := dt.wHour; t.minute := dt.wMinute; t.second := dt.wSecond
  13. END GetTime;
  14. PROCEDURE (hook: DatesHook) GetUTCTime (OUT d: Dates.Date; OUT t: Dates.Time);
  15. VAR dt: WinApi.SYSTEMTIME;
  16. BEGIN
  17. WinApi.GetSystemTime(dt);
  18. d.year := dt.wYear; d.month := dt.wMonth; d.day := dt.wDay;
  19. t.hour := dt.wHour; t.minute := dt.wMinute; t.second := dt.wSecond
  20. END GetUTCTime;
  21. PROCEDURE (hook: DatesHook) GetUTCBias (OUT bias: INTEGER);
  22. VAR res: INTEGER; info: WinApi.TIME_ZONE_INFORMATION;
  23. BEGIN
  24. bias := 0;
  25. res := WinApi.GetTimeZoneInformation(info);
  26. IF res # -1 THEN
  27. IF BITS(res) = WinApi.TIME_ZONE_ID_DAYLIGHT THEN bias := info.Bias + info.DaylightBias
  28. ELSE bias := info.Bias + info.StandardBias
  29. END
  30. END
  31. END GetUTCBias;
  32. PROCEDURE (hook: DatesHook) DateToString (d: Dates.Date; format: INTEGER; OUT str: ARRAY OF CHAR);
  33. VAR res, pos, i: INTEGER; time: WinApi.SYSTEMTIME; fmt: ARRAY 64 OF CHAR;
  34. BEGIN
  35. time.wYear := SHORT(d.year); time.wMonth := SHORT(d.month); time.wDay := SHORT(d.day);
  36. IF format = Dates.short THEN
  37. res := WinApi.GetDateFormatW(
  38. HostRegistry.localeId, WinApi.DATE_SHORTDATE, time, NIL, str, LEN(str))
  39. ELSIF format = Dates.long THEN
  40. res := WinApi.GetDateFormatW(HostRegistry.localeId, WinApi.DATE_LONGDATE, time, NIL, str, LEN(str))
  41. ELSE
  42. res := WinApi.GetLocaleInfoW(HostRegistry.localeId, WinApi.LOCALE_SLONGDATE, fmt, LEN(fmt));
  43. IF format # Dates.abbreviated THEN (* remove weekday *)
  44. Strings.Find(fmt, "dddd", 0, pos); i := pos + 4;
  45. IF pos < 0 THEN Strings.Find(fmt, "ddd", 0, pos); i := pos + 3 END;
  46. IF pos >= 0 THEN
  47. WHILE (fmt[i] # 0X) & (CAP(fmt[i]) < "A") OR (CAP(fmt[i]) > "Z") DO INC(i) END;
  48. Strings.Replace(fmt, pos, i - pos, "")
  49. END
  50. END;
  51. IF format # Dates.plainLong THEN (* abbreviated *)
  52. Strings.Find(fmt, "dddd", 0, pos);
  53. IF pos >= 0 THEN Strings.Replace(fmt, pos, 4, "ddd") END;
  54. Strings.Find(fmt, "MMMM", 0, pos);
  55. IF pos >= 0 THEN Strings.Replace(fmt, pos, 4, "MMM") END
  56. END;
  57. res := WinApi.GetDateFormatW(HostRegistry.localeId, {}, time, fmt, str, LEN(str))
  58. END;
  59. IF res = 0 THEN str := "?" END
  60. END DateToString;
  61. PROCEDURE (hook: DatesHook) TimeToString (t: Dates.Time; OUT str: ARRAY OF CHAR);
  62. VAR res: INTEGER; time: WinApi.SYSTEMTIME;
  63. BEGIN
  64. time.wHour := SHORT(t.hour); time.wMinute := SHORT(t.minute);
  65. time.wSecond := SHORT(t.second); time.wMilliseconds := 0;
  66. res := WinApi.GetTimeFormatW(HostRegistry.localeId, {}, time, NIL, str, LEN(str));
  67. IF res = 0 THEN str := "?" END
  68. END TimeToString;
  69. PROCEDURE Init;
  70. VAR datesHook: DatesHook;
  71. BEGIN
  72. NEW(datesHook); Dates.SetHook(datesHook)
  73. END Init;
  74. BEGIN
  75. Init
  76. END HostDates.