|
|
|
|
|
|
|
8.4.4.2 iso_first_day_of_week () |
|
|
|
|
|
|
|
|
This routine (Listing 8.11) returns the date that is the first 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 Monday. |
|
|
|
|
| Listing 8.11 | |
|
|
|
|
3. The 'year type' refers to the value, 1 through 14, which identifies
the 'type' of year in the Western calendar. Each year begins with a
certain day of the week (DOW), and is either a common or leap year.
All years with the same year type are structurally identical.
4. The array 'tab' carries the starting date of week 1 for each year
type. The year is carried as an offset, either 0 (the year itself)
or -1 (the prior year). Since the starting date falls before February,
leap years have the same starting date as common years, so the year
types 8 through 14 can be folded over into types 1 through 7. Once the
starting date is established for week 1, the starting date for any
other week number can be found by adding multiples of 7 days to that
date, via conversion to the JD#.
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.
The consequence of these rules is that there are seven cases:
Case 01 JAN Y 1st Thursday Monday starting
Number falls on DOW is date week 1 is date
------ ------------ ------------ ---------------
1 Sunday 05 JAN Y 02 JAN Y
2 Monday 04 JAN Y 01 JAN Y
3 Tuesday 03 JAN Y 31 DEC Y-1
4 Wednesday 02 JAN Y 30 DEC Y-1
5 Thursday 01 JAN Y 29 DEC Y-1
6 Friday 07 JAN Y 04 JAN Y
7 Saturday 06 JAN Y 03 JAN Y
*/
#include "scdtl_2.h"
struct DATE_INFO iso_first_day_of_week (int year, int week)
{
double jd;
int yt;
struct DATE_INFO date;
struct DATE_INFO tab [8] = {{0, 0, 0}, {0, 1, 2}, {0, 1, 1}, {-1, 12, 31},
{-1, 12, 30}, {-1, 12, 29}, {0, 1, 4}, {0, 1, 3}};
date = tab [0];
if ( (week < 1) || (week > 53) )
return (date);
yt = year_type (year);
if ( (yt < 1) || (yt > 14) )
return (date);
|
|
|
|
|
|
|
|