Datetime rounding enhancement

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Datetime rounding enhancement

Post by h.hasenack » Fri Jul 24, 2009 9:33 am

I have been using this patch for a long time now, to allow better rounding of intervals < half month. It also allows rounding of dates before 1-1-1900.

Code: Select all

Function TeeRoundDate(Const ADate:TDateTime; AStep:TDateTimeStep):TDateTime;
var Year  : Word;
    Month : Word;
    Day   : Word;
begin
  if ADate=0 then // only suppress rounding for the Delphi 'null' date 30-12-1899
     result:=ADate
  else
  begin
    if AStep<dtHalfMonth then
    begin
      Case AStep of
        dtOneDay: result:=round(ADate); 
        dtTwoDays: result:=round(ADate/2.0)*2;
        dtThreeDays: result:=round(ADate/3.0)*3;
        dtOneWeek: result:=2.0+round((ADate-2.0)/7.0)*7;
        else result:=ADate;
      end;
    end
    else
    begin
      DecodeDate(ADate,Year,Month,Day);
      Case AStep of
         dtHalfMonth   : if Day>=15 then Day:=15
                                    else Day:=1;
         dtOneMonth,
         dtTwoMonths,
         dtThreeMonths,
         dtFourMonths,
         dtSixMonths   : Day:=1;
         dtOneYear     : begin
                           Day:=1;
                           Month:=1;
                         end;
      end;
      result:=EncodeDate(Year,Month,Day);
    end;
  end;
end;

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Datetime rounding enhancement

Post by Yeray » Fri Jul 24, 2009 1:50 pm

Hi Hans,

I've added this to the wish list to be implemented in future releases (TV52014310).

Thank you.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Datetime rounding enhancement

Post by Narcís » Thu Jul 30, 2009 11:32 am

Hi Hans,

Thanks for your feedback! I've added your suggestion to v8 sources so that you can expect this being in next maintenance release.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply