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

📄 _stdate.pas

📁 条码控件: 一维条码控件 二维条码控件 PDF417Barcode MaxiCodeBarcode
💻 PAS
📖 第 1 页 / 共 2 页
字号:
(* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * 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 TurboPower SysTools
 *
 * The Initial Developer of the Original Code is
 * TurboPower Software
 *
 * Portions created by the Initial Developer are Copyright (C) 1996-2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** *)

{*********************************************************}
{*                   _STDATE.PAS 3.00                    *}
{*********************************************************}

{$I STDEFINE.INC}
{$I STCOMDEF.INC}
unit _StDate;

interface

uses
  ComObj, StDate, SysTools_TLB, StdVcl;

type
  TStDate = class(TAutoObject, IStDate)
   private
    FIsLicensed : Boolean;
   public
    procedure Initialize; override;
   protected {Protected declarations }
    { IStDate - Methods }
    function AstJulianDate(Julian: TDateTime): Double; safecall;
    function AstJulianDatePrim(Year, Month, Day: Integer; UT: TDateTime): Double; safecall;
    function AstJulianDateToStDate(AstJD: Double; Truncate: WordBool): TDateTime; safecall;
    function BondDateDiff(Date1, Date2: TDateTime; DayBasis: TStBondDateType): TDateTime; safecall;
    function CurrentDate: TDateTime; safecall;
    function CurrentDateString(const Picture: WideString; Pack: WordBool): WideString; safecall;
    function CurrentTime: TDateTime; safecall;
    function CurrentTimeString(const Picture: WideString; Pack: WordBool): WideString; safecall;
    procedure DateDiff(Date1, Date2: TDateTime; var Days, Months, Years: Integer); safecall;
    function DateStringHMStoAstJD(const Picture, DS: WideString; Hours, Minutes, Seconds, Epoch: Integer): Double; safecall;
    function DateStringToDMY(const Picture, S: WideString; var Day, Month, Year: Integer; Epoch: Integer): WordBool; safecall;
    function DateStringToStDate(const Picture, S: WideString; Epoch: Integer): TDateTime; safecall;
    procedure DateTimeDiff(DT1, DT2: TDateTime; var Days, Seconds: Integer); safecall;
    function DayOfWeek(Julian: TDateTime): TStDayType; safecall;
    function DayOfWeekDMY(Day, Month, Year, Epoch: Integer): TStDayType; safecall;
    function DayOfWeekToString(WeekDay: TStDayType): WideString; safecall;
    function DaysInMonth(Month, Year, Epoch: Integer): Integer; safecall;
    function DecTime(T: TDateTime; Hours, Minutes, Seconds: Byte): TDateTime; safecall;
    function DMYtoStDate(Day, Month, Year, Epoch: Integer): TDateTime; safecall;
    function DMYtoDateString(const Picture: WideString; Day, Month, Year, Epoch: Integer; Pack: WordBool): WideString; safecall;
    function HMStoStTime(Hours, Minutes, Seconds: Byte): TDateTime; safecall;
    function IncDate(Julian: TDateTime; Days, Months, Years: Integer): TDateTime; safecall;
    procedure IncDateTime(DT1: TDateTime; var DT2: TDateTime; Days,
      Seconds: Integer); safecall;
    function IncDateTrunc(Julian: TDateTime; Months, Years: Integer): TDateTime; safecall;
    function IncTime(T: TDateTime; Hours, Minutes, Seconds: Byte): TDateTime; safecall;
    function InternationalDate(ForceCentury: WordBool): WideString; safecall;
    function InternationalLongDate(ShortNames, ExcludeDOW: WordBool): WideString; safecall;
    function InternationalTime(ShowSeconds: WordBool): WideString; safecall;
    function IsLeapYear(Year: Integer): WordBool; safecall;
    function MonthToString(Month: Integer): WideString; safecall;
    function RoundToNearestHour(T: TDateTime; Truncate: WordBool): TDateTime; safecall;
    function RoundToNearestMinute(T: TDateTime; Truncate: WordBool): TDateTime; safecall;
    function StDateToDateString(const Picture: WideString; Julian: TDateTime; Pack: WordBool): WideString; safecall;
    procedure StDateToDMY(Julian: TDateTime; var Day, Month, Year: Integer);  safecall;
    function StTimeToAmPmString(const Picture: WideString; T: TDateTime; Pack: WordBool): WideString; safecall;
    procedure StTimeToHMS(T: TDateTime; var Hours, Minutes, Seconds: Byte);  safecall;
    function StTimeToTimeString(const Picture: WideString; T: TDateTime; Pack: WordBool): WideString; safecall;
    procedure TimeDiff(T1, T2: TDateTime; var Hours, Minutes, Seconds: Byte); safecall;
    function TimeStringToHMS(const Picture, TS: WideString; var Hours, Minutes, Seconds: Integer): WordBool; safecall;
    function TimeStringToStTime(const Picture, S: WideString): TDateTime; safecall;
    function ValidDate(Day, Month, Year, Epoch: Integer): WordBool; safecall;
    function ValidTime(Hours, Minutes, Seconds: Integer): WordBool; safecall;
    function WeekOfYear(Julian: TDateTime): Byte; safecall;
    function License(const Key: WideString): WordBool; safecall;
  end;

implementation

uses ComServ, StDateSt {$IFDEF LICENSE}, ActiveX, StComLic {$ENDIF};

procedure TStDate.Initialize;
begin
  inherited Initialize;
  {$IFDEF LICENSE}
  FIsLicensed := False;
  {$ELSE}
  FIsLicensed := True;
  {$ENDIF}
end;

{ ********** TStDate Methods ********************************************************** }
function TStDate.AstJulianDate(Julian: TDateTime): Double;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.AstJulianDate(StDate.DateTimeToStDate(Julian));
end;

function TStDate.AstJulianDatePrim(Year, Month, Day: Integer;
  UT: TDateTime): Double;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.AstJulianDatePrim(Year, Month, Day, StDate.DateTimeToStTime(UT));
end;

function TStDate.AstJulianDateToStDate(AstJD: Double;
  Truncate: WordBool): TDateTime;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.StDateToDateTime(StDate.AstJulianDatetoStDate(AstJD, Truncate));
end;

function TStDate.BondDateDiff(Date1, Date2: TDateTime;
  DayBasis: TStBondDateType): TDateTime;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.StDateToDateTime(StDate.BondDateDiff(StDate.DateTimeToStDate(Date1),
                                                        StDate.DateTimeToStDate(Date2),
                                                        StDate.TStBondDateType(DayBasis)));
end;

function TStDate.CurrentDate: TDateTime;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.StDateToDateTime(StDate.CurrentDate);
end;

function TStDate.CurrentDateString(const Picture: WideString;
  Pack: WordBool): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDateSt.CurrentDateString(Picture, Pack);
end;

function TStDate.CurrentTime: TDateTime;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.StTimeToDateTime(StDate.CurrentTime);
end;

function TStDate.CurrentTimeString(const Picture: WideString;
  Pack: WordBool): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDateSt.CurrentTimeString(Picture, Pack);
end;

procedure TStDate.DateDiff(Date1, Date2: TDateTime; var Days, Months,
  Years: Integer);
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  StDate.DateDiff(StDate.DateTimeToStDate(Date1),
                  StDate.DateTimeToStDate(Date2), Days, Months, Years);
end;

function TStDate.DateStringHMStoAstJD(const Picture, DS: WideString; Hours,
  Minutes, Seconds, Epoch: Integer): Double;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDateSt.DateStringHMStoAstJD(Picture, DS, Hours, Minutes, Seconds, Epoch);
end;

function TStDate.DateStringToDMY(const Picture, S: WideString; var Day,
  Month, Year: Integer; Epoch: Integer): WordBool;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDateSt.DateStringToDMY(Picture, S, Epoch, Day, Month, Year);
end;

function TStDate.DateStringToStDate(const Picture, S: WideString;
  Epoch: Integer): TDateTime;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.StDateToDateTime(StDateSt.DateStringToStDate(Picture, S, Epoch));
end;

procedure TStDate.DateTimeDiff(DT1, DT2: TDateTime; var Days,
  Seconds: Integer);
var
  DTR1, DTR2 : StDate.TStDateTimeRec;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  DTR1.D := StDate.DateTimeToStDate(DT1);
  DTR1.T := StDate.DateTimeToStTime(DT1);

  DTR2.D := StDate.DateTimeToStDate(DT2);
  DTR2.T := StDate.DateTimeToStTime(DT2);

  StDate.DateTimeDiff(DTR1, DTR2, Days, Seconds);
end;

function TStDate.DayOfWeek(Julian: TDateTime): TStDayType;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := TStDayType(StDate.DayOfWeek(StDate.DateTimeToStDate(Julian)));
end;

function TStDate.DayOfWeekDMY(Day, Month, Year,
  Epoch: Integer): TStDayType;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := TStDayType(StDate.DayOfWeekDMY(Day, Month, Year, Epoch));
end;

function TStDate.DayOfWeekToString(WeekDay: TStDayType): WideString;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDateSt.DayOfWeekToString(StDate.TStDayType(WeekDay));
end;

function TStDate.DaysInMonth(Month, Year, Epoch: Integer): Integer;
begin
  {$IFDEF LICENSE}
   if (not FIsLicensed) or (not COMHasBeenLicensed) then
     OleError(CLASS_E_NOTLICENSED);
  {$ENDIF}
  Result := StDate.DaysInMonth(Month, Year, Epoch);
end;

function TStDate.DecTime(T: TDateTime; Hours, Minutes,
  Seconds: Byte): TDateTime;
begin
  {$IFDEF LICENSE}

⌨️ 快捷键说明

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