1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * Time_t conversion support
32 static unsigned char offset
[7][3] =
45 * 0 sunday first day of week
46 * 1 monday first day of week
47 * 2 monday first day of iso week
48 * if week<0 then return week for tm
49 * if day<0 then set tm to first day of week
50 * otherwise set tm to day in week
51 * and return tm->tm_yday
55 tmweek(Tm_t
* tm
, int type
, int week
, int day
)
61 if ((day
= tm
->tm_wday
- tm
->tm_yday
% 7) < 0)
63 week
= (tm
->tm_yday
+ offset
[day
][type
]) / 7;
67 week
= (day
> 0 && day
< 6 || tmisleapyear(tm
->tm_year
- 1)) ? 53 : 52;
68 else if (week
== 53 && (tm
->tm_wday
+ (31 - tm
->tm_mday
)) < 4)
79 tm
->tm_mday
= week
* 7 - offset
[d
][type
] + ((day
|| type
!= 2) ? day
: 7);
81 if (d
= tm
->tm_wday
- day
)