datih.inc 5.4 KB

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