datih.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. { date time formatting characters:
  24. c : shortdateformat + ' ' + shorttimeformat
  25. d : day of month
  26. dd : day of month (leading zero)
  27. ddd : day of week (abbreviation)
  28. dddd : day of week (full)
  29. ddddd : shortdateformat
  30. dddddd : longdateformat
  31. m : month
  32. mm : month (leading zero)
  33. mmm : month (abbreviation)
  34. mmmm : month (full)
  35. y : year (four digits)
  36. yy : year (two digits)
  37. yyyy : year (with century)
  38. h : hour
  39. hh : hour (leading zero)
  40. n : minute
  41. nn : minute (leading zero)
  42. s : second
  43. ss : second (leading zero)
  44. t : shorttimeformat
  45. tt : longtimeformat
  46. am/pm : use 12 hour clock and display am and pm accordingly
  47. a/p : use 12 hour clock and display a and p accordingly
  48. / : insert date seperator
  49. : : insert time seperator
  50. "xx" : literal text
  51. 'xx' : literal text
  52. }
  53. Eoln = #10;
  54. type
  55. TSystemTime = record
  56. Year, Month, Day: word;
  57. Hour, Minute, Second, MilliSecond: word;
  58. end ;
  59. TDateTime = double;
  60. TTimeStamp = record
  61. Time: integer; { Number of milliseconds since midnight }
  62. Date: integer; { One plus number of days since 1/1/0001 }
  63. end ;
  64. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  65. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  66. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  67. function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  68. function EncodeDate(Year, Month, Day :word): TDateTime;
  69. function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  70. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  71. procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  72. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  73. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  74. function DayOfWeek(DateTime: TDateTime): integer;
  75. function Date: TDateTime;
  76. function Time: TDateTime;
  77. function Now: TDateTime;
  78. function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  79. function IsLeapYear(Year: Word): boolean;
  80. function DateToStr(Date: TDateTime): string;
  81. function TimeToStr(Time: TDateTime): string;
  82. function DateTimeToStr(DateTime: TDateTime): string;
  83. function StrToDate(const S: string): TDateTime;
  84. function StrToTime(const S: string): TDateTime;
  85. function StrToDateTime(const S: string): TDateTime;
  86. function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  87. procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  88. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  89. Function FileDateToDateTime (Filedate : Longint) : TDateTime;
  90. {
  91. $Log$
  92. Revision 1.6 2000-02-09 16:59:32 peter
  93. * truncated log
  94. }