-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkn_DateTime.pas
204 lines (164 loc) · 5.37 KB
/
kn_DateTime.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
unit kn_DateTime;
(* ************************************************************
KEYNOTE: MOZILLA PUBLIC LICENSE STATEMENT.
-----------------------------------------------------------
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is KeyNote 1.0.
The Initial Developer of the Original Code is Marek Jedlinski
<eristic@lodz.pdi.net> (Poland).
Portions created by Marek Jedlinski are
Copyright (C) 2000-2003. All Rights Reserved.
-----------------------------------------------------------
Contributor(s):
-----------------------------------------------------------
History:
-----------------------------------------------------------
Released: 30 June 2001
-----------------------------------------------------------
URLs:
- for OpenSource development:
http://keynote.sourceforge.net
- original author's software site:
http://www.lodz.pdi.net/~eristic/free/index.html
http://go.to/generalfrenetics
Email addresses (at least one should be valid)
<eristic@lodz.pdi.net>
<cicho@polbox.com>
<cicho@tenbit.pl>
************************************************************ *)
interface
uses Windows, Classes, SysUtils, gf_misc;
const
_DTFORMAT_COMMENT_CHAR = '#';
_ENGLISH_DATE_PREFIX_CHAR = '@';
_DateFormatsFile = 'dateformats.txt';
_TimeFormatsFile = 'timeformats.txt';
_MAX_DATE_FORMATS = 25;
_MAX_TIME_FORMATS = 9;
{
TIME_FORMAT_LIST : array[1..MAX_TIME_FORMATS] of string = (
'k', // time in KeyNote default format
't', // time in ShortTimeFormat
'tt', // time in LongTimeFormat
'hh:mm',
'hh:mm:ss',
'hh:mm ampm', // time with system default am/pm specifier
'hh:mm:ss ampm',
'hh:mm am/pm', // time with am/pm specifier
'hh:mm:ss am/pm'
);
}
{
DATE_FORMAT_LIST : array[1..MAX_DATE_FORMATS] of string = (
'k', // date in KeyNote default format
'ddddd',
'dddddd',
'c',
'dd-MM-yy',
'dd-MM-yyyy',
'dddd, dd mmmm yyyy',
'dd mmmm yyyy (dddd)',
'dd mmmm yyyy',
'dd mmmm, yyyy',
'yy/mm/dd',
'yyyy/mm/dd',
'mmmm, dd',
'mmmm dd, yyyy',
'dd mmmm',
'dd/mmm/yy',
'dd/mmm/yyyy',
'dd/mm/yyyy hh:mm',
'dd/mm/yyyy hh:mm:ss',
'dd mmm yyyy hh:mm',
'dd mmm yyyy hh:mm:ss',
'dd mmmm yyyy hh:mm',
'dd mmmm yyyy hh:mm:ss',
'dddd, dd mmmm yyyy hh:mm',
'dddd, dd mmmm yyyy hh:mm:ss'
);
}
var
DATE_FORMAT_LIST : TStringList;
TIME_FORMAT_LIST : TStringList;
function LoadDateFormatsList : boolean;
function LoadTimeFormatsList : boolean;
function GetDateTimeFormatted( fmtstr : string; const DT : TDateTime ) : WideString;
implementation
function GetDateTimeFormatted( fmtstr : string; const DT : TDateTime ) : WideString;
begin
if ( fmtstr <> '' ) and ( fmtstr[1] = _ENGLISH_DATE_PREFIX_CHAR ) then
begin
delete( fmtstr, 1, 1 );
result := FormatDateTimeEnglish( fmtstr, DT );
end
else
result := FormatDateTime( fmtstr, DT );
end; // GetDateTimeFormatted
function LoadFormatFile( const fn : string; List : TStrings; MaxCount : integer ) : boolean;
var
i : integer;
s : string;
f : textfile;
begin
result := false;
if ( not fileexists( fn )) then exit;
assignfile( f, fn );
try
reset( f );
try
while ( not eof( f )) and ( List.Count < MaxCount ) do
begin
readln( f, s );
s := trim( s );
if ( s = '' ) then continue;
case s[1] of
_DTFORMAT_COMMENT_CHAR : continue;
else
List.Add( s );
end;
end;
result := true;
finally
closefile( f );
end;
except
result := false;
end;
end; // LoadFormatFile
function LoadDateFormatsList : boolean;
var
cnt, i : integer;
begin
DATE_FORMAT_LIST.Clear;
DATE_FORMAT_LIST.Add( 'k' ); // date in KeyNote default format
DATE_FORMAT_LIST.Add( 'ddddd' ); // system default short date format
DATE_FORMAT_LIST.Add( 'dddddd' ); // system default long date format
DATE_FORMAT_LIST.Add( 'c' ); // short date format + short time format
result := LoadFormatFile( extractfilepath( ParamStr( 0 )) + _DateFormatsFile, DATE_FORMAT_LIST, _MAX_DATE_FORMATS );
end; // LoadDateFormatsList
function LoadTimeFormatsList : boolean;
var
cnt, i : integer;
begin
TIME_FORMAT_LIST.Clear;
TIME_FORMAT_LIST.Add( 'k' ); // KeyNote default
TIME_FORMAT_LIST.Add( 't' ); // system default short time format
TIME_FORMAT_LIST.Add( 'tt' ); // system default long time format
result := LoadFormatFile( extractfilepath( ParamStr( 0 )) + _TimeFormatsFile, TIME_FORMAT_LIST, _MAX_TIME_FORMATS );
end; // LoadTimeFormatsList
Initialization
TIME_FORMAT_LIST := TStringList.Create;
DATE_FORMAT_LIST := TStringList.Create;
LoadDateFormatsList;
LoadTimeFormatsList;
Finalization
TIME_FORMAT_LIST.Free;
DATE_FORMAT_LIST.Free;
end.