Qp0zCvtToTimeval()-Convert _MI_Time to Timeval Structure
Syntax:
#include <qp0z1170.h> int Qp0zCvtToTimeval (struct timeval *to, const _MI_Time from, int option);
Service Program Name: QP0ZCPA
Default Public Authority: *USE
Threadsafe: Yes
The Qp0zCvtToTimeval() 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:
- 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.
- Timestamp offsets that are greater than or equal to 0 and less than 2,147,483,648 seconds.
Note: 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 Header Files for UNIX®-Type Functions) for the file and member name of each header file.
Parameters
- to
- (Output) The address of the timeval structure to contain the converted
timestamp (or timestamp offset).
- from
- (Input) The _MI_Time data type to be converted.
- option
- (Input) The conversion option.
The option parameter must be one of the following constants:
- QP0Z_CVTTIME_TO_OFFSET
- Do the conversion as a timestamp offset, not factoring in the UTC offset
from the current time zone of the job or epoch-1970.
- QP0Z_CVTTIME_TO_TIMESTAMP
- Do the conversion as a timestamp, factoring in the UTC offset from the
current time zone of the job and epoch-1970.
- QP0Z_CVTTIME_FACTOR_EPOCH_ONLY
- Do the conversion as a timestamp, but factor in epoch-1970 only.
- QP0Z_CVTTIME_FACTOR_UTCOFFSET_ONLY
- Do the conversion as a timestamp, but factor in the UTC offset from the current time zone of the job only.
Authorities and Locks
None.
Return Value
0 | Qp0zCvtToTimeval() was successful. The value referenced by the to parameter is the converted timestamp (or timestamp offset). |
-1 | Qp0zCvtToTimeval() was not successful. The errno variable is set to indicate the error. |
Error Conditions
If Qp0zCvtToTimeval() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
- [EINVAL]
- The value specified for the argument is not correct.
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.
An argument value is not valid, out of range, or NULL.
- [EFAULT]
- The address used for an argument is not correct.
In attempting to use an argument in a call, the system detected an address that is not valid.
While attempting to access a parameter passed to this function, the system detected an address that is not valid.
- [ERANGE]
- A range error occurred.
The value of an argument is too small, or a result too large.
- [EUNKNOWN]
- Unknown system state.
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.
Error Messages
None.
Usage Notes
- Qp0zCvtToTimeval(), when called with option equal to QP0Z_CVTTIME_TO_OFFSET, will convert the machine timestamp offset given in the from parameter to an equivalent number of seconds and microseconds. This could be used to calculate a time delay.
- Qp0zCvtToTimeval(), when called with option equal to QP0Z_CVTTIME_TO_TIMESTAMP, will convert the machine timestamp given in the from parameter to an equivalent number of seconds and microseconds. This could be used as a UNIX-type timestamp.
Related Information
- The <qp0z1170.h> file (see Header Files for UNIX-Type Functions)
- Qp0zCvtToMITime() - Convert Timeval Structure to_MI_Time
Example
The following example converts a timestamp.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#include <qp0z1170.h> #include <mimchint.h> #include <stdio.h> #include <errno.h> int main(int argc, char *argv[]) { _MI_Time mt; struct timeval tv; int rc; mattod(mt); printf("mi timestamp: %08X%08X\n", *((unsigned *)&mt[0]), *((unsigned *)&mt[4])); rc = Qp0zCvtToTimeval(&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; }Example Output:
mi timestamp: 7B7E9425EAC00000 timeval timestamp: 867422292.052992
API introduced: V4R2