|
|
|

The Time_s service program is a collection of functions that handle time issues.
Functions In This Service Program
The Time_s service program contains the following functions:
| Time_TopOfTheHour | Returns the top of the next hour for the time passed |
| Time_DelayJobUntil | Delays until the time passed. (Checks for %shtdn ) |
| Time_MicroSleep | Sleeps for a number of microseconds |
| Time_Sleep | Sleeps for a number of seconds |
| Time_TimeToString | Returns the time in a string of words |
Time_P Prototypes Source
/if defined(TIME_p)
/eof
/endif
/define TIME_p
d TIME_TopOfTheHour...
d pr t
d PassedTime t const options(*nopass)
d TIME_DelayJobUntil...
d pr
d PassedTime t const
d Resolution 6p 0 const options(*nopass)
d TIME_MicroSleep...
d pr
d SleepTime 10u 0 const
d TIME_uSleep...
d pr 10u 0 ExtProc('usleep')
d SleepTime 10u 0 value
d TIME_Sleep pr 10u 0 ExtProc('sleep')
d SleepTime 10u 0 value
d TIME_TimeToString...
d pr 11a
d PassedTime t const
Time_S Service Program Source
h nomain bnddir('QC2LE')
/copy *libl/qrpglesrc,time_p
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* T I M E _ S S e r v i c e P r o g r a m
*
* @copyrite 1997, 2009 Michael Catalani
* ProvatoSys www.ProvatoSys.com
* mcatalani@aol.com
* 901.581.8791
*
*
* FUNCTION DESCRIPTION
* TopOfTheHour Returns the day of the week name
* DelayJobUntil Pauses until a certain time is reached
* MicroSleep Sleeps for microseconds
* TimeToString Returns the a time in XX:XX:XXam format
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/if defined(TIME_i)
/eof
/endif
/define TIME_i
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* T i m e _ T o p O f T h e H o u r
*
* Returns a time which reflects the top of the next hour
* ie: A time of 03:32:45 would return 04:00:00
*
* Input Field - Input Time ( Time Field )
* Returns - Top of the hour ( Time Field )
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p Time_TopOfTheHour...
p b export
d Time_TopOfTheHour...
d pi t
d PassedTime t const options(*nopass)
d NewTime s t
/free
if %parms = 0;
NewTime = %time;
else;
NewTime = PassedTime;
endif;
NewTime -= %minutes( %subdt( NewTime : *minutes ) ) -
%seconds( %subdt( NewTime : *seconds ) ) +
%hours( 1 );
return NewTime;
/end-free
p e
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* T i m e _ D e l a y J o b U n t i l
*
* This procedure will sleep until the time specified, while
* checking perioically for a %shutdn condition
*
* Input Field - Resume Time ( Time Field )
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p Time_DelayJobUntil...
p b export
d Time_DelayJobUntil...
d pi
d PassedTime t const
d Resolution 6p 0 const options(*nopass)
d WaitTime s 6p 0
d ResumeStamp s z
d UntilTime s 15p 0
d MicroTime s 10u 0
/free
if %parms < 2;
WaitTime = 10;
else;
WaitTime = Resolution;
endif;
ResumeStamp = %date + passedtime;
if ResumeStamp < %timestamp;
ResumeStamp = ResumeStamp + %days( 1 );
endif;
dou %timestamp > ResumeStamp ;
UntilTime = %diff( ResumeStamp : %timestamp : *mseconds );
if UntilTime < ( WaitTime * 1000000);
MicroTime = UntilTime;
TIME_MicroSleep( MicroTime );
else;
TIME_Sleep( WaitTime );
endif;
if %shtdn;
return;
endif;
enddo;
return;
/end-free
p e
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* T i m e _ M i c r o S l e e p
*
* This function can sleep for intermittent durations down to
* 1 microsecond.
*
* Input Field - Time to Sleep in MicroSeconds (10u 0)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p Time_MicroSleep...
p b export
d Time_MicroSleep...
d pi
d MicroSeconds 10u 0 const
d Seconds s like(MicroSeconds)
d RemainingTime s like(MicroSeconds)
/free
if MicroSeconds >= 1000000;
Seconds = Microseconds/1000000;
RemainingTime = MicroSeconds - (Seconds * 1000000);
Time_Sleep(Seconds);
Time_usleep(RemainingTime);
else;
Time_uSleep(MicroSeconds);
endif;
return;
/end-free
p e
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* T i m e _ T i m e T o S t r i n g
*
* Returns a formatted time string
*
* Input Field - Input Time ( Time Field )
* Returns - XX:XX:XX am/pm Time ( Character 11 )
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
p Time_TimeToString...
p b export
d Time_TimeToString...
d pi 11a
d PassedTime t const
d TimeString s 11a varying
d Hours s 2p 0
d Minutes s 2p 0
d Seconds s 2p 0
d AmPm s 3a
/free
Hours = %subdt( PassedTime : *hours );
Minutes = %subdt( PassedTime : *minutes );
Seconds = %subdt( PassedTime : *seconds );
if %subdt( PassedTime : *hours) >= 12;
AmPm = ' pm';
if %subdt( PassedTime : *hours) > 12;
Hours -= 12;
endif;
else;
AmPm = ' am';
if %subdt( PassedTime : *hours) = 0;
Hours = 12;
endif;
endif;
TimeString = %editc( Hours : 'X' ) + ':' +
%editc( Minutes : 'X' ) + ':' +
%editc( Seconds : 'X' ) +
AmPm;
return ( TimeString );
/end-free
p e
Time_S Binder Source
STRPGMEXP PGMLVL(*CURRENT)
EXPORT SYMBOL(Time_TopOfTheHour)
EXPORT SYMBOL(Time_DelayJobUntil)
EXPORT SYMBOL(Time_MicroSleep)
EXPORT SYMBOL(Time_TimeToString)
ENDPGMEXP
Creating The Service Program
CRTRPGMOD MODULE(CF/TIME_S) SRCFILE(CF/QRPGLESRC)
CRTSRVPGM SRVPGM(CF/TIME_S)
** replace the library "CF" with the library you are using.
Perform an ADDBNDDIRE to place the service program into a binding directory.