John,

Your code is indeed simpler. I took 1970-1-1 as the base. The code
*executes* one %diff and one %rem, but with a bit more fiddling because
1970.

The weeknumber calculation i just implemented reading the wiki page,
assuming it's correct (which it is). I simply took the first method listed.
There are 3 methods listed, but the first seemed to be the most elaborate
one ;)

Also, i replaced for example

// UK08
wd4 = IsoWkdayNum(%date(y*10000+104:*iso));

with

// UK08
x = %diff(date:%date(y*10000+104:*iso):*d);
if x < 0;
wd4 = wd1 - x;
if wd4 > 7;
wd4 = wd4 - 7;
endif;
else;
wd4 = wd1 - %rem(x:7);
if wd4 < 1;
wd4 = wd4 + 7;
endif;
endif;

to make it - a bit - more efficient (so IsoWkdayNum is called just once
instead of 5 times).







On Wed, Dec 3, 2014 at 5:09 PM, John Yeung <gallium.arsenide@xxxxxxxxx>
wrote:

On Wed, Dec 3, 2014 at 7:17 AM, John E <whattssonn@xxxxxxxxx> wrote:
From http://nl.wikipedia.org/wiki/Weeknummer (which is in dutch) :

To calculate the ISO weekday (1=monday) for a given date:

I don't read Dutch, but even so, I didn't see any weekday calculations
on that page. I saw a bunch of tables and algorithms relating to ISO
week *number* (which makes sense, given the title of the article).

Calculating the *weekday* in pure RPG (IV) doesn't have to be as
complicated as what you've provided, though. Now, before I go any
further, let me just state for the record that I recommend using the
available SQL functions, including converting the source to SQLRPGLE
if it isn't already.

For those who *for whatever reason* want to get the ISO weekday in RPG
IV without SQL, you can make use of the fact that the date type
supports proleptic Gregorian dates back to 0001-01-01. Also make use
of the fact that 0001-01-01 was (proleptically speaking) a Monday.

Assuming you keep all the declarations as before, simply do

d = %diff(date:d'0001-01-01':*d);
return %rem(d:7) + 1;

Note that the result of %DIFF gives you the number of days AFTER
0001-01-01 (so 0001-01-02 is Day 1). Also note that calculating the
day of the week (whether ISO or any other reasonable scheme) should
NEVER be more complicated than one %DIFF, one %REM, and optionally
*one* fudge at the end to adjust the offset.

The ISO week number calculations are necessarily more complicated.
I'm not sure they have to be as complicated as what you've provided,
but I don't have the time to search for a simpler implementation or
come up with my own right now.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2019 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].