Нужно создать модуль для работы с датой и временем в делфи (не используя компонент TCalendar и тип данных TDate)Список задач, которые должен выполнять этот модуль:Определение дня недели;Определение количества дней между Д1 и Д2;Проверка корректности введенной даты;Определение текущей даты и времени;Вычисление количества рабочих дней между датами;Определение даты и времени через определенное (Д, ч, м, с) от текущей датыСоставить календарь
function GetWeekday(const ADay: TDateTime): string; function GetDaysDifference(const ADate1, ADate2: TDateTime): Integer; function IsValidDate(const ADate: TDateTime): Boolean; function GetCurrentDateTime: TDateTime; function GetWorkdaysBetweenDates(const ADate1, ADate2: TDateTime): Integer; function GetDateTimeOffset(const ADays, AHours, AMinutes, ASeconds: Integer): TDateTime;
implementation
uses DateUtils, SysUtils;
function GetWeekday(const ADay: TDateTime): string; begin Result := FormatDateTime('dddd', ADay); end;
function GetDaysDifference(const ADate1, ADate2: TDateTime): Integer; begin Result := DaysBetween(ADate1, ADate2); end;
function IsValidDate(const ADate: TDateTime): Boolean; begin try StrToDate(FormatDateTime('dd.mm.yyyy', ADate)); Result := True; except Result := False; end; end;
function GetCurrentDateTime: TDateTime; begin Result := Now; end;
function GetWorkdaysBetweenDates(const ADate1, ADate2: TDateTime): Integer; var CurrentDate: TDateTime; Workdays: Integer; begin CurrentDate := ADate1; Workdays := 0;
while CurrentDate <= ADate2 do begin if (DayOfTheWeek(CurrentDate) <> 1) and (DayOfTheWeek(CurrentDate) <> 7) then Inc(Workdays);
CurrentDate := IncDay(CurrentDate);
end;
Result := Workdays; end;
function GetDateTimeOffset(const ADays, AHours, AMinutes, ASeconds: Integer): TDateTime; begin Result := Now + ADays + AHours/24 + AMinutes/1440 + ASeconds/86400; end;
unit DateTimeModule;
interface
function GetWeekday(const ADay: TDateTime): string;
function GetDaysDifference(const ADate1, ADate2: TDateTime): Integer;
function IsValidDate(const ADate: TDateTime): Boolean;
function GetCurrentDateTime: TDateTime;
function GetWorkdaysBetweenDates(const ADate1, ADate2: TDateTime): Integer;
function GetDateTimeOffset(const ADays, AHours, AMinutes, ASeconds: Integer): TDateTime;
implementation
uses
DateUtils, SysUtils;
function GetWeekday(const ADay: TDateTime): string;
begin
Result := FormatDateTime('dddd', ADay);
end;
function GetDaysDifference(const ADate1, ADate2: TDateTime): Integer;
begin
Result := DaysBetween(ADate1, ADate2);
end;
function IsValidDate(const ADate: TDateTime): Boolean;
begin
try
StrToDate(FormatDateTime('dd.mm.yyyy', ADate));
Result := True;
except
Result := False;
end;
end;
function GetCurrentDateTime: TDateTime;
begin
Result := Now;
end;
function GetWorkdaysBetweenDates(const ADate1, ADate2: TDateTime): Integer;
var
CurrentDate: TDateTime;
Workdays: Integer;
begin
CurrentDate := ADate1;
Workdays := 0;
while CurrentDate <= ADate2 do
CurrentDate := IncDay(CurrentDate);begin
if (DayOfTheWeek(CurrentDate) <> 1) and (DayOfTheWeek(CurrentDate) <> 7) then
Inc(Workdays);
end;
Result := Workdays;
end;
function GetDateTimeOffset(const ADays, AHours, AMinutes, ASeconds: Integer): TDateTime;
begin
Result := Now + ADays + AHours/24 + AMinutes/1440 + ASeconds/86400;
end;
end.