dati.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. {==============================================================================}
  20. { internal functions }
  21. {==============================================================================}
  22. const
  23. DayTable: array[Boolean, 1..12] of longint =
  24. ((0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
  25. (0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335));
  26. function DoEncodeDate(Year, Month, Day: Word): longint;
  27. var
  28. c, ya: cardinal;
  29. begin
  30. if (Month > 0) and (Month < 13) and (Day > 0) and (Day < 32) then
  31. begin
  32. if month > 2 then Month := Month - 3 else
  33. begin
  34. Month := Month + 9;
  35. Year:= Year - 1;
  36. end;
  37. c:= Year DIV 100;
  38. ya:= Year - 100*c;
  39. result := (146097*c) SHR 2 + (1461*ya) SHR 2 + (153*Month+2) DIV 5 + Day -
  40. 693900;
  41. end else result:=0;
  42. end;
  43. function DoEncodeTime(Hour, Minute, Second, MilliSecond: word): longint;
  44. begin
  45. If ((hour>=0) and (Hour<24)) and
  46. ((Minute>=0) and (Minute<60)) and
  47. ((Second>=0) and (Second<60)) and
  48. ((MilliSecond>=0) and (Millisecond<1000)) then
  49. Result := (Hour * 3600000 + Minute * 60000 + Second * 1000 + MilliSecond)
  50. else
  51. Result:=0;
  52. end ;
  53. {==============================================================================}
  54. { Public functions }
  55. {==============================================================================}
  56. { DateTimeToTimeStamp converts DateTime to a TTimeStamp }
  57. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  58. begin
  59. result.Time := Trunc(Frac(DateTime) * MSecsPerDay);
  60. result.Date := 1
  61. + DateDelta
  62. + Trunc(System.Int(DateTime));
  63. end ;
  64. { TimeStampToDateTime converts TimeStamp to a TDateTime value }
  65. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  66. begin
  67. result := (TimeStamp.Date - DateDelta - 1) + (TimeStamp.Time / MSecsPerDay);
  68. end ;
  69. { MSecsToTimeStamp }
  70. function MSecsToTimeStamp(MSecs: comp): TTimeStamp;
  71. begin
  72. result.Date := trunc(msecs / msecsperday);
  73. msecs:= msecs - comp(result.date) * comp(msecsperday);
  74. result.Time := Trunc(MSecs);
  75. end ;
  76. { TimeStampToMSecs }
  77. function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  78. begin
  79. result := TimeStamp.Time + timestamp.date*msecsperday;
  80. end ;
  81. { EncodeDate packs three variables Year, Month and Day into a
  82. TDateTime value the result is the number of days since 12/30/1899 }
  83. function EncodeDate(Year, Month, Day: word): TDateTime;
  84. begin
  85. result := DoEncodeDate(Year, Month, Day);
  86. end ;
  87. { EncodeTime packs four variables Hour, Minute, Second and MilliSecond into
  88. a TDateTime value }
  89. function EncodeTime(Hour, Minute, Second, MilliSecond:word):TDateTime;
  90. begin
  91. Result := DoEncodeTime(hour, minute, second, millisecond) / MSecsPerDay;
  92. end ;
  93. { DecodeDate unpacks the value Date into three values:
  94. Year, Month and Day }
  95. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  96. var
  97. j : cardinal;
  98. begin
  99. j := pred((Trunc(System.Int(Date)) + 693900) SHL 2);
  100. Year:= j DIV 146097;
  101. j:= j - 146097 * Year;
  102. Day := j SHR 2;
  103. j:=(Day SHL 2 + 3) DIV 1461;
  104. Day:= (Day SHL 2 + 7 - 1461*j) SHR 2;
  105. Month:=(5 * Day-3) DIV 153;
  106. Day:= (5 * Day +2 - 153*Month) DIV 5;
  107. Year:= 100 * Year + j;
  108. if Month < 10 then Month:= Month + 3 else begin
  109. Month:= Month-9;
  110. inc(Year);
  111. end;
  112. end ;
  113. { DecodeTime unpacks Time into four values:
  114. Hour, Minute, Second and MilliSecond }
  115. procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  116. Var
  117. l : cardinal;
  118. begin
  119. l := Trunc(Frac(time) * MSecsPerDay);
  120. Hour := l div 3600000;
  121. l := l mod 3600000;
  122. Minute := l div 60000;
  123. l := l mod 60000;
  124. Second := l div 1000;
  125. l := l mod 1000;
  126. MilliSecond := l;
  127. end;
  128. { DateTimeToSystemTime converts DateTime value to SystemTime }
  129. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  130. begin
  131. DecodeDate(DateTime, SystemTime.Year, SystemTime.Month, SystemTime.Day);
  132. DecodeTime(DateTime, SystemTime.Hour, SystemTime.Minute, SystemTime.Second, SystemTime.MilliSecond);
  133. end ;
  134. { SystemTimeToDateTime converts SystemTime to a TDateTime value }
  135. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  136. begin
  137. result := DoEncodeDate(SystemTime.Year,
  138. SystemTime.Month,
  139. SystemTime.Day) +
  140. DoEncodeTime(SystemTime.Hour,
  141. SystemTime.Minute,
  142. SystemTime.Second,
  143. SystemTime.MilliSecond) / MSecsPerDay;
  144. end ;
  145. { DayOfWeek returns the Day of the week (sunday is day 1) }
  146. function DayOfWeek(DateTime: TDateTime): integer;
  147. begin
  148. Result := 1 + (Abs(Trunc(DateTime) - 1) mod 7);
  149. end ;
  150. { Date returns the current Date }
  151. function Date: TDateTime;
  152. var SystemTime: TSystemTime;
  153. begin
  154. GetLocalTime(SystemTime);
  155. result := DoEncodeDate(SystemTime.Year,
  156. SystemTime.Month,
  157. SystemTime.Day);
  158. end ;
  159. { Time returns the current Time }
  160. function Time: TDateTime;
  161. var SystemTime: TSystemTime;
  162. begin
  163. GetLocalTime(SystemTime);
  164. Result := DoEncodeTime(SystemTime.Hour,
  165. SystemTime.Minute,
  166. SystemTime.Second,
  167. SystemTime.MilliSecond) / MSecsPerDay;
  168. end ;
  169. { Now returns the current Date and Time }
  170. function Now: TDateTime;
  171. var SystemTime: TSystemTime;
  172. begin
  173. GetLocalTime(SystemTime);
  174. result := DoEncodeDate(SystemTime.Year,
  175. SystemTime.Month,
  176. SystemTime.Day) +
  177. DoEncodeTime(SystemTime.Hour,
  178. SystemTime.Minute,
  179. SystemTime.Second,
  180. SystemTime.MilliSecond) / MSecsPerDay;
  181. end ;
  182. { IncMonth increments DateTime with NumberOfMonths months,
  183. NumberOfMonths can be less than zero }
  184. function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  185. var Year, Month, Day: word;
  186. S : Integer;
  187. begin
  188. If NumberOfMonths>=0 then s:=1 else s:=-1;
  189. DecodeDate(DateTime, Year, Month, Day);
  190. Year := Year + (NumberOfMonths div 12);
  191. Month := Month + (NumberOfMonths mod 12)-1 ; // Mod result always positive
  192. if Month>11 then begin
  193. Dec(Month, S*12);
  194. Inc(Year, S);
  195. end ;
  196. Inc(Month, 1); { Months from 1 to 12 }
  197. if (Month = 2) and (IsLeapYear(Year)) and (Day > 28) then
  198. Day := 28;
  199. result := Frac(DateTime) + DoEncodeDate(Year, Month, Day);
  200. end ;
  201. { IsLeapYear returns true if Year is a leap year }
  202. function IsLeapYear(Year: Word): boolean;
  203. begin
  204. Result := (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0));
  205. end;
  206. { DateToStr returns a string representation of Date using ShortDateFormat }
  207. function DateToStr(Date: TDateTime): string;
  208. begin
  209. result := FormatDateTime('ddddd', Date);
  210. end ;
  211. { TimeToStr returns a string representation of Time using ShortTimeFormat }
  212. function TimeToStr(Time: TDateTime): string;
  213. begin
  214. result := FormatDateTime('t', Time);
  215. end ;
  216. { DateTimeToStr returns a string representation of DateTime using ShortDateTimeFormat }
  217. function DateTimeToStr(DateTime: TDateTime): string;
  218. begin
  219. result := FormatDateTime('c', DateTime);
  220. end ;
  221. { StrToDate converts the string S to a TDateTime value
  222. if S does not represent a valid date value
  223. an EConvertError will be raised }
  224. function StrToDate(const S: string): TDateTime;
  225. var
  226. df:string;
  227. d,m,y:word;
  228. n,i:longint;
  229. c:word;
  230. dp,mp,yp,which : Byte;
  231. s1:string[4];
  232. values:array[1..3] of longint;
  233. LocalTime:tsystemtime;
  234. begin
  235. df := UpperCase(ShortDateFormat);
  236. { Determine order of D,M,Y }
  237. yp:=0;
  238. mp:=0;
  239. dp:=0;
  240. Which:=0;
  241. i:=0;
  242. while (i<Length(df)) and (Which<3) do
  243. begin
  244. inc(i);
  245. Case df[i] of
  246. 'Y' :
  247. if yp=0 then
  248. begin
  249. Inc(Which);
  250. yp:=which;
  251. end;
  252. 'M' :
  253. if mp=0 then
  254. begin
  255. Inc(Which);
  256. mp:=which;
  257. end;
  258. 'D' :
  259. if dp=0 then
  260. begin
  261. Inc(Which);
  262. dp:=which;
  263. end;
  264. end;
  265. end;
  266. if Which<>3 then
  267. Raise EConvertError.Create('Illegal format string');
  268. { Get actual values }
  269. for i := 1 to 3 do
  270. values[i] := 0;
  271. s1 := '';
  272. n := 0;
  273. for i := 1 to length(s) do
  274. begin
  275. if (s[i] in ['0'..'9']) then
  276. s1 := s1 + s[i];
  277. if (s[i] in [dateseparator,' ']) or (i = length(s)) then
  278. begin
  279. inc(n);
  280. if n>3 then
  281. Raise EConvertError.Create('Invalid date format');
  282. val(s1, values[n], c);
  283. if c<>0 then
  284. Raise EConvertError.Create('Invalid date format');
  285. s1 := '';
  286. end ;
  287. end ;
  288. // Fill in values.
  289. If N=3 then
  290. begin
  291. y:=values[yp];
  292. m:=values[mp];
  293. d:=values[dp];
  294. end
  295. Else
  296. begin
  297. getLocalTime(LocalTime);
  298. y := LocalTime.Year;
  299. If n<2 then
  300. begin
  301. d:=values[1];
  302. m := LocalTime.Month;
  303. end
  304. else
  305. If dp<mp then
  306. begin
  307. d:=values[1];
  308. m:=values[2];
  309. end
  310. else
  311. begin
  312. d:=values[2];
  313. m:=values[1];
  314. end;
  315. end;
  316. if (y >= 0) and (y < 100) then
  317. inc(y,1900);
  318. Result := DoEncodeDate(y, m, d);
  319. end ;
  320. { StrToTime converts the string S to a TDateTime value
  321. if S does not represent a valid time value an
  322. EConvertError will be raised }
  323. function StrToTime(const s: string): TDateTime;
  324. var
  325. Len, Current: integer; PM: boolean;
  326. function GetElement: integer;
  327. var
  328. j: integer; c: word;
  329. begin
  330. result := -1;
  331. Inc(Current);
  332. while (result = -1) and (Current < Len) do begin
  333. if S[Current] in ['0'..'9'] then begin
  334. j := Current;
  335. while (Current < Len) and (s[Current + 1] in ['0'..'9']) do
  336. Inc(Current);
  337. val(copy(S, j, 1 + Current - j), result, c);
  338. end
  339. else if (S[Current] = TimeAMString[1]) or (S[Current] in ['a', 'A']) then begin
  340. Current := 1 + Len;
  341. end
  342. else if (S[Current] = TimePMString[1]) or (S[Current] in ['p', 'P']) then begin
  343. Current := 1 + Len;
  344. PM := True;
  345. end
  346. else if (S[Current] = TimeSeparator) or (S[Current] = ' ') then
  347. Inc(Current)
  348. else
  349. raise EConvertError.Create('Invalid Time format');
  350. end ;
  351. end ;
  352. var
  353. i: integer;
  354. TimeValues: array[0..4] of integer;
  355. begin
  356. Current := 0;
  357. Len := length(s);
  358. PM := False;
  359. for i:=0 to 4 do
  360. timevalues[i]:=0;
  361. i := 0;
  362. TimeValues[i] := GetElement;
  363. while (i < 5) and (TimeValues[i] <> -1) do begin
  364. i := i + 1;
  365. TimeValues[i] := GetElement;
  366. end ;
  367. If (i<5) and (TimeValues[I]=-1) then
  368. TimeValues[I]:=0;
  369. if PM then Inc(TimeValues[0], 12);
  370. result := EncodeTime(TimeValues[0], TimeValues[1], TimeValues[2], TimeValues[3]);
  371. end ;
  372. { StrToDateTime converts the string S to a TDateTime value
  373. if S does not represent a valid date and time value
  374. an EConvertError will be raised }
  375. function StrToDateTime(const s: string): TDateTime;
  376. var i: integer;
  377. begin
  378. i := pos(' ', s);
  379. if i > 0 then result := StrToDate(Copy(S, 1, i - 1)) + StrToTime(Copy(S, i + 1, length(S)))
  380. else result := StrToDate(S);
  381. end ;
  382. { FormatDateTime formats DateTime to the given format string FormatStr }
  383. function FormatDateTime(FormatStr: string; DateTime: TDateTime): string;
  384. var
  385. ResultLen: integer;
  386. ResultBuffer: array[0..255] of char;
  387. ResultCurrent: pchar;
  388. procedure StoreStr(Str: pchar; Len: integer);
  389. begin
  390. if ResultLen + Len < SizeOf(ResultBuffer) then begin
  391. StrMove(ResultCurrent, Str, Len);
  392. ResultCurrent := ResultCurrent + Len;
  393. ResultLen := ResultLen + Len;
  394. end ;
  395. end ;
  396. procedure StoreString(const Str: string);
  397. var Len: integer;
  398. begin
  399. Len := Length(Str);
  400. if ResultLen + Len < SizeOf(ResultBuffer) then begin
  401. StrMove(ResultCurrent, pchar(Str), Len);
  402. ResultCurrent := ResultCurrent + Len;
  403. ResultLen := ResultLen + Len;
  404. end;
  405. end;
  406. procedure StoreInt(Value, Digits: integer);
  407. var S: string; Len: integer;
  408. begin
  409. S := IntToStr(Value);
  410. Len := Length(S);
  411. if Len < Digits then begin
  412. S := copy('0000', 1, Digits - Len) + S;
  413. Len := Digits;
  414. end ;
  415. StoreStr(pchar(@S[1]), Len);
  416. end ;
  417. Function TimeReFormat(Const S : string) : string;
  418. // Change m into n for time formatting.
  419. Var i : longint;
  420. begin
  421. Result:=S;
  422. For I:=1 to Length(Result) do
  423. If Result[i]='m' then
  424. result[i]:='n';
  425. end;
  426. var
  427. Year, Month, Day, DayOfWeek, Hour, Minute, Second, MilliSecond: word;
  428. procedure StoreFormat(const FormatStr: string);
  429. var
  430. Token: char;
  431. FormatCurrent: pchar;
  432. FormatEnd: pchar;
  433. Count: integer;
  434. Clock12: boolean;
  435. P: pchar;
  436. begin
  437. FormatCurrent := Pchar(FormatStr);
  438. FormatEnd := FormatCurrent + Length(FormatStr);
  439. Clock12 := false;
  440. P := FormatCurrent;
  441. while P < FormatEnd do begin
  442. Token := UpCase(P^);
  443. if Token in ['"', ''''] then begin
  444. P := P + 1;
  445. while (P < FormatEnd) and (P^ <> Token) do
  446. P := P + 1;
  447. end
  448. else if Token = 'A' then begin
  449. if (StrLIComp(P, 'A/P', 3) = 0) or
  450. (StrLIComp(P, 'AMPM', 4) = 0) or
  451. (StrLIComp(P, 'AM/PM', 5) = 0) then begin
  452. Clock12 := true;
  453. break;
  454. end ;
  455. end ;
  456. P := P + 1;
  457. end ;
  458. while FormatCurrent < FormatEnd do begin
  459. Token := UpCase(FormatCurrent^);
  460. Count := 1;
  461. P := FormatCurrent + 1;
  462. case Token of
  463. '''', '"': begin
  464. while (P < FormatEnd) and (p^ <> Token) do
  465. P := P + 1;
  466. P := P + 1;
  467. Count := P - FormatCurrent;
  468. StoreStr(FormatCurrent + 1, Count - 2);
  469. end ;
  470. 'A': begin
  471. if StrLIComp(FormatCurrent, 'AMPM', 4) = 0 then begin
  472. Count := 4;
  473. if Hour < 12 then StoreString(TimeAMString)
  474. else StoreString(TimePMString);
  475. end
  476. else if StrLIComp(FormatCurrent, 'AM/PM', 5) = 0 then begin
  477. Count := 5;
  478. if Hour < 12 then StoreStr('am', 2)
  479. else StoreStr('pm', 2);
  480. end
  481. else if StrLIComp(FormatCurrent, 'A/P', 3) = 0 then begin
  482. Count := 3;
  483. if Hour < 12 then StoreStr('a', 1)
  484. else StoreStr('p', 1);
  485. end
  486. else
  487. Raise EConvertError.Create('Illegal character in format string');
  488. end ;
  489. '/': StoreStr(@DateSeparator, 1);
  490. ':': StoreStr(@TimeSeparator, 1);
  491. ' ', 'C', 'D', 'H', 'M', 'N', 'S', 'T', 'Y': begin
  492. while (P < FormatEnd) and (UpCase(P^) = Token) do
  493. P := P + 1;
  494. Count := P - FormatCurrent;
  495. case Token of
  496. ' ': StoreStr(FormatCurrent, Count);
  497. 'Y': begin
  498. case Count of
  499. 1: StoreInt(Year, 0);
  500. 2: StoreInt(Year mod 100, 2);
  501. 4: StoreInt(Year, 4);
  502. end ;
  503. end ;
  504. 'M': begin
  505. case Count of
  506. 1: StoreInt(Month, 0);
  507. 2: StoreInt(Month, 2);
  508. 3: StoreString(ShortMonthNames[Month]);
  509. 4: StoreString(LongMonthNames[Month]);
  510. end ;
  511. end ;
  512. 'D': begin
  513. case Count of
  514. 1: StoreInt(Day, 0);
  515. 2: StoreInt(Day, 2);
  516. 3: StoreString(ShortDayNames[DayOfWeek]);
  517. 4: StoreString(LongDayNames[DayOfWeek]);
  518. 5: StoreFormat(ShortDateFormat);
  519. 6: StoreFormat(LongDateFormat);
  520. end ;
  521. end ;
  522. 'H': begin
  523. if Clock12 then begin
  524. if Count = 1 then StoreInt(Hour mod 12, 0)
  525. else StoreInt(Hour mod 12, 2);
  526. end
  527. else begin
  528. if Count = 1 then StoreInt(Hour, 0)
  529. else StoreInt(Hour, 2);
  530. end ;
  531. end ;
  532. 'N': begin
  533. if Count = 1 then StoreInt(Minute, 0)
  534. else StoreInt(Minute, 2);
  535. end ;
  536. 'S': begin
  537. if Count = 1 then StoreInt(Second, 0)
  538. else StoreInt(Second, 2);
  539. end ;
  540. 'T': begin
  541. if Count = 1 then StoreFormat(timereformat(ShortTimeFormat))
  542. else StoreFormat(TimeReformat(LongTimeFormat));
  543. end ;
  544. 'C':
  545. begin
  546. StoreFormat(ShortDateFormat);
  547. if (Hour<>0) or (Minute<>0) or (Second<>0) then
  548. begin
  549. StoreString(' ');
  550. StoreFormat(TimeReformat(ShortTimeFormat));
  551. end;
  552. end;
  553. end ;
  554. end ;
  555. else
  556. StoreStr(@Token, 1);
  557. end ;
  558. FormatCurrent := FormatCurrent + Count;
  559. end ;
  560. end ;
  561. begin
  562. DecodeDate(DateTime, Year, Month, Day);
  563. DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
  564. DayOfWeek := SysUtils.DayOfWeek(DateTime);
  565. ResultLen := 0;
  566. ResultCurrent := @ResultBuffer;
  567. StoreFormat(FormatStr);
  568. ResultBuffer[ResultLen] := #0;
  569. result := StrPas(@ResultBuffer);
  570. end ;
  571. { DateTimeToString formats DateTime to the given format in FormatStr }
  572. procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  573. begin
  574. Result := FormatDateTime(FormatStr, DateTime);
  575. end ;
  576. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  577. Var YY,MM,DD,H,m,s,msec : Word;
  578. begin
  579. Decodedate (DateTime,YY,MM,DD);
  580. If (YY<1980) or (YY>2099) then
  581. Result:=0
  582. else
  583. begin
  584. DecodeTime (DateTime,h,m,s,msec);
  585. Result:=(s shr 1) or (m shl 5) or (h shl 11);
  586. Result:=Result or DD shl 16 or (MM shl 21) or ((YY-1980) shl 25);
  587. end;
  588. end;
  589. Function FileDateToDateTime (Filedate : Longint) : TDateTime;
  590. Var Date,Time : Word;
  591. begin
  592. Date:=FileDate shr 16;
  593. Time:=FileDate and $ffff;
  594. Result:=EncodeDate((Date shr 9) + 1980,(Date shr 5) and 15, Date and 31) +
  595. EncodeTime(Time shr 11, (Time shr 5) and 63, (Time and 31) shl 1,0);
  596. end;
  597. {
  598. $Log$
  599. Revision 1.20 2000-02-09 16:59:32 peter
  600. * truncated log
  601. Revision 1.19 1999/11/29 16:59:27 pierre
  602. * fix for form bug 719
  603. Revision 1.18 1999/11/06 14:41:30 peter
  604. * truncated log
  605. Revision 1.17 1999/10/28 09:52:29 peter
  606. * fixed dayofweek
  607. Revision 1.16 1999/08/11 21:53:04 peter
  608. * fixed formatdatetime('c',...)
  609. * fixed strtodate
  610. * dateencode/decode is now delphi compatible
  611. Revision 1.15 1999/07/24 11:21:14 peter
  612. * fixed encode/decode date/time
  613. }