Windows.Clock.Mod 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. MODULE Clock; (** fof , adaption of interface of Aos modules Clock to windows version **)
  2. (* ETH Oberon, Copyright 2003 ETH Zuerich Institut fuer Computersysteme, ETH Zentrum, CH-8092 Zuerich.
  3. Refer to the "General ETH Oberon System Source License" contract available at: http://www.oberon.ethz.ch/ *)
  4. (*
  5. history
  6. first version (windows): 01.04.2003, fof.
  7. todo
  8. *)
  9. IMPORT Kernel32;
  10. VAR tz*: LONGINT; (** system time zone offset in minutes (from -720 to 720) *)
  11. starttime*, startdate*: LONGINT; (** time this module was loaded (usually boot time) *)
  12. (** Get time (t) and date (d).
  13. day = d MOD 32, month = d DIV 32 MOD 16, year = 1900+d DIV 512,
  14. hour = t DIV 4096 MOD 32, minute = t DIV 64 MOD 64, second = t MOD 64 *)
  15. PROCEDURE Get* (VAR t, d: LONGINT);
  16. VAR st: Kernel32.SystemTime;
  17. BEGIN
  18. t := 0; d := 0;
  19. Kernel32.GetLocalTime(st);
  20. d := st.wYear - 1900; d := ASH(d, 4);
  21. d := d + st.wMonth; d := ASH(d, 5);
  22. d := d + st.wDay;
  23. t := st.wHour; t := ASH(t, 6);
  24. t := t + st.wMinute; t := ASH(t, 6);
  25. t := t + st.wSecond
  26. END Get;
  27. (** Set time (t) and date (d). *)
  28. PROCEDURE Set* (t, d: LONGINT);
  29. VAR st: Kernel32.SystemTime;retBOOL: Kernel32.BOOL; (* Dan 09.11.05 *)
  30. BEGIN
  31. st.wDay := SHORT(d MOD 20H); d := ASH(d, - 5);
  32. st.wMonth := SHORT(d MOD 10H); d := ASH(d, - 4);
  33. st.wYear := SHORT(d MOD 80H) + 1900;
  34. st.wMilliseconds := 0;
  35. st.wSecond := SHORT(t MOD 40H); t := ASH(t, - 6);
  36. st.wMinute := SHORT(t MOD 40H); t := ASH(t, - 6);
  37. st.wHour := SHORT(t MOD 20H);
  38. retBOOL := Kernel32.SetLocalTime(st)
  39. END Set;
  40. (* Get and Set taken from Module Oberon, (C) Copyright ETH Zuerich Institut fuer Computersysteme, ETH Zentrum, CH-8092 Zuerich *)
  41. BEGIN
  42. Get(starttime,startdate)
  43. END Clock.