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 #include "FEATURE/tmlib"
36 * time zone and leap seconds accounted for in return value
40 tmxtm(register Tm_t
* tm
, Time_t t
, Tm_zone_t
* zone
)
42 register struct tm
* tp
;
43 register Tm_leap_t
* lp
;
57 if ((tm_info
.flags
& (TM_ADJUST
|TM_LEAP
)) == (TM_ADJUST
|TM_LEAP
) && (n
= tmxsec(t
)))
59 for (lp
= &tm_data
.leap
[0]; n
< lp
->time
; lp
++);
62 if (n
== lp
->time
&& (leapsec
= (lp
->total
- (lp
+1)->total
)) < 0)
64 t
= tmxsns(n
- lp
->total
, tmxnsec(t
));
68 if (!(tm
->tm_zone
= zone
))
70 if (tm_info
.flags
& TM_UTC
)
71 tm
->tm_zone
= &tm_data
.zone
[2];
73 tm
->tm_zone
= tm_info
.zone
;
75 if ((o
= 60 * tm
->tm_zone
->west
) && x
> o
)
81 i
= x
/ (24 * 60 * 60);
83 n
= x
- z
* (24 * 60 * 60);
84 tm
->tm_sec
= n
% 60 + leapsec
;
91 tm
->tm_sec
= x
% 60 + leapsec
;
98 tm
->tm_wday
= (x
+ 4) % 7;
99 tm
->tm_year
= (400 * (x
+ 25202)) / 146097 + 1;
101 x
-= n
* 365 + n
/ 4 - n
/ 100 + (n
+ (1900 - 1600)) / 400 - (1970 - 1901) * 365 - (1970 - 1901) / 4;
104 tm
->tm_nsec
= tmxnsec(t
);
108 if (tm
->tm_zone
->daylight
)
110 if ((y
= tmequiv(tm
) - 1900) == tm
->tm_year
)
118 now
= tmxsec(tmxtime(&te
, tm
->tm_zone
->west
));
120 if ((tp
= tmlocaltime(&now
)) && ((tm
->tm_isdst
= tp
->tm_isdst
) || o
))
122 tm
->tm_min
-= o
/ 60 + (tm
->tm_isdst
? tm
->tm_zone
->dst
: 0);
131 * time zone and leap seconds accounted for in return value
139 return tmxtm(&ts
, t
, NiL
);