× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On 01/04/2008, at 2:13 AM, Joe D wrote:

Although I do not know it is a 'trap', posting to the list right before bed
is a very bad idea. As soon as my head hit the pillow, I rethought the
formula and realized it was - as you said - just as bad as the misquoted one
from my first post. Then my mind started working through alternatives...

I solve far too many coding issues either just before or while I'm asleep. I used to live 200 metres from where I worked and far too often I'd wake up at 2 or 3 AM with a coding solution fresh in my head and go in to work to code it up. I should get a life! Oh, that's right I did.


I came up with the one you posted, and a couple of alternatives. All three
of which were (quite unfortunately) thought through thoroughly - when I
should have been sleeping.

Here are the two others I thought of, and I am sure there are others:
Quarter = %div(Month : 3.01) + 1;

The compiler won't like that one. Make it normal division q=(m/3.01) +1 and it works. I don't like this because it's obscure. It makes you stop and ask Why the .01? And out comes the pencil and paper to prove that it's correct.

Quarter %dim(Month + 2 : 3);

I don't like that one either. It makes it harder to deal with financial quarters.

For me I wouldn't do this calculation in direct code. I'd write a generic procedure:
getQuarterOfYear( date [, fiscalPeriodStart] )

that defaults to calendar quarters but can optionally handle fiscal quarters with any period starting month. Thus:
x = getQuarterOfYear( date )
gives the calendar quarters while:
x = getQuarterOfYear( date, $JULY ) // where $JULY is a constant of 7
gives fiscal quarters for a July-June financial year.

True, you have the cost of a procedure call but you get self- documenting code as a result.

Now, if RPG IV only supported in-lining procedures ...

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.