Dates.pas
资源名称:delphi.rar [点击查看]
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:2k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit Dates;
- interface
- type
- TDate = class
- private
- fDate: TDateTime;
- procedure SetDay(const Value: Integer);
- procedure SetMonth(const Value: Integer);
- procedure SetYear(const Value: Integer);
- function GetDay: Integer;
- function GetMonth: Integer;
- function GetYear: Integer;
- public
- constructor Create; overload;
- constructor Create (y, m, d: Integer); overload;
- procedure SetValue (y, m, d: Integer); overload;
- procedure SetValue (NewDate: TDateTime); overload;
- procedure Assign(Source: TDate);
- function LeapYear: Boolean;
- procedure Increase (NumberOfDays: Integer = 1);
- procedure Decrease (NumberOfDays: Integer = 1);
- function GetText: string;
- property Year: Integer read GetYear write SetYear;
- property Month: Integer read GetMonth write SetMonth;
- property Day: Integer read GetDay write SetDay;
- end;
- TNewDate = class (TDate)
- public
- function GetText: string;
- end;
- implementation
- uses
- SysUtils, DateUtils;
- procedure TDate.Assign (Source: TDate);
- begin
- fDate := Source.fDate;
- end;
- procedure TDate.SetValue (y, m, d: Integer);
- begin
- fDate := EncodeDate (y, m, d);
- end;
- function TDate.LeapYear: Boolean;
- begin
- Result := IsInLeapYear(fDate);
- end;
- procedure TDate.Increase (NumberOfDays: Integer = 1);
- begin
- fDate := fDate + NumberOfDays;
- end;
- function TDate.GetText: string;
- begin
- GetText := DateToStr (fDate);
- end;
- procedure TDate.Decrease (NumberOfDays: Integer = 1);
- begin
- fDate := fDate - NumberOfDays;
- end;
- constructor TDate.Create (y, m, d: Integer);
- begin
- fDate := EncodeDate (y, m, d);
- end;
- constructor TDate.Create;
- begin
- fDate := Date;
- end;
- procedure TDate.SetValue(NewDate: TDateTime);
- begin
- fDate := NewDate;
- end;
- procedure TDate.SetDay(const Value: Integer);
- begin
- fDate := RecodeDay (fDate, Value);
- end;
- procedure TDate.SetMonth(const Value: Integer);
- begin
- fDate := RecodeMonth (fDate, Value);
- end;
- procedure TDate.SetYear(const Value: Integer);
- begin
- fDate := RecodeYear (fDate, Value);
- end;
- function TDate.GetDay: Integer;
- begin
- Result := DayOf (fDate);
- end;
- function TDate.GetMonth: Integer;
- begin
- Result := MonthOf (fDate);
- end;
- function TDate.GetYear: Integer;
- begin
- Result := YearOf (fDate);
- end;
- { TNewDate }
- function TNewDate.GetText: string;
- begin
- GetText := FormatDateTime ('dddddd', fDate);
- end;
- end.