datih.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. type
  20. PDayTable = ^TDayTable;
  21. TDayTable = array[1..12] of Word;
  22. const
  23. HoursPerDay = 24;
  24. MinsPerHour = 60;
  25. SecsPerMin = 60;
  26. MSecsPerSec = 1000;
  27. MinsPerDay = HoursPerDay * MinsPerHour;
  28. SecsPerDay = MinsPerDay * SecsPerMin;
  29. MSecsPerDay = SecsPerDay * MSecsPerSec;
  30. DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
  31. UnixDateDelta = 25569;
  32. { True=Leapyear }
  33. MonthDays: array [Boolean] of TDayTable =
  34. ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
  35. (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
  36. TwoDigitYearCenturyWindow : word=0;
  37. { Threshold to be subtracted from year before
  38. age-detection.}
  39. { date time formatting characters:
  40. c : shortdateformat + ' ' + shorttimeformat
  41. d : day of month
  42. dd : day of month (leading zero)
  43. ddd : day of week (abbreviation)
  44. dddd : day of week (full)
  45. ddddd : shortdateformat
  46. dddddd : longdateformat
  47. m : month
  48. mm : month (leading zero)
  49. mmm : month (abbreviation)
  50. mmmm : month (full)
  51. y : year (four digits)
  52. yy : year (two digits)
  53. yyyy : year (with century)
  54. h : hour
  55. hh : hour (leading zero)
  56. n : minute
  57. nn : minute (leading zero)
  58. s : second
  59. ss : second (leading zero)
  60. t : shorttimeformat
  61. tt : longtimeformat
  62. am/pm : use 12 hour clock and display am and pm accordingly
  63. a/p : use 12 hour clock and display a and p accordingly
  64. / : insert date seperator
  65. : : insert time seperator
  66. "xx" : literal text
  67. 'xx' : literal text
  68. }
  69. type
  70. {$ifndef win32}
  71. { Win32 reuses the struct from the Windows unit }
  72. TSystemTime = record
  73. Year, Month, Day: word;
  74. Hour, Minute, Second, MilliSecond: word;
  75. end ;
  76. {$endif win32}
  77. TTimeStamp = record
  78. Time: integer; { Number of milliseconds since midnight }
  79. Date: integer; { One plus number of days since 1/1/0001 }
  80. end ;
  81. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  82. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  83. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  84. function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  85. function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
  86. function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
  87. function EncodeDate(Year, Month, Day :word): TDateTime;
  88. function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  89. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  90. function DecodeDateFully(const DateTime: TDateTime; var Year, Month, Day, DOW: Word): Boolean;
  91. procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  92. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  93. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  94. function DayOfWeek(DateTime: TDateTime): integer;
  95. function Date: TDateTime;
  96. function Time: TDateTime;
  97. function Now: TDateTime;
  98. function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  99. function IsLeapYear(Year: Word): boolean;
  100. function DateToStr(Date: TDateTime): string;
  101. function TimeToStr(Time: TDateTime): string;
  102. function DateTimeToStr(DateTime: TDateTime): string;
  103. function StrToDate(const S: string): TDateTime;
  104. function StrToTime(const S: string): TDateTime;
  105. function StrToDateTime(const S: string): TDateTime;
  106. function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  107. procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  108. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  109. Function FileDateToDateTime (Filedate : Longint) :TDateTime;
  110. { FPC Extra }
  111. Procedure GetLocalTime(var SystemTime: TSystemTime);
  112. {
  113. $Log$
  114. Revision 1.1 2003-10-06 21:01:06 peter
  115. * moved classes unit to rtl
  116. Revision 1.8 2003/01/18 23:45:37 michael
  117. + Fixed EncodeDate/Time so they use TryEncodeDate/Time
  118. Revision 1.7 2002/12/25 01:03:48 peter
  119. * some date constants added
  120. Revision 1.6 2002/10/02 21:04:06 peter
  121. * For win32 use the tsystemtime from the windows unit, that is changed
  122. to a variant record with compatibile field names
  123. Revision 1.5 2002/09/07 16:01:22 peter
  124. * old logs removed and tabs fixed
  125. }