On Tue, 12 Jan 2021 19:19:01 +0200, Itschak Mugzach wrote:
>
>So if I ignore leap seconds, Can I just divide the number by 409600 and
>subtruct 1.1.1970-1.1.1900?
> 
Here's some code I wrote.  The input data are the list of leap seconds
in PoOp.

Restriction:  Presumes a system such as Linux providing the "right"
hierarchy in /usr/share/zoneinfo.

-- gil


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
/*bin/true;exec rexx "$0" "$@";exit # REXX  Magic!
   Doc: Verify the leap second list in Principles of Operation.
*/

ABCD = ,
7D91 048B CA00 0000 ,  /* Circa Jan 1970 -- Must be first!  */
                    ,  /* From PrincOps:   */ 
8000 0000 0000 0000 ,  /* May 1971 -- TOD Rollover.       */
8126 D60E 4600 0000 ,  /* Dec 1971 -- UTC begins.         */
820B A981 1E24 0000 ,  /* Jun 1972 -- first leap second.  */
82F3 00AE E248 0000 84BD E971 146C 0000 8688 D233 4690 0000 8853 BAF5 78B4 0000 
8A1F E595 20D8 0000 8BEA CE57 52FC 0000 8DB5 B719 8520 0000 8F80 9FDB B744 0000 
9230 5C0F CD68 0000 93FB 44D1 FF8C 0000 95C6 2D94 31B0 0000 995D 40F5 17D4 0000 
9DDA 69A5 57F8 0000 A171 7D06 3E1C 0000 A33C 65C8 7040 0000 ,
A5EC 21FC 8664 0000 A7B7 0ABE B888 0000 A981 F380 EAAC 0000 AC34 336F ECD0 0000 
AEE3 EFA4 02F4 0000 B196 2F93 0518 0000 BE25 1097 973C 0000 C387 0CB9 BB60 0000 
C9CC 9A70 4D84 0000 CF2D 54B4 FBA8 0000 ,
D1E0 D681 73CC 0000, /* 2016-12-31 23:59:60  */
d7c7 8993 9481 99a3, /* EBCDIC "PGilmart"    */
D7D9 E4C9 E3C5 D940, /* EBCDIC "PRUITER"     */
F7A3 048A D5DC 0000  /* The End of Time!     */

signal on novalue
numeric digits 25
say ABCD
say
parse value ABCD with A B C D .
call Adjust
TOD1970 =  TOD
say '/*' TOD TOD1970 '*/'
say d2x( ( x2d( '7FFFFFFF' ) + TOD1970 + 1 ) * 4096 * 1000000 )
say d2x( ( 1483228827        + TOD1970     ) * 4096 * 1000000 )
say

RC = W( '#include <stdlib.h>', 1 )  /* Start at line 1  */
RC = W( '#include <stdio.h>' )
RC = W( '#include <time.h>' )
RC = W( 'static const time_t leaps[] = {' )

do Lctr = 0 while ABCD<>''
    parse value ABCD with A B C D ABCD
    call Adjust
    RC = W( '/* TOD:' A B C D ,
        'UNIX: */' right( TOD - TOD1970, 10 )copies( ',', ABCD>>'' ),
            '/*' Frac '*/' );  end Lctr
RC = W( '    };' )
RC = W( '' )

RC = W( 'int ShowIt( const time_t *pT ) {' )
RC = W( '    char s[100];' )
RC = W( '' )
RC = W( '    strftime( s, 99, "%c", localtime( pT ) );' )
RC = W( '    printf( "Time =%11ld  for: %s\n", (long)*pT, s );' )
RC = W( '    return 0; }' )

RC = W( '' )
RC = W( 'int main( void ) {' )
RC = W( '    const time_t *I;' )
RC = W( '          time_t TT;' )
RC = W( '' )

RC = W( '    system( "uname -a" );' )
RC = W( '    putenv( "TZ=right/Universal" );')
RC = W( '    putenv( "TZ=right/America/Denver" );')
RC = W( '    putenv( "TZ=right/America/Los_Angeles" );')
RC = W( '    printf( "For Timezone: %s\n", getenv( "TZ" ) );' )
RC = W( '    tzset(); for ( I = leaps; I<leaps+'Lctr'; I++ ) {')
RC = W( '        printf( "\n" );' )
RC = W( '        TT = *I - 2;  ShowIt( &TT );' )
RC = W( '        TT = *I - 1;  ShowIt( &TT ); /* Leap second begins.  */' )
RC = W( '        ShowIt( I );                 /* Leap second ends.  */ }' )
RC = W( '    return 0; }' )

if 0 then RC = W( )                  /* End file.  */
'set -x; make leapsec && ./leapsec'  /* Compile and execute.  */
return( RC )

Adjust:
    TOD = A || B || C || D
    TOD = x2d( TOD ) / 4096 / 1000000
    Frac = TOD // 1
    TOD = TOD % 1
    say A B C D '' TOD length( TOD ) d2x( TOD * 4096 * 1000000 ) ,
        d2x( ( TOD + 1 ) * 4096 * 1000000 )
    return TOD

W: procedure
    F = 'leapsec.c'
    if arg( 2, 'Exists' )
        then return( lineout( F,  arg( 1 ), arg( 2 ) ) )
    else if arg( 1, 'Exists' )
        then return( lineout( F,  arg( 1 )           ) )
    else     return( lineout( F                      ) )



----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to