datih.inc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. DateSeparator: char = '-';
  24. TimeSeparator: char = ':';
  25. TimeAMString: string = 'am';
  26. TimePMString: string = 'pm';
  27. ShortMonthNames: array[1..12] of string =
  28. ('Jan','Feb','Mar','Apr','May','Jun',
  29. 'Jul','Aug','Sep','Oct','Nov','Dec');
  30. LongMonthNames: array[1..12] of string =
  31. ('January','February','March','April','May','June',
  32. 'July','August','September','October','November','December');
  33. ShortDayNames: array[1..7] of string =
  34. ('Sun','Mon','Tue','Wen','Thu','Fri','Sat');
  35. LongDayNames: array[1..7] of string =
  36. ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  37. { date time formatting characters:
  38. c : shortdateformat + ' ' + shorttimeformat
  39. d : day of month
  40. dd : day of month (leading zero)
  41. ddd : day of week (abbreviation)
  42. dddd : day of week (full)
  43. ddddd : shortdateformat
  44. dddddd : longdateformat
  45. m : month
  46. mm : month (leading zero)
  47. mmm : month (abbreviation)
  48. mmmm : month (full)
  49. y : year (four digits)
  50. yy : year (two digits)
  51. yyyy : year (with century)
  52. h : hour
  53. hh : hour (leading zero)
  54. n : minute
  55. nn : minute (leading zero)
  56. s : second
  57. ss : second (leading zero)
  58. t : shorttimeformat
  59. tt : longtimeformat
  60. am/pm : use 12 hour clock and display am and pm accordingly
  61. a/p : use 12 hour clock and display a and p accordingly
  62. / : insert date seperator
  63. : : insert time seperator
  64. "xx" : literal text
  65. 'xx' : literal text
  66. }
  67. ShortDateFormat: string = 'd/m/y';
  68. LongDateFormat: string = 'dd" "mmmm" "yyyy';
  69. ShortTimeFormat: string = 'hh:nn';
  70. LongTimeFormat: string = 'hh:nn:ss';
  71. Eoln = #10;
  72. type
  73. TSystemTime = record
  74. Year, Month, Day: word;
  75. Hour, Minute, Second, MilliSecond: word;
  76. end ;
  77. TDateTime = double;
  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 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. procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  90. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  91. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  92. function DayOfWeek(DateTime: TDateTime): integer;
  93. function Date: TDateTime;
  94. function Time: TDateTime;
  95. function Now: TDateTime;
  96. function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  97. function IsLeapYear(Year: Word): boolean;
  98. function DateToStr(Date: TDateTime): string;
  99. function TimeToStr(Time: TDateTime): string;
  100. function DateTimeToStr(DateTime: TDateTime): string;
  101. function StrToDate(const S: string): TDateTime;
  102. function StrToTime(const S: string): TDateTime;
  103. function StrToDateTime(const S: string): TDateTime;
  104. function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  105. procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  106. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  107. Function FileDateToDateTime (Filedate : Longint) : TDateTime;
  108. {
  109. $Log$
  110. Revision 1.4 1998-10-11 13:40:53 michael
  111. + Added Conversion TDateTime <-> file date and time
  112. Revision 1.3 1998/10/08 14:07:45 florian
  113. * date and day names fixed
  114. Revision 1.2 1998/09/16 08:28:37 michael
  115. Update from gertjan Schouten, plus small fix for linux
  116. Revision 1.1 1998/04/10 15:17:46 michael
  117. + Initial implementation; Donated by Gertjan Schouten
  118. His file was split into several files, to keep it a little bit structured.
  119. }