< previous page page_219 next page >

Page 219
8.4.4.3
iso_last_day_of_week ()
This routine (Listing 8.12) returns the date that is the last day of the week for the given year and week number. The definition of week number follows the ISO rule. This date is always a Sunday.
(continued)
Listing 8.12
   4. This routine uses the 'iso_first_day_of_week ()' routine to perform
      the essential validations and calculations, and simply adds 6 to
      the date returned by that routine. This strategy avoids duplication
      of code and ensures that the routines operate consistently together.
   5. The ISO definition of week number depends upon two rules:
      5.1. The first day of the week is Monday.
      5.2. The first week of the year is the week containing the first
           Thursday of the year.


   The consequence of these rules is that there are seven cases:


   Case     01 JAN Y       1st Thursday   Monday starting  Sunday ending
   Number   falls on DOW   is date        week 1 is date   week 1 is date
   ------   ------------   ------------   ---------------  --------------
     1      Sunday         05 JAN Y       02 JAN Y         08 JAN Y
     2      Monday         04 JAN Y       01 JAN Y         07 JAN Y
     3      Tuesday        03 JAN Y       31 DEC Y-1       06 JAN Y
     4      Wednesday      02 JAN Y       30 DEC Y-1       05 JAN Y
     5      Thursday       01 JAN Y       29 DEC Y-1       04 JAN Y
     6      Friday         07 JAN Y       04 JAN Y         10 JAN Y
     7      Saturday       06 JAN Y       03 JAN Y         09 JAN Y


*/


#include "scdtl_2.h"
#include "iso_2.h"


struct DATE_INFO iso_last_day_of_week (int year, int week)
{
   double jd;
   struct DATE_INFO date;


   date = iso_first_day_of_week (year, week);


   if ( (date.year == 0) && (date.month == 0) && (date.day == 0) )
      return (date);


   jd = date_to_JD0 (&date);
   jd += 6.0;
   date = JD0_to_date (jd);


   return (date);
}


 
< previous page page_219 next page >