Metropoli BBS
VIEWER: weeknum.arx MODE: TEXT (ASCII)
/******************************************************************************/
/* Copyright 1995 (C) by Andreas Haack
** $Id: weeknum.arx,v 1.5 1996/06/02 10:19:22 hak Exp $
*******************************************************************************
** week numbering - rexx
** $Log: weeknum.arx,v $
** Revision 1.5  1996/06/02 10:19:22  hak
** supply year ast 4th parameter to weeknumber rexx function
**
** Revision 1.4  1996/05/08 23:43:49  hak
** intermidiate level
** with config
**
** Revision 1.3  1996/03/04 23:39:36  hak
** APR000000000: Corenction
** uses start of week
** corrected calulation
**
** Revision 1.2  1996/01/30 20:12:51  hak
** corrected problem with 4.th week in 2000
** no bWeekstart on needed anymore
**
** Revision 1.1  1996/01/23 22:00:53  hak
** Initial revision
**
*******************************************************************************/

/*******************************************************************************
A year has 52 weeks plus 1 or 2 days if 1st jan is a fri - son the week counts
to prev year thus it is still 53rd week otherwise week count to this year
dayOfYear = 0 .. 364,365, weekday 0-6 0 = sun
*******************************************************************************/
trace('O');

parse arg weekday, dayOfYear, bStartOnSunday, year .

weekday = (weekday + (\ bStartOnSunday * 6)) // 7;
dow1st = ((7 - (dayOfYear // 7)) + weekday) // 7;                                 /* week day of 1st week sun = 0*/
week = (dayOfYear + dow1st) % 7;                                           /* 0 based week number */
thisYear = dow1st < 4;                                                          /* if most part of 1st week belongs to this year*/

select
    when week = 0 then
        select
            when dow1st = 4 then
                week = 53;
            when dow1st > 4 then
                week = 52;
            otherwise
                week = 1;
        end
    when week = 52 then
        select
            when dow1st = 3 then
                week = 53;
            when dow1st > 3 then
                week = 52;
            otherwise
                week = 1;
        end
    otherwise
        week = week + thisYear;
end
return week;
[ RETURN TO DIRECTORY ]