2
*********************************************************************
3
$Id: datih.inc,v 1.2 2003/11/26 20:15:46 michael Exp $
4
Copyright (C) 1997, 1998 Gertjan Schouten
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*********************************************************************
21
System Utilities For Free Pascal
26
PDayTable = ^TDayTable;
27
TDayTable = array[1..12] of Word;
34
MinsPerDay = HoursPerDay * MinsPerHour;
35
SecsPerDay = MinsPerDay * SecsPerMin;
36
MSecsPerDay = SecsPerDay * MSecsPerSec;
38
DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
39
UnixDateDelta = 25569;
42
MonthDays: array [Boolean] of TDayTable =
43
((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
44
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
46
TwoDigitYearCenturyWindow : word= 50;
47
{ Threshold to be subtracted from year before
50
{ date time formatting characters:
51
c : shortdateformat + ' ' + shorttimeformat
53
dd : day of month (leading zero)
54
ddd : day of week (abbreviation)
55
dddd : day of week (full)
56
ddddd : shortdateformat
57
dddddd : longdateformat
59
mm : month (leading zero)
60
mmm : month (abbreviation)
62
y : year (four digits)
63
yy : year (two digits)
64
yyyy : year (with century)
66
hh : hour (leading zero)
68
nn : minute (leading zero)
70
ss : second (leading zero)
73
am/pm : use 12 hour clock and display am and pm accordingly
74
a/p : use 12 hour clock and display a and p accordingly
75
/ : insert date seperator
76
: : insert time seperator
83
{ Win32 reuses the struct from the Windows unit }
85
Year, Month, Day: word;
86
Hour, Minute, Second, MilliSecond: word;
91
Time: integer; { Number of milliseconds since midnight }
92
Date: integer; { One plus number of days since 1/1/0001 }
96
function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
97
function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
98
function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
99
function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
100
function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
101
function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
102
function EncodeDate(Year, Month, Day :word): TDateTime;
103
function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
104
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
105
function DecodeDateFully(const DateTime: TDateTime; var Year, Month, Day, DOW: Word): Boolean;
106
procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
107
procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
108
function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
109
function DayOfWeek(DateTime: TDateTime): integer;
110
function Date: TDateTime;
111
function Time: TDateTime;
112
function Now: TDateTime;
113
function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
114
function IsLeapYear(Year: Word): boolean;
115
function DateToStr(Date: TDateTime): string;
116
function TimeToStr(Time: TDateTime): string;
117
function DateTimeToStr(DateTime: TDateTime): string;
118
function StrToDate(const S: string): TDateTime;
119
function StrToTime(const S: string): TDateTime;
120
function StrToDateTime(const S: string): TDateTime;
121
function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
122
procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
123
Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
124
Function FileDateToDateTime (Filedate : Longint) :TDateTime;
127
Procedure GetLocalTime(var SystemTime: TSystemTime);
131
Revision 1.2 2003/11/26 20:15:46 michael
132
TwoDigitYearCenturyWindow is 50
134
Revision 1.1 2003/10/06 21:01:06 peter
135
* moved classes unit to rtl
137
Revision 1.8 2003/01/18 23:45:37 michael
138
+ Fixed EncodeDate/Time so they use TryEncodeDate/Time
140
Revision 1.7 2002/12/25 01:03:48 peter
141
* some date constants added
143
Revision 1.6 2002/10/02 21:04:06 peter
144
* For win32 use the tsystemtime from the windows unit, that is changed
145
to a variant record with compatibile field names
147
Revision 1.5 2002/09/07 16:01:22 peter
148
* old logs removed and tabs fixed