datih.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {
  2. *********************************************************************
  3. $Id$
  4. Copyright (C) 1997, 1998 Gertjan Schouten
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *********************************************************************
  17. System Utilities For Free Pascal
  18. }
  19. const
  20. SecsPerDay = 24 * 60 * 60; // Seconds and milliseconds per day
  21. MSecsPerDay = SecsPerDay * 1000;
  22. DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
  23. TwoDigitYearCenturyWindow : word=0;
  24. { Threshold to be subtracted from year before
  25. age-detection.}
  26. { date time formatting characters:
  27. c : shortdateformat + ' ' + shorttimeformat
  28. d : day of month
  29. dd : day of month (leading zero)
  30. ddd : day of week (abbreviation)
  31. dddd : day of week (full)
  32. ddddd : shortdateformat
  33. dddddd : longdateformat
  34. m : month
  35. mm : month (leading zero)
  36. mmm : month (abbreviation)
  37. mmmm : month (full)
  38. y : year (four digits)
  39. yy : year (two digits)
  40. yyyy : year (with century)
  41. h : hour
  42. hh : hour (leading zero)
  43. n : minute
  44. nn : minute (leading zero)
  45. s : second
  46. ss : second (leading zero)
  47. t : shorttimeformat
  48. tt : longtimeformat
  49. am/pm : use 12 hour clock and display am and pm accordingly
  50. a/p : use 12 hour clock and display a and p accordingly
  51. / : insert date seperator
  52. : : insert time seperator
  53. "xx" : literal text
  54. 'xx' : literal text
  55. }
  56. type
  57. {$ifndef win32}
  58. { Win32 reuses the struct from the Windows unit }
  59. TSystemTime = record
  60. Year, Month, Day: word;
  61. Hour, Minute, Second, MilliSecond: word;
  62. end ;
  63. {$endif win32}
  64. TTimeStamp = record
  65. Time: integer; { Number of milliseconds since midnight }
  66. Date: integer; { One plus number of days since 1/1/0001 }
  67. end ;
  68. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  69. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  70. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  71. function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  72. function EncodeDate(Year, Month, Day :word): TDateTime;
  73. function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  74. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  75. procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  76. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  77. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  78. function DayOfWeek(DateTime: TDateTime): integer;
  79. function Date: TDateTime;
  80. function Time: TDateTime;
  81. function Now: TDateTime;
  82. function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  83. function IsLeapYear(Year: Word): boolean;
  84. function DateToStr(Date: TDateTime): string;
  85. function TimeToStr(Time: TDateTime): string;
  86. function DateTimeToStr(DateTime: TDateTime): string;
  87. function StrToDate(const S: string): TDateTime;
  88. function StrToTime(const S: string): TDateTime;
  89. function StrToDateTime(const S: string): TDateTime;
  90. function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  91. procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  92. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  93. Function FileDateToDateTime (Filedate : Longint) :TDateTime;
  94. { FPC Extra }
  95. Procedure GetLocalTime(var SystemTime: TSystemTime);
  96. {
  97. $Log$
  98. Revision 1.6 2002-10-02 21:04:06 peter
  99. * For win32 use the tsystemtime from the windows unit, that is changed
  100. to a variant record with compatibile field names
  101. Revision 1.5 2002/09/07 16:01:22 peter
  102. * old logs removed and tabs fixed
  103. }