datih.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. var
  36. TwoDigitYearCenturyWindow : word absolute DefaultFormatSettings.TwoDigitYearCenturyWindow;
  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. { windows isn't defined in 2.0.2 (FK) }
  71. {$if not(defined(windows)) and not(defined(win32))}
  72. { Win32 reuses the struct from the Windows unit }
  73. TSystemTime = record
  74. Year, Month, Day: word;
  75. Hour, Minute, Second, MilliSecond: word;
  76. end ;
  77. {$endif windows}
  78. TTimeStamp = record
  79. Time: integer; { Number of milliseconds since midnight }
  80. Date: integer; { One plus number of days since 1/1/0001 }
  81. end ;
  82. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  83. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  84. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  85. function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  86. function TryEncodeDate(Year, Month, Day: Word; out Date: TDateTime): Boolean;
  87. function TryEncodeTime(Hour, Min, Sec, MSec: Word; out Time: TDateTime): Boolean;
  88. function EncodeDate(Year, Month, Day :word): TDateTime;
  89. function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  90. function ComposeDateTime(Date,Time : TDateTime) : TDateTime;
  91. procedure DecodeDate(Date: TDateTime; out Year, Month, Day: word);
  92. function DecodeDateFully(const DateTime: TDateTime; out Year, Month, Day, DOW: Word): Boolean;
  93. procedure DecodeTime(Time: TDateTime; out Hour, Minute, Second, MilliSecond: word);
  94. procedure DateTimeToSystemTime(DateTime: TDateTime; out SystemTime: TSystemTime);
  95. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  96. function DayOfWeek(DateTime: TDateTime): integer;
  97. function Date: TDateTime;
  98. function Time: TDateTime;
  99. function Now: TDateTime;
  100. function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer = 1 ): TDateTime;
  101. function IsLeapYear(Year: Word): boolean;
  102. function DateToStr(Date: TDateTime): string;
  103. function TimeToStr(Time: TDateTime): string;
  104. function DateTimeToStr(DateTime: TDateTime): string;
  105. function StrToDate(const S: string): TDateTime;
  106. function StrToTime(const S: string): TDateTime;
  107. function StrToDateTime(const S: string): TDateTime;
  108. function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  109. procedure DateTimeToString(out Result: string; const FormatStr: string; const DateTime: TDateTime);
  110. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  111. Function FileDateToDateTime (Filedate : Longint) :TDateTime;
  112. function TryStrToDate(const S: string; out Value: TDateTime): Boolean;
  113. function TryStrToTime(const S: string; out Value: TDateTime): Boolean;
  114. function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
  115. // function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
  116. // function TryStrToTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
  117. // function TryStrToDateTime(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean;
  118. function StrToDateDef(const S: string; const Defvalue : TDateTime): TDateTime;
  119. function StrToTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
  120. function StrToDateTimeDef(const S: string; const Defvalue : TDateTime): TDateTime;
  121. function CurrentYear:Word;
  122. { FPC Extra }
  123. Procedure GetLocalTime(var SystemTime: TSystemTime);
  124. procedure ReplaceTime(var dati:TDateTime; NewTime : TDateTime); inline;