ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/cvttotv.htm

314 lines
7.9 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>Qp0zCvtToTimeval()-Convert _MI_Time to Timeval Structure</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- CVTTOTV SCRIPT A converted by B2H R4.1 (346) (CMS) by KENTALA at -->
<!-- RCHVMW2 on 7 Oct 1998 at 11:50:01 -->
<!-- This file has undergone html cleanup on 1/28/02 by JET -->
<!-- End Header Records -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>Qp0zCvtToTimeval()-Convert _MI_Time to Timeval Structure</h2>
<div class="box" style="width: 80%;">
<br>
&nbsp;&nbsp;Syntax:<br>
<pre>
#include &lt;qp0z1170.h&gt;
int Qp0zCvtToTimeval (struct timeval *<em>to</em>,
const _MI_Time <strong>from</strong>,
int <strong>option</strong>);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0ZCPA<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>Qp0zCvtToTimeval()</strong> function converts a machine
timestamp (or a machine timestamp offset), represented by an _MI_Time data
type, to a corresponding structure timeval value. The job's time zone offset from UTC
and epoch-1970 are optionally taken into account by this conversion. Only
timestamps or timestamp offsets in the following ranges can be converted:</p>
<ul>
<li>Timestamps that are later than or equal to 1 January 1970, 00:00:00 UTC
(epoch-1970) and less than 19 January 2038, 03:14:08 UTC.</li>
<li>Timestamp offsets that are greater than or equal to 0 and less than 2,147,483,648
seconds.</li>
</ul>
<p><strong>Note:</strong> This function uses a header (include) file from the
library QSYSINC, which is optionally installable. Make sure QSYSINC is
installed on your system before using this function. See <a href="unix13.htm">
Header Files for UNIX-Type Functions</a>) for the file and member name of each
header file.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>to</strong></dt>
<dd>(Output) The address of the timeval structure to contain the converted
timestamp (or timestamp offset).<br>
<br>
</dd>
<dt><strong>from</strong></dt>
<dd>(Input) The _MI_Time data type to be converted.<br>
<br>
</dd>
<dt><strong>option</strong></dt>
<dd>(Input) The conversion option.</dd>
</dl>
<br>
<p>The <strong>option</strong> parameter must be one of the following
constants:</p>
<dl>
<dt><strong>QP0Z_CVTTIME_TO_OFFSET</strong></dt>
<dd>Do the conversion as a timestamp offset, not factoring in the UTC offset
from the current time zone of the job or epoch-1970.<br>
<br>
</dd>
<dt><strong>QP0Z_CVTTIME_TO_TIMESTAMP</strong></dt>
<dd>Do the conversion as a timestamp, factoring in the UTC offset from the
current time zone of the job and epoch-1970.<br>
<br>
</dd>
<dt><strong>QP0Z_CVTTIME_FACTOR_EPOCH_ONLY</strong></dt>
<dd>Do the conversion as a timestamp, but factor in epoch-1970 only.<br>
<br>
</dd>
<dt><strong>QP0Z_CVTTIME_FACTOR_UTCOFFSET_ONLY</strong></dt>
<dd>Do the conversion as a timestamp, but factor in the UTC offset from
the current time zone of the job only.</dd>
</dl>
<br>
<h3>Authorities and Locks</h3>
<p>None.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="15 85" -->
<tr>
<td align="left" valign="top"><em>0</em></td>
<td align="left" valign="top"><strong>Qp0zCvtToTimeval()</strong> was
successful. The value referenced by the <strong>to</strong> parameter is the
converted timestamp (or timestamp offset).</td>
</tr>
<tr>
<td align="left" valign="top"><em>-1</em></td>
<td align="left" valign="top"><strong>Qp0zCvtToTimeval()</strong> was not
successful. The <em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>Qp0zCvtToTimeval()</strong> is not successful, <em>errno</em>
usually indicates one of the following errors. Under some conditions, <em>
errno</em> could indicate an error other than those listed here.</p>
<dl>
<dt><em>[EINVAL]</em></dt>
<dd>The value specified for the argument is not correct.
<p>A function was passed incorrect argument values, or an operation was
attempted on an object and the operation specified is not supported for that
type of object.</p>
<p>An argument value is not valid, out of range, or NULL.</p>
</dd>
<dt><em>[EFAULT]</em></dt>
<dd>The address used for an argument is not correct.
<p>In attempting to use an argument in a call, the system detected an address
that is not valid.</p>
<p>While attempting to access a parameter passed to this function, the system
detected an address that is not valid.</p>
</dd>
<dt><em>[ERANGE]</em></dt>
<dd>A range error occurred.
<p>The value of an argument is too small, or a result too large.</p>
</dd>
<dt><em>[EUNKNOWN]</em></dt>
<dd>Unknown system state.
<p>The operation failed because of an unknown system state. See any messages in
the job log and correct any errors that are indicated, then retry the
operation.</p>
</dd>
</dl>
<br>
<h3>Error Messages</h3>
<p>None.</p>
<br>
<h3>Usage Notes</h3>
<ol type="1">
<li><strong>Qp0zCvtToTimeval()</strong>, when called with <strong>
option</strong> equal to QP0Z_CVTTIME_TO_OFFSET, will convert the machine
timestamp offset given in the <strong>from</strong> parameter to an equivalent
number of seconds and microseconds. This could be used to calculate a time
delay.</li>
<li><strong>Qp0zCvtToTimeval()</strong>, when called with <strong>
option</strong> equal to QP0Z_CVTTIME_TO_TIMESTAMP, will convert the machine
timestamp given in the <strong>from</strong> parameter to an equivalent number
of seconds and microseconds. This could be used as a UNIX-type timestamp.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>qp0z1170.h</strong>&gt; file (see <a href="unix13.htm">
Header Files for UNIX-Type Functions</a>)</li>
<li><a href="cvttomit.htm">Qp0zCvtToMITime() - Convert Timeval Structure
to_MI_Time</a></li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example converts a timestamp:</p>
<pre>
#include &lt;qp0z1170.h&gt;
#include &lt;mimchint.h&gt;
#include &lt;stdio.h&gt;
#include &lt;errno.h&gt;
int main(int argc, char *argv[])
{
_MI_Time mt;
struct timeval tv;
int rc;
mattod(mt);
printf("mi timestamp: %08X%08X\n",
*((unsigned *)&amp;mt[0]),
*((unsigned *)&amp;mt[4]));
rc = Qp0zCvtToTimeval(&amp;tv, mt, QP0Z_CVTTIME_TO_TIMESTAMP);
if(rc==0) {
printf("timeval timestamp: %u.%06u\n",
tv.tv_sec, tv.tv_usec);
}
else {
printf("Qp0zCvtToTimeval() failed, errno = %d\n",
errno);
return -1;
}
return 0;
}
</pre>
<strong>Example Output:</strong>
<pre>
mi timestamp: 7B7E9425EAC00000
timeval timestamp: 867422292.052992
</pre>
<br>
<hr>
API introduced: V4R2
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"misc1.htm">Miscellaneous APIs</a> | <a href="aplist.htm">APIs by
category</a></td>
</tr>
</table>
</center>
</body>
</html>