< previous page page_220 next page >

Page 220
Listing 8.13 iso_date_to_ywd ()
/* idat2ywd.c


   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+


   Routine converts a date expressed as a DATE_INFO structure, as a year, month and
   day to an ISO_YWD structure, expressing the same date in the form of a year, week
   and day. The week is the ISO week number, and the day is the ISO day in the week.


   INPUTS:
   1. date, pointer to a DATE_INFO structure, containing the date to be
      converted to an ISO_YWD structure date.


   OUTPUTS:
   1. Returned by routine, an ISO_YWD structure containing the input date,
      converted to ISO_YWD form.


   NOTES:
   1. The 'week' of the ISO_YWD structure is the ISO week number, 1 to 53.
   2. The 'day' of the ISO_YWD structure is the ISO day number in a week,
      from 1 to 7, as follows:


      1 = Monday
      2 = Tuesday
      3 = Wednesday
      4 = Thursday
      5 = Friday
      6 = Saturday
      7 = Sunday
*/


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


struct ISO_YWD iso_date_to_ywd (struct DATE_INFO *date)
{
   double jd;
   int m;
   struct ISO_YWD ywd;


   ywd.year = date->year;
   ywd.week = iso_week_number (date);
   m = date->month;


   /*
   Following code checks for January dates which are part of last week of previous
   year. Use '50' to pick up special case of A.D. 1582, as well as usual cases of year
   ending with week 52 or week 53. Several other values would also work as well.
   */


   if (m = 1)
      {
      if (ywd.week > 50)
         ywd.year--;
      }

 
< previous page page_220 next page >