AlonsoYSal_FactuGES2/Source/Base/Utiles/uDateUtils.pas

61 lines
1.4 KiB
ObjectPascal
Raw Normal View History

unit uDateUtils;
interface
uses
SysUtils, Classes;
function DarFechaPrimerDia(Date: TDateTime): TDateTime;
function DarFechaUltimoDia(Date: TDateTime): TDateTime;
function EsFechaVacia(AFecha : TDateTime): Boolean;
function DarInicioAno(AFecha: TDateTime): TDateTime;
function DarFinAno(AFecha: TDateTime): TDateTime;
const
FECHA_NULA = -700000;
implementation
function DarInicioAno(AFecha: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
Result := EncodeDate(Year, 1, 1);
end;
function DarFinAno(AFecha: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
Result := EncodeDate(Year, 12, 31);
end;
function EsFechaVacia(AFecha : TDateTime): Boolean;
begin
Result := (AFecha = FECHA_NULA) or (AFecha = 0);
end;
function DarFechaPrimerDia(Date: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
Result := EncodeDate(Year, Month, 1);
end;
function DarFechaUltimoDia(Date: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
// (if Month < 12 then inc(Month)
// else begin Month := 1; inc(Year) end;
// Result := EncodeDate(Year, Month, 1) - 1;
Result := EncodeDate(Year, Month,
MonthDays[IsLeapYear(Year), Month]);
end;
end.