⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dateutils.pp

📁 Lazarus is a free and open source development tool for the FreePascal Compiler. The purpose of the p
💻 PP
📖 第 1 页 / 共 4 页
字号:
end;Function DayOfTheMonth(const AValue: TDateTime): Word;Var  Y,M : Word;begin  DecodeDate(AValue,Y,M,Result);end;Function HourOfTheMonth(const AValue: TDateTime): Word;Var  Y,M,D,H,N,S,MS : Word;begin  DecodeDateTime(AValue,Y,M,D,H,N,S,MS);  Result:=(D-1)*24+H;end;Function MinuteOfTheMonth(const AValue: TDateTime): Word;Var  Y,M,D,H,N,S,MS : Word;begin  DecodeDateTime(AValue,Y,M,D,H,N,S,MS);  Result:=((D-1)*24+H)*60+N;end;Function SecondOfTheMonth(const AValue: TDateTime): LongWord;Var  Y,M,D,H,N,S,MS : Word;begin  DecodeDateTime(AValue,Y,M,D,H,N,S,MS);  Result:=(((D-1)*24+H)*60+N)*60+S;end;Function MilliSecondOfTheMonth(const AValue: TDateTime): LongWord;Var  Y,M,D,H,N,S,MS : Word;begin  DecodeDateTime(AValue,Y,M,D,H,N,S,MS);  Result:=((((D-1)*24+H)*60+N)*60+S)*1000+MS;end;{ ---------------------------------------------------------------------    Part of week functions.  ---------------------------------------------------------------------}Function DayOfTheWeek(const AValue: TDateTime): Word;begin  Result:=DowMAP[DayOfWeek(AValue)];end;Function HourOfTheWeek(const AValue: TDateTime): Word;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=(DayOfTheWeek(AValue)-1)*24+H;end;Function MinuteOfTheWeek(const AValue: TDateTime): Word;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=((DayOfTheWeek(AValue)-1)*24+H)*60+M;end;Function SecondOfTheWeek(const AValue: TDateTime): LongWord;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=(((DayOfTheWeek(AValue)-1)*24+H)*60+M)*60+S;end;Function MilliSecondOfTheWeek(const AValue: TDateTime): LongWord;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=((((DayOfTheWeek(AValue)-1)*24+H)*60+M)*60+S)*1000+MS;end;{ ---------------------------------------------------------------------    Part of day functions.  ---------------------------------------------------------------------}Function HourOfTheDay(const AValue: TDateTime): Word;Var  M,S,MS : Word;begin  DecodeTime(AValue,Result,M,S,MS);end;Function MinuteOfTheDay(const AValue: TDateTime): Word;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=(H*60)+M;end;Function SecondOfTheDay(const AValue: TDateTime): LongWord;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=((H*60)+M)*60+S;end;Function MilliSecondOfTheDay(const AValue: TDateTime): LongWord;Var  H,M,S,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=(((H*60)+M)*60+S)*1000+MS;end;{ ---------------------------------------------------------------------    Part of hour functions.  ---------------------------------------------------------------------}Function MinuteOfTheHour(const AValue: TDateTime): Word;Var  H,S,MS : Word;begin  DecodeTime(AValue,H,Result,S,MS);end;Function SecondOfTheHour(const AValue: TDateTime): Word;Var  H,S,M,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=M*60+S;end;Function MilliSecondOfTheHour(const AValue: TDateTime): LongWord;Var  H,S,M,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=(M*60+S)*1000+MS;end;{ ---------------------------------------------------------------------    Part of minute functions.  ---------------------------------------------------------------------}Function SecondOfTheMinute(const AValue: TDateTime): Word;Var  H,M,MS : Word;begin  DecodeTime(AValue,H,M,Result,MS);end;Function MilliSecondOfTheMinute(const AValue: TDateTime): LongWord;Var  H,S,M,MS : Word;begin  DecodeTime(AValue,H,M,S,MS);  Result:=S*1000+MS;end;{ ---------------------------------------------------------------------    Part of second functions.  ---------------------------------------------------------------------}Function MilliSecondOfTheSecond(const AValue: TDateTime): Word;Var  H,M,S : Word;begin  DecodeTime(AValue,H,M,S,Result);end;{ ---------------------------------------------------------------------    Range checking functions.  ---------------------------------------------------------------------}Function WithinPastYears(const ANow, AThen: TDateTime; const AYears: Integer): Boolean;begin  Result:=YearsBetween(ANow,AThen)<=AYears;end;Function WithinPastMonths(const ANow, AThen: TDateTime; const AMonths: Integer): Boolean;begin  Result:=MonthsBetween(ANow,AThen)<=AMonths;end;Function WithinPastWeeks(const ANow, AThen: TDateTime; const AWeeks: Integer): Boolean;begin  Result:=WeeksBetween(ANow,AThen)<=AWeeks;end;Function WithinPastDays(const ANow, AThen: TDateTime; const ADays: Integer): Boolean;begin  Result:=DaysBetween(ANow,AThen)<=ADays;end;Function WithinPastHours(const ANow, AThen: TDateTime; const AHours: Int64): Boolean;begin  Result:=HoursBetween(ANow,AThen)<=AHours;end;Function WithinPastMinutes(const ANow, AThen: TDateTime; const AMinutes: Int64): Boolean;begin  Result:=MinutesBetween(ANow,AThen)<=AMinutes;end;Function WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean;begin  Result:=SecondsBetween(ANow,Athen)<=ASeconds;end;Function WithinPastMilliSeconds(const ANow, AThen: TDateTime; const AMilliSeconds: Int64): Boolean;begin  Result:=MilliSecondsBetween(ANow,AThen)<=AMilliSeconds;end;{ ---------------------------------------------------------------------    Period functions.  ---------------------------------------------------------------------}{  These functions are declared as approximate by Borland.  A bit strange, since it can be calculated exactly ?}Function YearsBetween(const ANow, AThen: TDateTime): Integer;begin  Result:=Trunc(Abs(ANow-AThen)/ApproxDaysPerYear);end;Function MonthsBetween(const ANow, AThen: TDateTime): Integer;begin  Result:=Trunc(Abs(ANow-Athen)/ApproxDaysPerMonth);end;Function WeeksBetween(const ANow, AThen: TDateTime): Integer;begin  Result:=Trunc(Abs(ANow-AThen)) div 7;end;Function DaysBetween(const ANow, AThen: TDateTime): Integer;begin  Result:=Trunc(Abs(ANow-AThen));end;Function HoursBetween(const ANow, AThen: TDateTime): Int64;begin  Result:=Trunc(Abs(ANow-AThen)*HoursPerDay);end;Function MinutesBetween(const ANow, AThen: TDateTime): Int64;begin  Result:=Trunc(Abs(ANow-AThen)*MinsPerDay);end;Function SecondsBetween(const ANow, AThen: TDateTime): Int64;begin  Result:=Trunc(Abs(ANow-AThen)*SecsPerDay);end;Function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;begin  Result:=Trunc(Abs(ANow-AThen)*MSecsPerDay);end;{ ---------------------------------------------------------------------    Timespan in xxx functions.  ---------------------------------------------------------------------}Function YearSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(Anow-Athen)/ApproxDaysPerYear;end;Function MonthSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen)/ApproxDaysPerMonth;end;Function WeekSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen) / 7end;Function DaySpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen);end;Function HourSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen)*HoursPerDay;end;Function MinuteSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen)*MinsPerDay;end;Function SecondSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen)*SecsPerDay;end;Function MilliSecondSpan(const ANow, AThen: TDateTime): Double;begin  Result:=Abs(ANow-AThen)*MSecsPerDay;end;{ ---------------------------------------------------------------------    Increment/decrement functions.  ---------------------------------------------------------------------}Function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer ): TDateTime;Var  Y,M,D,H,N,S,MS : Word;begin  DecodeDateTime(AValue,Y,M,D,H,N,S,MS);  Y:=Y+ANumberOfYears;  If (M=2) and (D=29) And (Not IsLeapYear(Y)) then    D:=28;  Result:=EncodeDateTime(Y,M,D,H,N,S,MS);end;Function IncYear(const AValue: TDateTime): TDateTime; // ; const ANumberOfYears: Integer = 1)begin  Result:=IncYear(Avalue,1);end;Function IncWeek(const AValue: TDateTime; const ANumberOfWeeks: Integer): TDateTime;begin  Result:=AValue+ANumberOfWeeks*7;end;Function IncWeek(const AValue: TDateTime): TDateTime; // ; const ANumberOfWeeks: Integer = 1)begin  Result:=IncWeek(Avalue,1);end;Function IncDay(const AValue: TDateTime; const ANumberOfDays: Integer): TDateTime;begin  Result:=AValue+ANumberOfDays;end;Function IncDay(const AValue: TDateTime): TDateTime; //; const ANumberOfDays: Integer = 1)begin  Result:=IncDay(Avalue,1);end;Function IncHour(const AValue: TDateTime; const ANumberOfHours: Int64): TDateTime;begin  Result:=AValue+ANumberOfHours/HoursPerDay;end;Function IncHour(const AValue: TDateTime): TDateTime; //; const ANumberOfHours: Int64 = 1begin  Result:=IncHour(AValue,1);end;Function IncMinute(const AValue: TDateTime; const ANumberOfMinutes: Int64): TDateTime;begin  Result:=Result+ANumberOfMinutes / MinsPerDay;end;Function IncMinute(const AValue: TDateTime): TDateTime; // ; const ANumberOfMinutes: Int64 = 1begin  Result:=IncMinute(AValue,1);end;Function IncSecond(const AValue: TDateTime; const ANumberOfSeconds: Int64): TDateTime;begin  Result:=Result+ANumberOfSeconds / SecsPerDay;end;Function IncSecond(const AValue: TDateTime): TDateTime; // ; const ANumberOfSeconds: Int64 = 1begin  Result:=IncSecond(Avalue,1);end;Function IncMilliSecond(const AValue: TDateTime; const ANumberOfMilliSeconds: Int64): TDateTime;begin  Result:=Result+ANumberOfMilliSeconds/MSecsPerDay;end;Function IncMilliSecond(const AValue: TDateTime): TDateTime; // ; const ANumberOfMilliSeconds: Int64 = 1begin  Result:=IncMilliSecond(AValue,1);end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -