Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Suggestion

0 views
Skip to first unread message

Olivier Pons

unread,
Dec 30, 2007, 4:22:15 PM12/30/07
to
I don't know if this has already been asked to QC.
If no, I 'll do it :

How about those overriden functions (they don't exist) :

procedure ReplaceDate(var DateTime: TDateTime; const Year, Month, Day: Word);
procedure ReplaceTime(var DateTime: TDateTime; const Hour, Min, Sec, MSec: Word);

?

--
Olivier Pons
http://olivier.pons.free.fr/

Olivier Pons

unread,
Dec 30, 2007, 4:33:15 PM12/30/07
to
I forgot also :

procedure IncDate(var DateTime: TDateTime; const Year, Month, Day: Word);
procedure IncTime(var DateTime: TDateTime; const Hour, Min, Sec, MSec: Word);

Zoren Lendry

unread,
Dec 30, 2007, 4:54:01 PM12/30/07
to
Olivier Pons wrote:
> procedure IncDate(var DateTime: TDateTime; const Year, Month, Day: Word);
> procedure IncTime(var DateTime: TDateTime; const Hour, Min, Sec, MSec:
> Word);

Excuse my asking, but are you aware of the DateUtils unit? It's fairly
exhaustive with these types of routines.

Loren

Rudy Velthuis [TeamB]

unread,
Dec 30, 2007, 4:51:40 PM12/30/07
to
Olivier Pons wrote:

> I don't know if this has already been asked to QC.
> If no, I 'll do it :
>
> How about those overriden functions (they don't exist) :
>
> procedure ReplaceDate(var DateTime: TDateTime; const Year, Month,
> Day: Word);
> procedure ReplaceTime(var DateTime: TDateTime; const
> Hour, Min, Sec, MSec: Word);
>
> ?

Assuming you mean overloaded, and not overridden, it should be pretty
easy to write your own. Just give them slightly different names.

procedure ReplaceDateWith(var DateTime: TDateTime;


const Year, Month, Day: Word);

begin
ReplaceDate(myDateTime, EncodeDate(Year, Month, Day));
end;

procedure ReplaceTimeWith(var DateTime: TDateTime;
const Hour, Min, Sec, MSec: Word));
begin
ReplaceTime(myDateTime, EncodeTime(Hour, Min, Sec, MSec));
end;

--
Rudy Velthuis [TeamB] http://www.teamb.com

"Go away...I'm alright." -- H.G.Wells, dying words

Olivier Pons

unread,
Jan 1, 2008, 6:28:37 PM1/1/08
to
Rudy Velthuis [TeamB] wrote :
> ...
>

You're perfectly right.
I've done it, it's easy, but I was just wondering if it could be useful, say, for a beginner, not to have to write his/her own routine.

Olivier Pons

unread,
Jan 1, 2008, 6:30:25 PM1/1/08
to
Zoren Lendry wrote :
> ...

I'm sorry I didn't express myself properly and I forgot to say at the beginning of my post : "in the DateUtils functions, how about overloading those functions, that don't exist yet :"

JED

unread,
Jan 7, 2008, 8:48:53 PM1/7/08
to
Olivier Pons wrote:

> I don't know if this has already been asked to QC.
> If no, I 'll do it :
>
> How about those overriden functions (they don't exist) :
>
> procedure ReplaceDate(var DateTime: TDateTime; const Year, Month,
> Day: Word); procedure ReplaceTime(var DateTime: TDateTime; const
> Hour, Min, Sec, MSec: Word);

There is currently no QC report asking for these particular overloads
of ReplaceDate. I suggest you create one new report for each new
overload.

cheers,
Jeremy

--
TJSDialog - TaskDialog for other operating systems:
http://www.jed-software.com/jsd.htm
Visual Forms IDE Add In: http://www.jed-software.com/vf.htm

Blog: http://jedqc.blogspot.com

Jon P. Grewer

unread,
Jan 12, 2008, 6:47:50 PM1/12/08
to
I have been watching for some small way to give back to this community
that has given so much to me, so:

function IncDate(Const DateTime: TDateTime; const Year, Month, Day:
Word) : TDatetime;
var
YYYY, MM, DD : Word;
begin
DecodeDate(Datetime,YYYY,MM,DD);
inc(YYYY, Year);
inc(MM, Month);
inc(YYYY, MM div 12);
MM := MM mod 12;
DD := DD + Day - 1;
Result := EncodeDate(YYYY,MM,01);
Result := Result + DD + Frac(Datetime);
end;

Function IncTime(Const DateTime: TDateTime; const Hour, Min, Sec, MSec:
Word) : TDatetime;
var
H, M, S, MS : Word;
D : Cardinal;
begin
DecodeTime(DateTime, H, M, S, MS);
D := Trunc(Datetime);
inc(H,Hour);
inc(M, Min);
inc(S, Sec);
inc(MS, MSec);
inc(S, MS div 1000); MS := (MS mod 1000);
inc(M, S div 60 ); S := S mod 60;
inc(H, M div 60 ); M := M mod 60;
inc(D, H div 24 ); H := H mod 24;

Result := D + EncodeTime(H,M,S,MS);
end;

Function ReplaceDateWith(Const DateTime: TDateTime; const Year, Month,
Day: Word) : TDatetime;
begin
Result := Datetime;
ReplaceDate(Result, EncodeDate(Year, Month, Day));
end;

Function ReplaceTimeWith(Const DateTime: TDateTime; const Hour, Min,
Sec, MSec: Word) : TDatetime;
begin
Result := Datetime;
ReplaceTime(Result, EncodeTime(Hour, Min, Sec, MSec));
end;

Olivier Pons wrote :


> Rudy Velthuis [TeamB] wrote :
>> ...
>>
>
> You're perfectly right.
> I've done it, it's easy, but I was just wondering if it could be useful, say,
> for a beginner, not to have to write his/her own routine.

--
________
God is love. Love is a character trait. So, God is a character trait.


Carsten Bothe

unread,
Jan 16, 2008, 8:45:35 AM1/16/08
to
incdate, decdate ...

Very tricky, really smaller than my solution and looks correct,
more than i can say for my functions at one look.

hope can use it without purchasing :-)

cbo

"Jon P. Grewer" <JonNoSp...@Grewer.net> schrieb im Newsbeitrag
news:mn.64677d81c...@Grewer.net...

Julian M Bucknall [Developer Express]

unread,
Jan 16, 2008, 11:37:21 PM1/16/08
to
Jon

Hate to say it but your IncDate won't work properly. An example,
adding one month to 31-Jan-2007. The routine will fail at the moment,
but you need to decide what this calculation actually means. You need
a whole lot more processing in there to catch this kind of problem.

For an example of the complexities that are inherent in this type of
calculation, a long while back I wrote this post
(http://www.boyet.com/Articles/PublishedArticles/Calculatingthenumberofmon.html)
on how to calculate the number of months and days between two dates.

--
Cheers, Julian

-----------------------------------------------------------
Julian M Bucknall
CTO, Developer Express, www.devexpress.com
jul...@devexpress.com

Personal blog at http://www.boyet.com
Company blog at http://community.devexpress.com/blogs/ctodx
Author of "Tomes of Delphi: Algorithms and Data Structures"
Read my articles in PCPlus every month
-----------------------------------------------------------
|

Jon P. Grewer

unread,
Jan 17, 2008, 4:07:44 PM1/17/08
to
Hi Julian,

You are exactly right! I stand corrected. My IncDate routine will
deliver a valid date but it won't necessarily deliver expected results.
The following correct but redundant routine will always work but by
shifting responsibility back onto the programmer. Thanks for pointing
it out!

For anyone interested, I heartily recommend Julian's article. I had
read it a few years back but had apparently forgotten the gotcha's that
are so easily glossed over when we are in our abstracting problem
solving mode. Also, to anyone who made use of my routine: you have
very likely introduced a bug into your code. My apologies to you.

function IncDate(Const DateTime: TDateTime; const Day: Word) :
TDatetime;
begin
Result := DateTime;
Result := Result + Day;
end;

It happens that Julian M Bucknall [Developer Express] formulated :


> Jon
>
> Hate to say it but your IncDate won't work properly. An example,
> adding one month to 31-Jan-2007. The routine will fail at the moment,
> but you need to decide what this calculation actually means. You need
> a whole lot more processing in there to catch this kind of problem.
>
> For an example of the complexities that are inherent in this type of
> calculation, a long while back I wrote this post
> (http://www.boyet.com/Articles/PublishedArticles/Calculatingthenumberofmon.html)
> on how to calculate the number of months and days between two dates.

--
________
In communication 101, I am required to give a speech on drugs. But I
don't think I can deliver a good speech while on drugs!


0 new messages