• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Interpreting Stream File Timestamps

    May 14, 2014 Ted Holt

    Fortunately, IBM i has an Integrated File System (IFS), into which you can store any kind of data your heart desires. Fortunately, IBM provides an API that your programs can use to retrieve information about IFS stream files. Unfortunately, this API is rooted in the Unix world. Unfortunately, timestamps are stored in what I would call a bizarre manner. Fortunately, you are intelligent enough to learn how this API works.

    When you need to know programmatically about a stream file, you can use the stat API. Like many things UNIX, stat is idiosyncratic, especially in the way that it reports the last time a file was accessed, the last time the contents were changed, and the last time the status changed. These times are reported in epoch time.

    Epoch time is the number of seconds that have elapsed since January 1, 1970, UTC, not counting leap seconds. Since epoch time is represented as a four-byte signed integer, the range of permissible dates is December 13, 1901, through January 19, 2038.

    The following example of excellence in programming illustrates the process you must go through to find out when a file was last accessed or changed.

    H dftactgrp(*no) actgrp(*new)
    H option(*srcstmt: *nodebugio) bnddir('QC2LE')
    
    D g_UTC_Offset    s             10i 0
    
    D StmfInfo        ds                  qualified inz
    D   Mode                        10u 0
    D   ID                          10u 0
    D                                5u 0
    D                                5u 0
    D   UserID                      10u 0
    D   GroupID                     10u 0
    D   Size                        10i 0
    D   AccessTime                  10i 0
    D   ContentChangeTime...
    D                               10i 0
    D   StatusChangeTime...
    D                               10i 0
    D                               10u 0
    D   BlockSize                   10u 0
    D   AllocationSize...
    D                               10u 0
    D   ObjectType                  11a
    D                                1a
    D   CodePage                     5u 0
    D   CCSID                        5u 0
    D   DeivceID                    10u 0
    D   NumberOfLinks...
    D                               10u 0
    D   DeviceID                    20u 0
    D   FileSystemID                20u 0
    D                               36a
    D   Generation_ID...
    D                               10u 0
    
    D stat            pr            10i 0 extproc('stat')
    D   path                          *   value options(*string)
    D   buffer                            likeds(StmfInfo)
    
    D StmfName        s            256a   varying
    D FileStatus      s             10i 0
    
    D AccessTime      s               z
    D ContentChangeTime...
    D                 s               z
    D StatusChangeTime...
    D                 s               z
    
     /free
         *inlr = *on;
         Get_UTC_Offset ();
         //    UTC_Offset = -18,000 seconds
    
         StmfName = 'cdcatalog.xml';
         FileStatus = stat (StmfName: StmfInfo);
    
         if FileStatus >= *zero;
            AccessTime        = ToTime (StmfInfo.AccessTime);
            ContentChangeTime = ToTime (StmfInfo.ContentChangeTime);
            StatusChangeTime  = ToTime (StmfInfo.StatusChangeTime);
         endif;
    
         return;
     /end-free
     * ==============================================================
    P Get_UTC_Offset  b
    D                 pi
    
    D CEEUTCO         pr                  extproc('CEEUTCO')
    D   Hours                       10i 0
    D   Minutes                     10i 0
    D   Seconds                      8f
    D   FC                          12a   options(*omit)
    
    D UTC_Hours       s             10i 0
    D UTC_Minutes     s             10i 0
    D UTC_Seconds     s              8f
    
     /free
         CEEUTCO (UTC_Hours: UTC_Minutes: UTC_Seconds: *omit);
         g_UTC_Offset = %int(UTC_Seconds);
     /end-free
    P                 e
     * ===============================================================
    P ToTime          b
    D                 pi              z
    D  inSeconds                    10i 0 value
     *** locals
    D Epoch           s               z   inz(z'1970-01-01-00.00.00')
     /free
         return Epoch + %seconds(inSeconds) + %seconds(g_UTC_Offset);
    /end-free
    P                 e
    

    The program first calls the Get Offset from Universal Time Coordinated to Local Time (CEEUTCO) API to determine the system offset to UTC in seconds.

    D g_UTC_Offset    s             10i 0
    
    P Get_UTC_Offset  b
    D                 pi
    
    D CEEUTCO         pr                  extproc('CEEUTCO')
    D   Hours                       10i 0
    D   Minutes                     10i 0
    D   Seconds                      8f
    D   FC                          12a   options(*omit)
    
    D UTC_Hours       s             10i 0
    D UTC_Minutes     s             10i 0
    D UTC_Seconds     s              8f
    
     /free
         CEEUTCO (UTC_Hours: UTC_Minutes: UTC_Seconds: *omit);
         g_UTC_Offset = %int(UTC_Seconds);
     /end-free
    P                 e
    

    CEEUTCO loads three parameters:

    • The number of hours of offset.
    • The number of additional minutes of offset.
    • The total number of seconds offset.

    I ignore a fourth, omissible parameter. I also ignore the first two parameters. I only use the third one. Since my shop is in the Central Time Zone, which is five hours behind UTC, CEEUTCO loads -18000 into the third parameter. The program copies this value into global variable g_UTC_Offset. As a rule I avoid global variables, but global variables are good for unchangeable values such as this one.

    Next the program runs the stat API to retrieve information about a stream file.

    D StmfInfo        ds                  qualified inz
    D   Mode                        10u 0
    D   ID                          10u 0
    D                                5u 0
    D                                5u 0
    D   UserID                      10u 0
    D   GroupID                     10u 0
    D   Size                        10i 0
    D   AccessTime                  10i 0
    D   ContentChangeTime...
    D                               10i 0
    D   StatusChangeTime...
    D                               10i 0
    D                               10u 0
    D   BlockSize                   10u 0
    D   AllocationSize...
    D                               10u 0
    D   ObjectType                  11a
    D                                1a
    D   CodePage                     5u 0
    D   CCSID                        5u 0
    D   DeivceID                    10u 0
    D   NumberOfLinks...
    D                               10u 0
    D   DeviceID                    20u 0
    D   FileSystemID                20u 0
    D                               36a
    D   Generation_ID...
    D                               10u 0
    
    D stat            pr            10i 0 extproc('stat')
    D   path                          *   value options(*string)
    D   buffer                            likeds(StmfInfo)
    
    D StmfName        s            256a   varying
    D FileStatus      s             10i 0
    
     /free
         StmfName = 'cdcatalog.xml';
         FileStatus = stat (StmfName: StmfInfo);
    

    Now the program must convert the three timestamps from epoch format to the timestamp data type.

    AccessTime = ToTime (StmfInfo.AccessTime);
    
    P ToTime          b 
    D                 pi              z
    D  inSeconds                    10i 0 value
     *** locals
    D Epoch           s               z   inz(z'1970-01-01-00.00.00')
     /free
         return Epoch + %seconds(inSeconds) + %seconds(g_UTC_Offset);
    /end-free
    P                 e
    

    This table shows the timestamp values for the example file.




    Field

    Epoch time

    Timestamp

    Access
    time

    1397513743

    2014-04-14-17.15.43

    Content
    change time

    1380124596

    2013-09-25-10.56.36

    Status
    change time

    1380125525

    2013-09-25-11.12.05

    It may seem a bit odd to store timestamps this way, but if every little factory in Mississippi had been running Unix machines instead of System/34s in the 1980s, I would undoubtedly be very familiar with epoch time and consider it normal.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Symtrax:  SAP Webinar: Go Paperless with ePayslips for SAP - 13th of May, 4pm EDT
    LANSA:  Webinar: Mobile and the IBM i: Why Should You Care? May 21, 9 am PT/11 am CT/Noon ET
    RJS Software Systems:  Webinar: Learn how WebForms can save time and money. May 27.

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Magic Software Still Has The Touch In Q1 IBM Patches Heartbleed Vulnerability in Power Systems Firmware

    Leave a Reply Cancel reply

Volume 14, Number 11 -- May 14, 2014
THIS ISSUE SPONSORED BY:

ProData Computer Services
PowerTech
WorksRight Software

Table of Contents

  • Using Built-In Global Variables In DB2 For i 7.2
  • Interpreting Stream File Timestamps
  • Admin Alert: When Journaling Slows Down Your System, And What To Do About It

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle