• 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
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    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

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

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