9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / mktime.3c
blob0c0673b15d9b2caf690ffb35c39af075f8624626
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
45 .\" Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved.
46 .\" Copyright 2016 Joyent, Inc.
47 .\"
48 .TH MKTIME 3C "Mar 14, 2016"
49 .SH NAME
50 mktime, timegm \- convert a tm structure to a calendar time
51 .SH SYNOPSIS
52 .LP
53 .nf
54 #include <time.h>
56 \fBtime_t\fR \fBmktime\fR(\fBstruct tm *\fR\fItimeptr\fR);
57 .fi
58 .LP
59 .nf
60 \fBtime_t\fR \fBtimegm\fR(\fBstruct tm *\fR\fItimeptr\fR);
61 .fi
63 .SH DESCRIPTION
64 .LP
65 The \fBmktime()\fR function converts the time represented by the \fBtm\fR
66 structure pointed to by \fItimeptr\fR into a calendar time  (the number of
67 seconds since 00:00:00 UTC, January 1, 1970).
68 .sp
69 .LP
70 The \fBtm\fR structure contains the following members:
71 .sp
72 .in +2
73 .nf
74 int  tm_sec;     /* seconds after the minute [0, 60]  */
75 int  tm_min;     /* minutes after the hour [0, 59] */
76 int  tm_hour;    /* hour since midnight [0, 23] */
77 int  tm_mday;    /* day of the month [1, 31] */
78 int  tm_mon;     /* months since January [0, 11] */
79 int  tm_year;    /* years since 1900 */
80 int  tm_wday;    /* days since Sunday [0, 6] */
81 int  tm_yday;    /* days since January 1 [0, 365] */
82 int  tm_isdst;   /* flag for daylight savings time */
83 .fi
84 .in -2
86 .sp
87 .LP
88 In addition to computing the calendar time, \fBmktime()\fR normalizes the
89 supplied \fBtm\fR structure. The original values of the \fBtm_wday\fR and
90 \fBtm_yday\fR components of the structure are ignored, and the original values
91 of the other components are not restricted to the ranges indicated in the
92 definition of the structure. On successful completion, the values of the
93 \fBtm_wday\fR and \fBtm_yday\fR components are set appropriately, and the other
94 components are set to represent the specified calendar time, but with their
95 values forced to be within the appropriate ranges. The final value of
96 \fBtm_mday\fR is not set until \fBtm_mon\fR and \fBtm_year\fR are determined.
97 .sp
98 .LP
99 The \fBtm_year\fR member must be for year 1901 or later. Calendar times before
100 20:45:52 UTC, December 13, 1901 or after 03:14:07 UTC,  January 19, 2038 cannot
101 be represented. Portable applications should not try to create dates before
102 00:00:00 UTC, January 1, 1970 or after 00:00:00 UTC, January 1, 2038.
105 The original values of the components may be either greater than or less than
106 the specified range. For example, a \fBtm_hour\fR of \(mi1 means 1 hour before
107 midnight, \fBtm_mday\fR of 0 means the day preceding the current month, and
108 \fBtm_mon\fR of \(mi2 means 2 months before January of \fBtm_year\fR.
111 If \fBtm_isdst\fR is positive, the original values are assumed to be in the
112 alternate timezone. If it turns out that the alternate timezone is not valid
113 for the computed calendar time, then the components are adjusted to the main
114 timezone. Likewise, if \fBtm_isdst\fR is zero, the original values are assumed
115 to be in the main timezone and are converted to the alternate timezone if the
116 main timezone is not valid. If  \fBtm_isdst\fR is negative, \fBmktime()\fR
117 attempts to determine whether the alternate timezone is in effect for the
118 specified time.
121 Local timezone information is used as if \fBmktime()\fR had called
122 \fBtzset()\fR. See \fBctime\fR(3C).
125 The \fBtimegm()\fR function is identical to the \fBmktime()\fR function,
126 except that the \fBtimegm()\fR function ignores both the current time
127 zone and the \fBtm_isdst\fR member and operates as though the time zone
128 were set to UTC.
129 .SH RETURN VALUES
131 If the calendar time can be represented in an object of type
132 \fBtime_t\fR, the \fBmktime()\fR and \fBtimegm()\fR functions return the
133 specified calendar time without changing \fBerrno\fR. If the calendar
134 time cannot be represented, the function returns the value
135 (\fBtime_t\fR)\(mi1 and sets \fBerrno\fR to indicate the error.
136 .SH ERRORS
138 The \fBmktime()\fR and \fBtimegm()\fR functions will fail if:
140 .ne 2
142 \fB\fBEOVERFLOW\fR\fR
144 .RS 13n
145 The date represented by the input \fBtm\fR struct cannot be represented in a
146 \fBtime_t\fR.  Note that the \fBerrno\fR setting may change if future revisions
147 to the standards specify a different value.
150 .SH USAGE
152 The \fBmktime()\fR and \fBtimegm()\fR functions are MT-Safe in
153 multithreaded applications, as long as no user-defined function directly
154 modifies one of the following variables: \fBtimezone\fR, \fBaltzone\fR,
155 \fBdaylight\fR, and \fBtzname\fR. See \fBctime\fR(3C).
158 Note that \(mi1 can be a valid return value for the time that is one
159 second before the Epoch.  The user should clear \fBerrno\fR before
160 calling \fBmktime()\fR and \fBtimegm()\fR. If \fBmktime()\fR or
161 \fBtimegm()\fR then returns \(mi1, the user should check \fBerrno\fR to
162 determine whether or not an error actually occurred.
165 The \fBmktime()\fR and \fBtimegm()\fR functions assume Gregorian dates.
166 Times before the adoption of the Gregorian calendar will not match
167 historial records.
168 .SH EXAMPLES
170 \fBExample 1 \fRSample code using \fBmktime()\fR.
173 What day of the week is July 4, 2001?
176 .in +2
178 #include <stdio.h>
179 #include <time.h>
180 static char *const wday[\|] = {
181         "Sunday", "Monday", "Tuesday", "Wednesday",
182         "Thursday", "Friday", "Saturday", "-unknown-"
184 struct tm time_str;
185 /*\|.\|.\|.*/
186 time_str.tm_year        = 2001 - 1900;
187 time_str.tm_mon = 7 - 1;
188 time_str.tm_mday = 4;
189 time_str.tm_hour = 0;
190 time_str.tm_min = 0;
191 time_str.tm_sec = 1;
192 time_str.tm_isdst = \(mi1;
193 if (mktime(&time_str)== \(mi1)
194         time_str.tm_wday=7;
195 printf("%s\en", wday[time_str.tm_wday]);
197 .in -2
199 .SH BUGS
201 The \fBzoneinfo\fR timezone data files do not transition past Tue Jan 19
202 03:14:07 2038 UTC.  Therefore for 64-bit applications using \fBzoneinfo\fR
203 timezones, calculations beyond this date may not use the correct offset from
204 standard time, and could return incorrect values. This affects the 64-bit
205 versions of \fBmktime()\fR and \fBtimegm()\fR.
206 .SH ATTRIBUTES
208 See \fBattributes\fR(5) for descriptions of the following attributes:
213 box;
214 c | c
215 l | l .
216 ATTRIBUTE TYPE  ATTRIBUTE VALUE
218 Interface Stability     Standard
220 MT-Level        MT-Safe with exceptions
223 .SH SEE ALSO
225 \fBctime\fR(3C), \fBgetenv\fR(3C), \fBTIMEZONE\fR(4), \fBattributes\fR(5),
226 \fBstandards\fR(5)