📄 dateutils.pas
字号:
//******************************************************************//
// Project ADVmserve //
// //
// Module DateUtils (standard unit in Delphi 6) //
// //
// Description Implements aTWSocket-based SMTP server component. //
// For further details please see //
// RFC-821, RFC-1869, RFC-1870, RFC-1893, RFC-1985, //
// RFC-2034, RFC-2025, RFC-2920 //
// //
// TWsocket is a component of The Internet Component //
// Suite, freely downloadable from //
// http://www.overbyte.be //
// //
// Copyright This software is subject to the license at: //
// http://www.codecutters.org/software/license.html //
// with the additional conditions below: //
// //
// (i) This source code is "Open Source" //
// (ii) This source code may be freely distributed & //
// modified, but it's origin must not be //
// misrepresented in any way. This means that //
// this this header must remain intact, with //
// altered portions clearly marked and commented //
// (iii) This source code may be used in any project, //
// including commercial software; a mention of //
// ADVsystems and a link to the web site would //
// be appreciated, but is not mandatory. //
// (iv) As stated in the license terms, the author //
// accepts no responsibility for damages or costs//
// arising from the use or misuse of this //
// software; the software is supplied "as-is", //
// and no claims are made to its merchantability //
// or fitness for a given purpose. //
//******************************************************************//
// (C) ADV Systems 2003, All rights reserved. //
//******************************************************************//
// Version Date Author Reason //
// 1.00 290303 I.Baker Required for Delphi versions prior to //
// Delphi 6 (as reported by Arno Garrels) //
//******************************************************************//
unit DateUtils;
interface
uses SysUtils, Controls;
// General D6 routines
function ANSIindexText(const AText: string; const AValues: array of string): Integer;
function ANSIreplaceText(const AText, AFromText, AToText: string): string;
// D6 date routines
function SecondsBetween(ANow,AThen : TDateTime) : integer;
function YearOf(ANow : TDateTime) : word;
function MilliSecondOfTheYear(ANow : TDateTime) : Int64;
implementation
function ANSIindexText(const AText: string; const AValues: array of string): Integer;
begin
Result := High(AValues);
while (Result >= Low(AValues)) and not(SameText(AText,AValues[Result])) do
Dec(Result);
end;
function ANSIreplaceText(const AText, AFromText, AToText: string): string;
begin
Result := StringReplace(AText,AFromText,AToText,[rfReplaceAll]);
end;
function SecondsBetween(ANow,AThen : TDateTime) : integer;
begin
Result := TRUNC(ABS(AThen-ANow)*24*60*60);
end;
function YearOf(ANow : TDateTime) : word;
var
Month,
Day : word;
begin
// Strange but true - DecodeDateTime is in DateUtils in D6!
DecodeDate(ANow,Result,Month,Day);
end;
function MilliSecondOfTheYear(ANow : TDateTime) : Int64;
const
DaysInMonth : array[1..12] of byte
= (31,28,31,30,31,30,31,31,30,31,30,31);
PerDay = 24*60*60*1000;
var
Year,
Month,
Day : word;
i : integer;
begin
DecodeDate(ANow,Year,Month,Day);
for i := 1 to PRED(Month) do
Day := Day + DaysInMonth[i];
if (Month > 2) and IsLeapYear(Year) then
Inc(Day);
Result := Day*PerDay + (TRUNC(FRAC(ANow)*PerDay) mod PerDay);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -