Hi Marvin,
I am attempting to get the change date from the stat procedure. Can
anyone tell me how to translate the value received from stat into a
date and/or time?
The following code demonstrates this. It contains two procedures...
Unix2Rpg converts from the st_atime, st_mtime, st_ctime fields into the
timestamp format that we typically use in RPG.
There's also a Rpg2Unix in this sample code that translates the other
direction.... Which you didn't ask for, but I'm including it just to
be complete.
H DFTACTGRP(*NO)
/copy ifsio_h
D Unix2Rpg PR Z
D UnixTime 10U 0 value
D Rpg2Unix PR 10U 0
D RpgTime Z const
D myfile s 5000a varying
D st ds likeds(statds)
D ts s Z
D Uts s like(st_atime)
/free
myfile = '/home/klemscot/aaron.mbr';
if stat( %trimr(myfile): st ) = -1;
// check errno, handle error
endif;
// to convert into RPG's Z format:
ts = Unix2Rpg(st.st_atime);
dsply ('atime = ' + %char(ts:*ISO) );
ts = Unix2Rpg(st.st_mtime);
dsply ('mtime = ' + %char(ts:*ISO) );
ts = Unix2Rpg(st.st_ctime);
dsply ('ctime = ' + %char(ts:*ISO) );
// to convert back:
uts = Rpg2Unix(ts);
*inlr = *on;
/end-free
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Unix2Rpg(): Convert Unix timestamp -> RPG timestamp
*
* UnixTime = (input) timestamp in Unix format
* (seconds from epoch, UTC)
*
* Returns the RPG timestamp
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P Unix2Rpg B export
D Unix2Rpg PI Z
D UnixTime 10U 0 value
D CEEUTCO PR
D Hours 10I 0
D Mins 10I 0
D Secs 8F
D fc 12A options(*omit)
D Epoch c z'1970-01-01-00.00.00'
D offset s 10I 0 static inz(-1)
D Hours s 10I 0 static
D Mins s 10I 0 static
D Secs s 8F static
D retval s Z
/free
if (offset = -1);
CEEUTCO(Hours: Mins: Secs: *omit);
offset = secs;
endif;
retval = Epoch
+ %seconds(UnixTime)
+ %seconds(offset);
return retval;
/end-free
P E
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Rpg2Unix(): Convert RPG timestamp -> Unix timestamp
*
* RpgTime = (input) RPG timestamp field to convert.
*
* Returns the Unix timestamp (seconds from epoch in UTC)
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P Rpg2Unix B export
D Rpg2Unix PI 10U 0
D RpgTime Z const
D CEEUTCO PR
D Hours 10I 0
D Mins 10I 0
D Secs 8F
D fc 12A options(*omit)
D Epoch c z'1970-01-01-00.00.00'
D Hours s 10I 0 static
D Mins s 10I 0 static
D Secs s 8F static
D Offset s 10i 0 static inz(-1)
D UnixTime s 10U 0
/free
if (offset = -1);
CEEUTCO(Hours: Mins: Secs: *omit);
offset = secs;
endif;
Unixtime = %diff( RpgTime
: Epoch + %seconds(offset)
: *SECONDS );
return UnixTime;
/end-free
P E
As an Amazon Associate we earn from qualifying purchases.