cxdateutils.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,765 行 · 第 1/5 页
PAS
1,765 行
{********************************************************************}
{ }
{ Developer Express Visual Component Library }
{ Express Cross Platform Library classes }
{ }
{ Copyright (c) 2000-2008 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSCROSSPLATFORMLIBRARY AND ALL }
{ ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM }
{ ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{********************************************************************}
unit cxDateUtils;
{$I cxVer.inc}
interface
uses
Variants, SysUtils,
Windows, Controls, Classes, Graphics, cxClasses;
type
TDay = (dSunday, dMonday, dTuesday, dWednesday, dThursday, dFriday, dSaturday);
TDays = set of TDay;
TDayOfWeek = 0..6;
TcxDateElement = (deYear, deMonth, deDay);
TcxFirstWeekOfYear = (fwySystem, fwyJan1, fwyFirstFullWeek, fwyFirstFourDays);
const
DATE_YEARMONTH = $00000008; // use year month picture
{$EXTERNALSYM DATE_YEARMONTH}
DATE_LTRREADING = $00000010; // add marks for left to right reading order layout
{$EXTERNALSYM DATE_LTRREADING}
DATE_RTLREADING = $00000020; // add marks for right to left reading order layout
{$EXTERNALSYM DATE_RTLREADING}
NullDate = -700000;
InvalidDate = NullDate + 1;
SmartTextToDateFunc: function(const AText: string; var ADate: TDateTime): Boolean = nil;
{$IFNDEF DELPHI7}
ApproxDaysPerMonth: Double = 30.4375;
ApproxDaysPerYear: Double = 365.25;
DaysPerWeek = 7;
WeeksPerFortnight = 2;
MonthsPerYear = 12;
YearsPerDecade = 10;
YearsPerCentury = 100;
YearsPerMillennium = 1000;
HoursPerDay = 24;
MinsPerHour = 60;
SecsPerMin = 60;
MSecsPerSec = 1000;
MinsPerDay = HoursPerDay * MinsPerHour;
SecsPerDay = MinsPerDay * SecsPerMin;
MSecsPerDay = SecsPerDay * MSecsPerSec;
DayMonday = 1;
DayTuesday = 2;
DayWednesday = 3;
DayThursday = 4;
DayFriday = 5;
DaySaturday = 6;
DaySunday = 7;
{$ENDIF}
const
CAL_GREGORIAN = 1; //Gregorian (localized) calendar
{$EXTERNALSYM CAL_GREGORIAN}
CAL_GREGORIAN_US = 2; //Gregorian (U.S.) calendar
{$EXTERNALSYM CAL_GREGORIAN_US}
CAL_JAPAN = 3; // Japanese Emperor Era calendar
{$EXTERNALSYM CAL_JAPAN}
CAL_TAIWAN = 4; // Republic of China Era calendar
{$EXTERNALSYM CAL_TAIWAN}
CAL_KOREA = 5; // Korean Tangun Era calendar
{$EXTERNALSYM CAL_KOREA}
CAL_HIJRI = 6; // Hijri (Arabic Lunar) calendar
{$EXTERNALSYM CAL_HIJRI}
CAL_THAI = 7; // Thai calendar
{$EXTERNALSYM CAL_THAI}
CAL_HEBREW = 8; // Hebrew calendar
{$EXTERNALSYM CAL_HEBREW}
CAL_GREGORIAN_ME_FRENCH = 9; // Gregorian Middle East French calendar
{$EXTERNALSYM CAL_GREGORIAN_ME_FRENCH}
CAL_GREGORIAN_ARABIC = 10; // Gregorian Arabic calendar
{$EXTERNALSYM CAL_GREGORIAN_ARABIC}
CAL_GREGORIAN_XLIT_ENGLISH = 11; // Gregorian Transliterated English calendar
{$EXTERNALSYM CAL_GREGORIAN_XLIT_ENGLISH}
CAL_GREGORIAN_XLIT_FRENCH = 12; // Gregorian Transliterated French calendar
{$EXTERNALSYM CAL_GREGORIAN_XLIT_FRENCH}
CAL_JULIAN = 13; // Julian calendar
{$EXTERNALSYM CAL_JULIAN}
CAL_JAPANESELUNISOLAR = 14; // Japanes Lunar/Solar calendar
{$EXTERNALSYM CAL_JAPANESELUNISOLAR}
CAL_CHINESELUNISOLAR = 15; // Chinese Lunar/Solar calendar
{$EXTERNALSYM CAL_CHINESELUNISOLAR}
CAL_SAKA = 16; // reserved to match Office but not implemented in our code
{$EXTERNALSYM CAL_SAKA}
CAL_LUNAR_ETO_CHN = 17; // reserved to match Office but not implemented in our code
{$EXTERNALSYM CAL_LUNAR_ETO_CHN}
CAL_LUNAR_ETO_KOR = 18; // reserved to match Office but not implemented in our code
{$EXTERNALSYM CAL_LUNAR_ETO_KOR}
CAL_LUNAR_ETO_ROKUYOU = 19; // reserved to match Office but not implemented in our code
{$EXTERNALSYM CAL_LUNAR_ETO_ROKUYOU}
CAL_KOREANLUNISOLAR = 20; // Korean Lunar/Solar calendar
{$EXTERNALSYM CAL_KOREANLUNISOLAR}
CAL_TAIWANLUNISOLAR = 21; // Taiwan Lunar/Solar calendar
{$EXTERNALSYM CAL_TAIWANLUNISOLAR}
CAL_PERSIAN = 22; // Persian calendar
{$EXTERNALSYM CAL_PERSIAN}
CAL_UMALQURA = 23; // UmAlQura Hijri (Arabic Lunar) calendar }
{$EXTERNALSYM CAL_UMALQURA}
CAL_SSHORTESTDAYNAME1 = $00000060; // Windows Vista or later: Short native name of the first day of the week.
{$EXTERNALSYM CAL_SSHORTESTDAYNAME1}
CAL_SSHORTESTDAYNAME2 = $00000061; // Windows Vista or later: Short native name of the second day of the week.
{$EXTERNALSYM CAL_SSHORTESTDAYNAME2}
CAL_SSHORTESTDAYNAME3 = $00000062; // Windows Vista or later: Short native name of the third day of the week.\
{$EXTERNALSYM CAL_SSHORTESTDAYNAME3}
CAL_SSHORTESTDAYNAME4 = $00000063; // Windows Vista or later: Short native name of the fourth day of the week.
{$EXTERNALSYM CAL_SSHORTESTDAYNAME4}
CAL_SSHORTESTDAYNAME5 = $00000064; // Windows Vista or later: Short native name of the fifth day of the week.
{$EXTERNALSYM CAL_SSHORTESTDAYNAME5}
CAL_SSHORTESTDAYNAME6 = $00000065; // Windows Vista or later: Short native name of the sixth day of the week.
{$EXTERNALSYM CAL_SSHORTESTDAYNAME6}
CAL_SSHORTESTDAYNAME7 = $00000066; // Windows Vista or later: Short native name of the seventh day of the week.
{$EXTERNALSYM CAL_SSHORTESTDAYNAME7}
CAL_RETURN_NUMBER = $20000000; // Windows 98/Me, Windows 2000 and later: Returns the result from GetCalendarInfo as a number instead of a string. This is only valid for CALTYPES beginning with CAL_I.
{$EXTERNALSYM CAL_RETURN_NUMBER}
CAL_ITWODIGITYEARMAX = $00000030; // Windows 98/Me, Windows 2000 and later: An integer value indicating the upper boundary of the two-digit year range.
{$EXTERNALSYM CAL_ITWODIGITYEARMAX}
CAL_SYEARMONTH = $0000002F; // Windows 98/Me, Windows 2000 and later: Enumerates the year/month formats for the specified calendars.
{$EXTERNALSYM CAL_SYEARMONTH}
type
{$IFNDEF DELPHI7}
TFormatSettings = record
CurrencyFormat: Byte;
NegCurrFormat: Byte;
ThousandSeparator: Char;
DecimalSeparator: Char;
CurrencyDecimals: Byte;
DateSeparator: Char;
TimeSeparator: Char;
ListSeparator: Char;
CurrencyString: string;
ShortDateFormat: string;
LongDateFormat: string;
TimeAMString: string;
TimePMString: string;
ShortTimeFormat: string;
LongTimeFormat: string;
ShortMonthNames: array[1..12] of string;
LongMonthNames: array[1..12] of string;
ShortDayNames: array[1..7] of string;
LongDayNames: array[1..7] of string;
TwoDigitYearCenturyWindow: Word;
end;
{$ENDIF}
{$EXTERNALSYM TcxCALID}
TcxCALID = DWORD; { Calendar ID. }
TcxCalendarAlgorithmType = (catUnknown, catSolarCalendar, catLunarCalendar,
catLunarSolarCalendar);
TcxDateTime = record
Era: Integer;
Year: Cardinal;
Month: Cardinal;
Day: Cardinal;
Hours: Byte;
Minutes: Byte;
Seconds: Byte;
Milliseconds: Word;
end;
TcxDate = record
Era: Integer;
Year: Cardinal;
Month: Cardinal;
Day: Cardinal;
end;
TcxTime = record
Hours: Cardinal;
Minutes: Cardinal;
Seconds: Cardinal;
Miliseconds: Cardinal;
end;
TcxEra = class(TPersistent)
private
FEra: Integer;
FMaxEraYear: Integer;
FMinEraYear: Integer;
FStartDate: TDateTime;
FYearOffset: Integer;
public
constructor Create(AEra: Integer; AStartDate: TDateTime;
AYearOffset, AMinEraYear, AMaxEraYear: Integer);
procedure Assign(Source: TPersistent); override;
property Era: Integer read FEra write FEra;
property MaxEraYear: Integer read FMaxEraYear write FMaxEraYear;
property MinEraYear: Integer read FMinEraYear write FMinEraYear;
property StartDate: TDateTime read FStartDate write FStartDate;
property YearOffset: Integer read FYearOffset write FYearOffset;
end;
TcxEras = class(TcxObjectList)
private
function GetItem(AIndex: Integer): TcxEra;
procedure SetItem(AIndex: Integer; AValue: TcxEra);
public
property Items[Index: Integer]: TcxEra read GetItem write SetItem; default;
end;
{ TcxCustomCalendarTable }
TcxCustomCalendarTable = class
protected
FEras: TcxEras;
procedure AdjustYear(var AYear, AEra: Integer); overload; virtual;
procedure AdjustYear(var AYear, AEra: Integer; AMonth, ADay: Integer); overload; virtual;
function GetCalendarAlgorithmType: TcxCalendarAlgorithmType; virtual; abstract;
function GetCalendarID: TcxCALID; virtual; abstract;
function GetDefaultEra: TcxEra; virtual; abstract;
function GetMaxSupportedDate: TDateTime; virtual; abstract;
function GetMinSupportedDate: TDateTime; virtual; abstract;
procedure CheckDateTime(var ADateTime: TDateTime); virtual;
function GetMaxSupportedYear: Integer; virtual; abstract;
function GetMinSupportedYear: Integer; virtual; abstract;
function IsNotValid(ADate: TcxDateTime; out AResult: TDateTime): Boolean;
procedure YearToGregorianYear(var AYear: Cardinal; AEra: Integer);
public
constructor Create; virtual;
destructor Destroy; override;
function AddDays(ADate: TcxDateTime; ACountDays: Integer): TDateTime; overload; virtual;
function AddMonths(ADate: TDateTime; ACountMonths: Integer): TDateTime; overload; virtual;
function AddMonths(ADate: TcxDateTime; ACountMonths: Integer): TDateTime; overload; virtual;
function AddYears(ADate: TDateTime; ACountYears: Integer): TDateTime; overload; virtual;
function AddYears(ADate: TcxDateTime; ACountYears: Integer): TDateTime; overload; virtual;
function AddWeeks(ADate: TDateTime; ACountWeeks: Integer): TDateTime; overload; virtual;
function AddWeeks(ADate: TcxDateTime; ACountWeeks: Integer): TDateTime; overload; virtual;
function FromDateTime(ADate: TDateTime): TcxDateTime; overload; virtual; abstract;
function FromDateTime(AYear, AMonth, ADay: Cardinal): TcxDateTime; overload; virtual;
function FromDateTime(AYear, AMonth, ADay: Cardinal; AHours, AMinutes, ASeconds: Byte;
AMilliseconds: Word): TcxDateTime; overload; virtual;
function GetDayOfYear(ADate: TDateTime): Cardinal; overload; virtual;
function GetDayOfYear(ADate: TcxDateTime): Cardinal; overload; virtual;
function GetDaysInMonth(AYear, AMonth: Cardinal): Cardinal; overload; virtual;
function GetDaysInMonth(AEra: Integer; AYear, AMonth: Cardinal): Cardinal; overload; virtual; abstract;
function GetDaysInYear(AYear: Cardinal): Cardinal; overload; virtual;
function GetDaysInYear(AEra: Integer; AYear: Cardinal): Cardinal; overload; virtual; abstract;
function GetEra(AYear: Integer): Integer; overload; virtual;
function GetEra(AYear, AMonth, ADay: Integer): Integer; overload; virtual;
function GetFirstDayOfWeek(ADate: TDateTime): TDateTime; overload; virtual;
function GetFirstDayOfWeek(ADate: TDateTime; AStartDayOfWeek: TDay): TDateTime; overload; virtual;
function GetFirstDayOfWeek(ADate: TcxDateTime): TcxDateTime; overload; virtual;
function GetFirstDayOfWeek(ADate: TcxDateTime; AStartDayOfWeek: TDay): TcxDateTime; overload; virtual;
function GetFirstWeekDay: Byte; virtual; abstract;
function GetFullWeeksInYear(AYear: Cardinal): Cardinal; virtual; abstract;
function GetMonthsInYear(AYear: Cardinal): Cardinal; overload; virtual;
function GetMonthsInYear(AEra: Integer; AYear: Cardinal): Cardinal; overload; virtual; abstract;
function GetYear(ADate: TDateTime): Cardinal; overload; virtual;
function GetYear(ADate: TcxDate): Cardinal; overload; virtual;
function GetYear(ADate: TcxDateTime): Cardinal; overload; virtual;
function GetWeekDay(ADate: TDateTime): Byte; overload; virtual;
function GetWeekDay(ADate: TcxDateTime): Byte; overload; virtual;
function GetWeekNumber(ADate: TDateTime; AStartOfWeek: TDay;
AFirstWeekOfYear: TcxFirstWeekOfYear): Cardinal; overload; virtual;
function GetWeekNumber(ADate: TcxDateTime; AStartOfWeek: TDay;
AFirstWeekOfYear: TcxFirstWeekOfYear): Cardinal; overload; virtual; abstract;
function IsLeapDay(AYear, AMonth, ADay: Cardinal): Boolean; overload; virtual;
function IsLeapDay(AEra: Integer; AYear, AMonth, ADay: Cardinal): Boolean; overload; virtual; abstract;
function IsLeapMonth(AYear, AMonth: Cardinal): Boolean; overload; virtual;
function IsLeapMonth(AEra: Integer; AYear, AMonth: Cardinal): Boolean; overload; virtual; abstract;
function IsLeapYear(AYear: Cardinal): Boolean; overload; virtual;
function IsLeapYear(AEra: Integer; Year: Cardinal): Boolean; overload; virtual; abstract;
function IsValidYear(AYear: Cardinal): Boolean; overload; virtual;
function IsValidYear(AEra: Integer; AYear: Cardinal): Boolean; overload; virtual;
function IsValidMonth(AYear, AMonth: Cardinal): Boolean; overload; virtual;
function IsValidMonth(AEra: Integer; AYear, AMonth: Cardinal): Boolean; overload; virtual;
function IsValidDay(AYear, AMonth, ADay: Cardinal): Boolean; overload; virtual;
function IsValidDay(AEra: Integer; AYear, AMonth, ADay: Cardinal): Boolean; overload; virtual;
function IsValidDate(ADate: TDateTime): Boolean; virtual;
function ToDateTime(ADate: TcxDate): TDateTime; overload; virtual;
function ToDateTime(AYear, AMonth, ADay: Cardinal): TDateTime; overload; virtual;
function ToDateTime(AYear, AMonth, ADay: Cardinal; AHours, AMinutes, ASeconds: Byte;
AMilliseconds: Word): TDateTime; overload; virtual;
function ToDateTime(ADateTime: TcxDateTime): TDateTime; overload; virtual; abstract;
function GetDayNumber(const S: string): Integer; virtual;
function GetMonthNumber(AYear: Integer; const S: string): Integer; virtual;
function GetYearNumber(const S: string): Integer; virtual;
property AlgorithmType: TcxCalendarAlgorithmType read GetCalendarAlgorithmType;
property CalendarID: TcxCALID read GetCalendarID;
property DefaultEra: TcxEra read GetDefaultEra;
property Eras: TcxEras read FEras;
property MaxSupportedDate: TDateTime read GetMaxSupportedDate;
property MinSupportedDate: TDateTime read GetMinSupportedDate;
end;
{ TcxGregorianCalendarTable }
TcxGregorianCalendarTableType = (gctLocalized = 1, gctUSEnglish = 2, gctMiddleEastFrench = 9,
gctArabic = 10, gctTransliteratedEnglish = 11, gctTransliteratedFrench = 12);
TcxGregorianCalendarTable = class(TcxCustomCalendarTable)
private
FDefaultEra: TcxEra;
FGregorianCalendarType: TcxGregorianCalendarTableType;
protected
function GetCalendarAlgorithmType: TcxCalendarAlgorithmType; override;
function GetCalendarID: TcxCALID; override;
function GetDefaultEra: TcxEra; override;
function GetMaxSupportedDate: TDateTime; override;
function GetMinSupportedDate: TDateTime; override;
function GetMaxSupportedYear: Integer; override;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?