IdTimeServer.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 10389: IdTimeServer.pas
  11. {
  12. { Rev 1.0 2002.11.12 10:56:56 PM czhower
  13. }
  14. unit IdTimeServer;
  15. interface
  16. {
  17. 2000-3-May J. Peter Mugaas
  18. -Added BaseDate to the date the calculations are based on can be
  19. adjusted to work after the year 2035
  20. 2000-30-April J. Peter Mugaas
  21. -Adjusted the formula for the integer so that the Time is now
  22. always based on Universal Time (also known as Greenwhich Mean
  23. -Time Replaced the old forumala used to calculate the time with
  24. a new one suggested by Jim Gunkel. This forumala is more
  25. accurate than the old one.
  26. 2000-24-April J. Peter Mugaaas
  27. -This now uses the Internet Byte order functions
  28. 2000-22-Apr J Peter Mugass
  29. -Ported to Indy
  30. -Fixed a problem where the server was not returning anything
  31. 2000-13-Jan MTL
  32. -Moved to new Palette Scheme (Winshoes Servers)
  33. 1999-13-Apr
  34. -Final Version
  35. Original Author: Ozz Nixon
  36. -Based on RFC 868
  37. }
  38. uses
  39. Classes,
  40. IdAssignedNumbers,
  41. IdTCPServer;
  42. const
  43. {This indicates that the default date is Jan 1, 1900 which was specified
  44. by RFC 868.}
  45. TIME_DEFBASEDATE = 2;
  46. Type
  47. TIdTimeServer = class(TIdTCPServer)
  48. protected
  49. FBaseDate : TDateTime;
  50. //
  51. function DoExecute(AThread: TIdPeerThread): Boolean; override;
  52. public
  53. constructor Create(AOwner: TComponent); override;
  54. published
  55. {This property is used to set the Date the Time server bases it's
  56. calculations from. If both the server and client are based from the same
  57. date which is higher than the original date, you can extend it beyond the
  58. year 2035}
  59. property BaseDate : TDateTime read FBaseDate write FBaseDate;
  60. property DefaultPort default IdPORT_TIME;
  61. end;
  62. implementation
  63. uses
  64. IdGlobal,
  65. IdStack, SysUtils;
  66. constructor TIdTimeServer.Create(AOwner: TComponent);
  67. begin
  68. inherited;
  69. DefaultPort := IdPORT_TIME;
  70. {This indicates that the default date is Jan 1, 1900 which was specified
  71. by RFC 868.}
  72. FBaseDate := 2;
  73. end;
  74. function TIdTimeServer.DoExecute(AThread: TIdPeerThread): Boolean;
  75. begin
  76. Result := true;
  77. with AThread.Connection do begin
  78. WriteCardinal(Trunc(extended(Now + IdGlobal.TimeZoneBias - Int(FBaseDate)) * 24 * 60 * 60));
  79. Disconnect;
  80. end;
  81. end;
  82. end.